-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rules for directory names #23
Comments
@selaux @markalfred I would love this feature as well. For backwards compatibility, maybe enable as an option to 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? |
@AndersDJohnson Sure, I would gladly accept a PR. |
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:
The Dirname returned is |
How can I change which root folder is sent? It should differ to |
Can you upload the code, so I can have a look at it? I don't fully understand the question yet... |
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? |
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) },
});
}
},
};
},
}; |
also will be great to have similar rule for folders, as you have for files: filename-case |
As an alternative, you can use eslint-plugin-project-structure
ESLint plugin with rules to help you achieve a scalable, consistent, and well-structured project. Create your own framework! Define your folder structure, advanced naming conventions, file composition, and create independent modules. Take your project to the next level and save time by automating the review of key principles of a healthy project! project‑structure/folder‑structureEnforce rules on folder structure to keep your project consistent, orderly and well thought out.
|
This is a feature I would personally use, but not sure if there's any demand for it from other folks or if it's better off as its own plugin.
For instance, I want all files and directories to be kebab-cased so that there are no issues between case-insensitive (OSX dev environments) and case-sensitive (Linux deployment environments). Currently, though, with this configuration:
I could create this file with no problem:
On my OSX machine, I could
import AuthHeader from 'app/components/auth/auth-header'
with no problem.But as soon as I deploy to a linux environment... 💥
The text was updated successfully, but these errors were encountered: