Many aspects of this project are shamelessly borrowed from FoldersLint, the best equivalent I was able to find before writing a Rust version named folders-lint. This is a TypeScript version because TypeScript is easier to package and collaborate with.
This module aims to improve folder structure by only allowing safe-listed file paths. As a byproduct, the configuration file can be thought of as reliable and readable documentation for the folder structure.
npm i -D @clowd/fsl
I recommend grouping by both feature (/*/
below) and file type (hooks
, components
, etc.):
{
"root": "src",
"rules": [
"src/App.*",
"src/index.*",
"src/*/index.*",
"src/*/hooks/use*.*",
"src/*/components/*.*",
"src/*/others/*.*",
]
}
Add this to your package.json
:
{
"scripts": {
"fsl": "fsl"
}
}
Run the linter:
npm run fsl
Use husky
and lint-staged
in combination, 2 great NPM packages. Husky lets you check rules on commit. Lint Staged only checks changed files.
Example .folder-structure-lint.json
glob rule:
{
"root": "src",
"rules": ["src/legacy/**"]
}
Regex is not supported in the TypeScript version. See the Rust version if interested or submit a pull-request.