A custom eslint to ensure files follow a folder structure.
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-folder-lint
:
npm install eslint-plugin-folder-lint --save-dev
(Local development when creating a rule):
# folder-lint
npm run build
# target repo
npm install --D file:../folder-lint/.build
Add folder-lint
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": ["folder-lint"]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
"folder-lint/lint": ['error, {
baseDir: 'src',
allowedPaths: ['components/*']
}]
}
}
For example:
Rule | Meaning |
---|---|
components |
✅ The directory components (and files in it) is accepted.❌ Any nested directory is not accepted. |
components/* |
✅ The directory components is accepted.✅ Any first level nested directory is accepted. ❌ Any second level nested directory is not accepted. |
components/*/utils |
✅ The directory components is accepted.✅ Any first level nested directory is accepted. ✅ The second level nested directory utils is accepted.❌ Any other second level nested directory is not accepted. |
components/** |
✅ The directory components is accepted.✅ Any nested directory on any level is accepted. |
components/*/components/** |
✅ The directory components is accepted.✅ Any first level nested directory is accepted. ✅ The second level nested directory components is accepted.❌ Any other second level nested directory is not accepted. ✅ Any nested directory on any level inside of components directory is accepted. |