UNPKG

eslint-plugin-file-export-name

Version:

ESLint plugin to enforce matching file names with default export names.

103 lines (78 loc) 2.2 kB
# ESLint Plugin: File Export Name This ESLint plugin ensures that the default export name matches the file name according to specified case styles and patterns. ## Installation ```bash npm install eslint-plugin-file-export-name --save-dev yarn add -D eslint-plugin-file-export-name pnpm add -D eslint-plugin-file-export-name ``` ## Usage Add the plugin to your `.eslintrc` configuration file: ```json { "plugins": ["file-export-name"], "rules": { "file-export-name/match-file-export-name": "error" } } ``` ## Rule: match-file-export-name This rule verifies that the default export name matches the file name according to the specified configuration. ### Options The rule accepts an object or an array of objects with the following properties: - `cases`: An array of allowed case styles (`"pascal"`, `"camel"`, `"kebab"`, `"snake"`). - `pattern`: A string representing a regular expression to match the export name. - `ignore`: An array of file patterns to ignore. - `extensions`: An array of file extensions to apply the rule to. ### Default Configuration ```json { "cases": ["pascal", "camel"], "extensions": [".jsx", ".tsx", ".js", ".ts"], "ignore": ["<text>", "<input>"], "pattern": null } ``` ### Examples #### Basic configuration ```json { "rules": { "file-export-name/match-file-export-name": ["error", { "cases": ["pascal", "camel"], "pattern": "^My.*$", "ignore": ["utils/*.js"], "extensions": [".jsx", ".tsx"] }] } } // or you can use just in one line { "rules": { "file-export-name/match-file-export-name": "error" } } ``` #### Multiple configurations ```json { "rules": { "file-export-name/match-file-export-name": ["error", [ { "cases": ["pascal"], "extensions": [".jsx", ".tsx"] }, { "cases": ["camel"], "extensions": [".js", ".ts"] } ]] } } ``` ## Features - Supports multiple case styles: PascalCase, camelCase, kebab-case, and snake_case - Custom regex pattern matching for export names - Ability to ignore specific files or patterns - Configure different rules for different file extensions - Automatically ignores `index` files