ESLint plugin validate filename.
npm install eslint-plugin-validate-filenameESLint rule to force file names format. Create common rules for file names by folder name or regex pattern.
``sh`
npm install --save-dev eslint-plugin-validate-filename
`javascript`
{
"plugins": ["validate-filename"]
}
Create a rule in the name of ESLint. You can set multiple rules.
`javascript`
{
"rules": {
"validate-filename/naming-rules": [
"error",
{
rules: [
{
case: 'pascal', // camel or pascal or snake or kebab or flat
target: "/components/", // target "components" folder
excludes: ['hooks'], // "hooks" folder is excluded.
},
{
case: 'camel',
target: "/hooks/", // target "hooks" folder
patterns: '^use', // file names begin with "use".
},
{
target: '/schemas/**', // target "schemas" folder
patterns: '^[a-z][a-zA-Z0-9]*\\.schema\\.ts$', // file names that contain 'schema'. ex: user.schema.ts
},
],
},
],
},
}
Only certain extensions are allowed. target is a regular expression that identifies the folder. extensions you want to allow for extensions.
`javascript`
{
"rules": {
"validate-filename/limit-extensions": [
"error",
{
rules: [
{
target: "/hooks/",
extensions: ['.ts', '.tsx'], // This cannot be created except for .ts or .tsx under the hooks folder.
},
],
},
],
},
}
First, install npm dependencies.
`bash`
npm install
Running unit test. This library uses vitest.
`bash`
npm run test
Build modules.
`bash``
npm run build
See Next.js naming conventions are checked with ESLint rules
article.
MIT License.© hiro08gh