Many aspects of this project are shamelessly borrowed form FoldersLint, the best equivalent I was able to find before writing this module.
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 readable documentation for the folder structure.
This is a Node.js module written in Rust and created using Neon. The underlying Glob implementation is the glob crate. The underlying Regex implementation is the regex crate.
Warning: Cloning this repo and building with Neon might work better for you, but please help fix if normal installation fails.
(The first step is Windows only.)
npm install --global windows-build-tools
npm install -g node-gyp
npm i -D mattferrin/folders-lint
(If installation has a cargo error hiccup try Installing Rust.)
Create your custom .folderslintrc.json
file:
{
"root": "src",
"rules": [
"App.*",
"index.*",
"common/hooks/use*.*",
"common/components/Render*.*",
"common/handlers/handle*.*",
"features/*/index.*",
"features/*/hooks/use*.*",
"features/*/components/Render*.*",
"features/*/handlers/handle*.*",
"__tests__/*/*.test.tsx"
]
}
Add this to your package.json
:
{
"scripts": {
"fslint": "folders-lint"
}
}
Run the linter:
npm run fslint
npm install husky --save-dev
And add this to your package.json
:
{
"scripts": {
"fslint": "folders-lint"
},
"husky": {
"hooks": {
"pre-commit": "npm run fslint"
}
}
}
The glob rules are matched with:
case_sensitive: true,
require_literal_leading_dot: false,
require_literal_separator: true`,
Example .folderslintrc.json
glob rule:
{
"root": "src",
"rules": ["legacy/**"]
}
Example .folderslintrc.json
regex rule:
{
"root": "src",
"rules": ["/index\\.tsx/"]
}
Example .folderslintrc.json
rules:
{
"root": "src",
"rules": ["legacy/**", "/index\\.tsx/"]
}
Note: Regex escape character \
needs double escaped in JSON: \\