Comments (10)
I would love to contribute to it too. I have developed a rule enforcing a custom file structure, but it could be easily adjusted.
from eslint-plugin-filenames.
@selaux @markalfred I would love this feature as well. For backwards compatibility, maybe enable as an option to filenames/match-regex
to match full file paths instead of just base file names?
Not sure if we should try to trim the absolute paths to be relative to the project root - may be tricky.
Would you accept a pull request and consider a release, or is it not worth my time?
from eslint-plugin-filenames.
@AndersDJohnson Sure, I would gladly accept a PR. match-regex
could be extended to match each path segment relative to root. Not sure how to find the root though 😉
from eslint-plugin-filenames.
Hi @selaux I am working on this but I am not sure how to set the root folder in my tests. I have a failing test now that should pass:
{
code: testCode,
filename: "SomeDir/VariableName.js",
// parserOptions: { ecmaVersion: 6, sourceType: "module" },
options: ['pascal']
},
The Dirname returned is foo/SomeDir
where it should be Foo/SomeDir
, but I am not sure how to set foo
to Foo
from eslint-plugin-filenames.
How can I change which root folder is sent? It should differ to match-dirname
tests, since I don't want /foo
as in the other tests.
from eslint-plugin-filenames.
Can you upload the code, so I can have a look at it? I don't fully understand the question yet...
from eslint-plugin-filenames.
I would love to contribute to it too. I have developed a rule enforcing a custom file structure, but it could be easily adjusted.
what about your rules now?
from eslint-plugin-filenames.
As it is small, I will post its entire code here.
Keep in mind that is was developed for an opinionated file structure (feature-based with layers inside of the features).
module.exports = {
meta: {
docs: {
description: 'This rule enforces a file path to match the guideline',
recommended: true,
},
messages: {
[MATCH_PATH_MESSAGE]: "File path '{{ pathDir }}' should match the guideline",
},
},
create: (context) => {
//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
const joinOptions = (options) => `(${options.join('|')})`;
return {
Program: (node) => {
const filename = path.resolve(context.getFilename()).replace(/\\/g, '/');
const rootFile = joinOptions(['serviceWorker', 'store']);
const validFiles = [
`${SRC_FOLDER}/${rootFile}.(js|ts)`, // src root files
`${SRC_FOLDER}/index((.integration)?.test)?.(js|ts|tsx)`, // src root file
`${SRC_FOLDER}/router.(js|tsx)`, // root router file
`${SRC_FOLDER}/modules/index.(js|ts)`, // modules entrypoint
`${SRC_FOLDER}/${I18N_LAYER_FOLDER}/${I18N_CASE}.json`,
`${FEATURE_FOLDER}(/${LAYER_FOLDER})?/index((.integration)?.test)?.(js|ts)`, // entrypoints
`${FEATURE_FOLDER}/${NAMESPACED_LAYER_FOLDER}(/${KEBAB_CASE})?/index(.test)?.(js|ts)`,
`${FEATURE_FOLDER}/${LAYERS.DECORATORS}(/${KEBAB_CASE})?/index(.test)?.tsx`, // decorators may have JSX
`${FEATURE_FOLDER}/${CONSTANTS_LAYER_FOLDER}/${KEBAB_CASE}.(js|ts)`,
`${FEATURE_FOLDER}/${REACT_LAYER_FOLDER}(/${PASCAL_CASE})?/index.scss`,
`${FEATURE_FOLDER}/${REACT_LAYER_FOLDER}(/${PASCAL_CASE})?/index((.integration)?.test|.story)?.(js|tsx)`,
`${FEATURE_FOLDER}/${TYPESCRIPT_LAYER_FOLDER}/${PASCAL_CASE}.ts`,
`${FEATURE_FOLDER}/${FREESTYLE_LAYER_FOLDER}.*`,
];
const validFilesRegExp = new RegExp(`${joinOptions(validFiles)}$`);
const fileIndex = filename.indexOf('src');
if (filename.match('src') && !filename.match(validFilesRegExp)) {
context.report({
node,
messageId: MATCH_PATH_MESSAGE,
data: { pathDir: filename.slice(fileIndex) },
});
}
},
};
},
};
from eslint-plugin-filenames.
also will be great to have similar rule for folders, as you have for files: filename-case
from eslint-plugin-filenames.
As an alternative, you can use eslint-plugin-project-structure
features:
✅ Validation of project structure (Any files/folders outside the structure will be considered an error).
✅ Validation of folder and file names.
✅ Name case validation.
✅ Name regex validation.
✅ File extension validation (Support for all extensions).
✅ Inheriting the parent's name (The child inherits the name of the folder in which it is located).
✅ Folder recursion (You can nest a given folder structure recursively).
✅ Forcing a nested/flat structure for a given folder.
from eslint-plugin-filenames.
Related Issues (20)
- Add match-exported = [parent folder]-[filename] pattern HOT 2
- Match parent folder name if index.js in src folder HOT 2
- version 1.3.0 should have been a breaking change HOT 7
- Add a CHANGELOG HOT 1
- index file with suffix HOT 1
- match-exported - match will fail for anonymous function
- Disallow file names ending with pattern HOT 1
- Feature Request: Do not apply match-exported if file is index.js HOT 1
- Feature request: Require file to have atleast one named export with the same name as file. HOT 1
- bug[match-regex]: negative lookahead doesn't work HOT 2
- Forbidden name rule HOT 2
- `filenames/match-exported`: Error when exporting from `index.d.ts` file. HOT 1
- Fails to detect name when using `export =` HOT 1
- Custom error message for filenames conventions
- filenames/match-regex error using export { ... } HOT 1
- match-exported with non-default exports HOT 3
- Abandoned? HOT 10
- Created a custom eslint-plugin, which uses your 'match-exported' rule
- Support ESLint 8.x HOT 1
- How to check for this pattern: componentService --> component.service.js? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-filenames.