Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
eslint-plugin-filenames
Advanced tools
The eslint-plugin-filenames package is an ESLint plugin that enforces consistent naming conventions for file names. It helps maintain a uniform codebase by ensuring that file names follow specified patterns.
Enforce kebab-case file names
This rule enforces that all file names must be in kebab-case (lowercase letters separated by hyphens).
module.exports = {
"plugins": ["filenames"],
"rules": {
"filenames/match-regex": ["error", "^[a-z-]+$", true]
}
};
Enforce PascalCase file names
This rule enforces that all file names must be in PascalCase (each word starts with an uppercase letter and no separators).
module.exports = {
"plugins": ["filenames"],
"rules": {
"filenames/match-regex": ["error", "^[A-Z][a-zA-Z]+$", true]
}
};
Enforce specific file name for main module
This rule enforces that the file name must match the name of the default export in the file, using camelCase.
module.exports = {
"plugins": ["filenames"],
"rules": {
"filenames/match-exported": ["error", "camel"]
}
};
eslint-plugin-filename-rules is another ESLint plugin that enforces naming conventions for file names. It offers similar functionality to eslint-plugin-filenames but with a different set of configuration options and rules.
eslint-plugin-unicorn is a comprehensive ESLint plugin that includes a wide range of rules for improving code quality, including rules for enforcing file naming conventions. It provides more extensive functionality beyond just file names.
Adds eslint rules to ensure consistent filenames for your javascript files.
Please note: This plugin will only lint the filenames of the .js
, .jsx
files you are linting with eslint. It will ignore other files that are not linted with eslint.
This plugin requires a version of eslint>=1.0.0
to be installed as a peer dependency.
Modify your .eslintrc
file to load the plugin and enable the rules you want to use.
{
"plugins": [
"filenames"
],
"rules": {
"filenames/match-regex": 2,
"filenames/match-exported": 2,
"filenames/no-index": 2
}
}
A rule to enforce a certain file naming convention using a regular expression.
The convention can be configured using a regular expression (the default is camelCase.js
). Additionally
exporting files can be ignored with a second configuration parameter.
"filenames/match-regex": [2, "^[a-z_]+$", true]
With these configuration options, camelCase.js
will be reported as an error while snake_case.js
will pass.
Additionally the files that have a named default export (according to the logic in the match-exported
rule) will be
ignored. They could be linted with the match-exported
rule. Please note that exported function calls are not
respected in this case.
Match the file name against the default exported value in the module. Files that dont have a default export will
be ignored. The exports of index.js
are matched against their parent directory.
// Considered problem only if the file isn't named foo.js or foo/index.js
export default function foo() {}
// Considered problem only if the file isn't named Foo.js or Foo/index.js
module.exports = class Foo() {}
// Considered problem only if the file isn't named someVariable.js or someVariable/index.js
module.exports = someVariable;
// Never considered a problem
export default { foo: "bar" };
If your filename policy doesn't quite match with your variable naming policy, you can add one or multiple transforms:
"filenames/match-exported": [ 2, "kebab" ]
Now, in your code:
// Considered problem only if file isn't named variable-name.js or variable-name/index.js
export default function variableName;
Available transforms: 'snake', 'kebab', 'camel', and 'pascal' (camel-cased with first letter in upper case).
For multiple transforms simply specify an array like this (null in this case stands for no transform):
"filenames/match-exported": [2, [ null, "kebab", "snake" ] ]
If you prefer to use suffixes for your files (e.g. Foo.react.js
for a React component file),
you can use a second configuration parameter. It allows you to remove parts of a filename matching a regex pattern
before transforming and matching against the export.
"filenames/match-exported": [ 2, null, "\\.react$" ]
Now, in your code:
// Considered problem only if file isn't named variableName.react.js, variableName.js or variableName/index.js
export default function variableName;
If you also want to match exported function calls you can use the third option (a boolean flag).
"filenames/match-exported": [ 2, null, null, true ]
Now, in your code:
// Considered problem only if file isn't named functionName.js or functionName/index.js
export default functionName();
Having a bunch of index.js
files can have negative influence on developer experience, e.g. when
opening files by name. When enabling this rule. index.js
files will always be considered a problem.
match-regex
and getExportedName
1.3.0
behind a flagstrip
option for match-exported
pascal
transformtransform
option for match-exported
match-regex
, match-exported
and no-index
FAQs
Eslint rule for consistent filenames.
The npm package eslint-plugin-filenames receives a total of 214,100 weekly downloads. As such, eslint-plugin-filenames popularity was classified as popular.
We found that eslint-plugin-filenames demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.