hiro08gh / eslint-plugin-validate-filename

ESLint plugin validate filename. It can be verification by case and pattern and extensions.

Home Page:https://medium.com/@hiro08gh/next-js-naming-conventions-are-checked-with-eslint-rules-946371d67882

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eslint-plugin-validate-filename

ESLint rule to force file names format. Create common rules for file names by folder name or regex pattern.

Install

npm install --save-dev eslint-plugin-validate-filename

Uasge

{
  "plugins": ["validate-filename"]
}

validate-filename/naming-rules

Create a rule in the name of ESLint. You can set multiple rules.

{
  "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".
          }
        ] 
      }
    ],
}

validate-filename/limit-extensions

Only certain extensions are allowed. target is a regular expression that identifies the folder. extensions you want to allow for extensions.

{
  "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.
          }
        ]
      }
    ],
}

Next.js structure settings example

See Next.js naming conventions are checked with ESLint rules article.

About

ESLint plugin validate filename. It can be verification by case and pattern and extensions.

https://medium.com/@hiro08gh/next-js-naming-conventions-are-checked-with-eslint-rules-946371d67882

License:MIT License


Languages

Language:TypeScript 80.5%Language:CSS 14.8%Language:JavaScript 4.7%