ESLint plugin for enforce a case style for file and folder.
npm install eslint-plugin-namingš¼ This rule is enabled in the ā
recommended.
Enforces all linted files and folders to have their names in a certain case style and lowercase file extension. The default is kebab.
- foo-bar.js
- foo-bar.test.js
- foo-bar.test-utils.js
- fooBar.js
- fooBar.test.js
- fooBar.testUtils.js
- FooBar.js
- FooBar.Test.js
- FooBar.TestUtils.js
- foo_bar.js
- foo_bar.test.js
- foo_bar.test_utils.js
- foobar.js
- foobar.test.js
- foobar.testutils.js
``bash`
$ yarn add --dev eslint-plugin-naming
`js`
module.exports = {
extends: ['plugin:naming/recommended'],
};
Type: string
You can set the match option like this:
`js`
module.exports = {
extends: ['plugin:naming/recommended'],
rules: {
'naming/case': ['error', 'kebab'],
},
};
Type: {string[]}
You can set the match option to allow multiple cases:
`js`
module.exports = {
extends: ['plugin:naming/recommended'],
rules: {
'naming/case': ['error', ['kebab', 'camel']],
},
};
Options object has the following properties:
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| match | string[] | ["kebab"] | List of cases to match |ignore
| | string[] RegExp[] | [] | List of regular expressions |defaultIgnore
| | boolean | true | Property that allows turning off default ignored values |validateFolders
| | boolean | true | Property that allows turning off folders naming validation |validateExtensions
| | boolean | true | Property that allows turning off extensions lowercase validation |
Example
`js`
module.exports = {
extends: ['plugin:naming/recommended'],
rules: {
'naming/case': [
'error',
{
match: 'kebab',
ignore: ['^FOOBAR\\.js$', '^(B|b)az', '\\.SOMETHING\\.js$', /^vendor/i],
},
],
},
};
Don't forget that you must escape special characters that you don't want to be interpreted as part of the regex, for example, if you have [ in the actual filename. For example, to match [id].js, use /^\[id]\.js$/ or '^\\[id]\\.js$'`.