eslint-plugin-file-export-name
Version:
ESLint plugin to enforce matching file names with default export names.
103 lines (78 loc) • 2.2 kB
Markdown
default export name matches the file name according to specified case styles and patterns.
```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
```
Add the plugin to your `.eslintrc` configuration file:
```json
{
"plugins": ["file-export-name"],
"rules": {
"file-export-name/match-file-export-name": "error"
}
}
```
This rule verifies that the default export name matches the file name according to the specified configuration.
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
}
```
```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"
}
}
```
```json
{
"rules": {
"file-export-name/match-file-export-name": ["error", [
{
"cases": ["pascal"],
"extensions": [".jsx", ".tsx"]
},
{
"cases": ["camel"],
"extensions": [".js", ".ts"]
}
]]
}
}
```
- 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
This ESLint plugin ensures that the