What is eslint-plugin-filename-rules?
The eslint-plugin-filename-rules package is an ESLint plugin that enforces consistent naming conventions for your files. It helps maintain a uniform file structure and naming pattern across your project, which can improve readability and maintainability.
What are eslint-plugin-filename-rules's main functionalities?
Enforce specific filename patterns
This feature allows you to enforce specific patterns for filenames. In this example, the rule enforces that all filenames must be in lowercase and can only contain hyphens.
{
"rules": {
"filename-rules/match": ["error", "^[a-z-]+$"]
}
}
Disallow specific filename patterns
This feature allows you to disallow specific patterns for filenames. In this example, the rule disallows any filenames that contain uppercase letters.
{
"rules": {
"filename-rules/no-match": ["error", "[A-Z]"]
}
}
Enforce specific file extensions
This feature allows you to enforce specific file extensions. In this example, the rule enforces that all files must have a .js extension.
{
"rules": {
"filename-rules/match": ["error", ".*\.js$"]
}
}
Other packages similar to eslint-plugin-filename-rules
eslint-plugin-filenames
eslint-plugin-filenames is another ESLint plugin that enforces consistent naming conventions for files. It offers similar functionality to eslint-plugin-filename-rules, such as enforcing specific filename patterns and extensions. However, eslint-plugin-filenames provides more granular control over naming conventions, including the ability to enforce specific naming conventions for different file types.
eslint-plugin-file-header
eslint-plugin-file-header is an ESLint plugin that enforces the presence of a specific header comment in files. While it does not enforce filename patterns, it can be used in conjunction with eslint-plugin-filename-rules to ensure both consistent file naming and the presence of necessary file headers.
eslint-plugin-filename-rules
Adds an ESLint rule to enforce filename conventions for linted files. Allows different options for different file extensions. Supports custom regular expressions.

Installation
$ npm install -D eslint-plugin-filename-rules
Add it to your .eslintrc.js
:
module.exports = {
plugins: [
'filename-rules',
],
rules: {
'filename-rules/match': [2, 'camelcase'],
},
};
Plugin Options
The following built-in values are supported: pascalcase
/PascalCase
, camelcase
/camelCase
, snakecase
/snake_case
, kebabcase
/kebab-case
. You can also provide your own regex:
...
'filename-rules/match': [2, /^([a-z]+-)*[a-z]+(?:\..*)?$/],
...
You can also specify different options for different file extensions. In this case the plugin will only check files with extensions you explicitly provided:
...
'filename-rules/match': [2, { '.js': 'camelCase', '.ts': /^([a-z]+-)*[a-z]+(?:\..*)?$/ }],
...
You can use the includePath: true
option to have the pattern matched against the full file path (instead of only the file basename):
...
'filename-rules/match': [2, { includePath: true, pattern: /^([a-z]+-)*[a-z]+(?:\..*)?$/ }],
...
The inverse rule not-match
checks that the files do NOT match the given pattern. Supports all the same options:
...
'filename-rules/not-match': [2, 'camelCase'],
...
License
MIT