From 1373fa2ae4dc12ce61f4b7501ad41828fa9076c1 Mon Sep 17 00:00:00 2001 From: Grace Park Date: Wed, 4 Dec 2024 10:39:04 -0800 Subject: [PATCH 1/4] update filenames default since it is now in our repo --- README.md | 6 ++++-- docs/rules/filenames-match-regex.md | 22 +++++++++++++++++----- lib/configs/flat/recommended.js | 2 +- lib/rules/filenames-match-regex.js | 3 ++- test-examples/flat/eslint.config.mjs | 1 + 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e86a3d43..43109452 100644 --- a/README.md +++ b/README.md @@ -56,9 +56,11 @@ export default [ ``` > [!NOTE] -> If you configured the `filenames/match-regex` rule, please note we have adapted the match regex rule into `eslint-plugin-github` as the original `eslint-filenames-plugin` is no longer maintained and needed an ESLint v9/flat config update. Please update the name to `github/filenames-match-regex` and keep the same configuration. Note, that the default rule is camelCase with one hump. If there are multiple humps like `camelCaseTest.js`, this default rule will error out. Here's an example for this rule with custom configuration: +> If you configured the `filenames/match-regex` rule, please note we have adapted the match regex rule into `eslint-plugin-github` as the original `eslint-filenames-plugin` is no longer maintained and needed a flat config support update. +> +> Please update the name to `github/filenames-match-regex`. Please note, the default rule is kebab case or camelCase with one hump. For custom configuration, such as matching for camelCase regex, here's an example: > -> `'github/filenames-match-regex': ['error', '^[a-z0-9-]+(.[a-z0-9-]+)?$']` +> `'github/filenames-match-regex': ['error', '^([a-z0-9]+)([A-Z][a-z0-9]+)*$'],` The available configs are: diff --git a/docs/rules/filenames-match-regex.md b/docs/rules/filenames-match-regex.md index 6476e14d..5fda99fa 100644 --- a/docs/rules/filenames-match-regex.md +++ b/docs/rules/filenames-match-regex.md @@ -4,26 +4,38 @@ ## Rule Details -Rule to ensure that filenames match a convention, with a default of camelCase for ESLint v9+. +Rule to ensure that filenames match a convention, with a default of kebab case or camelCase with one hump for flat config. 👎 Examples of **incorrect** filename for this default rule: -`file-name.js` +- `fileNameRule.js` 👍 Examples of **correct** code for this rule: -`fileName.js` +- `fileName.js` +- `file-name.js` ## Options -regex - Regex to match the filename structure. Defaults to camelCase. +- regex - Regex to match the filename structure. Defaults to kebab case or camelCase with one hump. +Default: ```json { "filenames-match-regex": [ "error", - "^[a-z0-9-]+(.[a-z0-9-]+)?$" + ] +} +``` + +If you want to add custom regex such as matching all camelCase, this would be the option: + +```json +{ + 'filenames-match-regex': [ + 'error', + '^([a-z0-9]+)([A-Z][a-z0-9]+)*$' ] } ``` diff --git a/lib/configs/flat/recommended.js b/lib/configs/flat/recommended.js index 31cb3400..2f089a19 100644 --- a/lib/configs/flat/recommended.js +++ b/lib/configs/flat/recommended.js @@ -32,7 +32,7 @@ module.exports = { 'eslintComments/no-unused-disable': 'error', 'eslintComments/no-unused-enable': 'error', 'eslintComments/no-use': ['error', {allow: ['eslint', 'eslint-disable-next-line', 'eslint-env', 'globals']}], - 'github/filenames-match-regex': ['error', '^[a-z0-9-]+(.[a-z0-9-]+)?$'], + 'github/filenames-match-regex': 'error', 'func-style': ['error', 'declaration', {allowArrowFunctions: true}], 'github/array-foreach': 'error', 'github/no-implicit-buggy-globals': 'error', diff --git a/lib/rules/filenames-match-regex.js b/lib/rules/filenames-match-regex.js index 515887ea..f50952c5 100644 --- a/lib/rules/filenames-match-regex.js +++ b/lib/rules/filenames-match-regex.js @@ -25,7 +25,8 @@ module.exports = { }, create(context) { - const defaultRegexp = /^([a-z0-9]+)([A-Z][a-z0-9]+)*$/g + // GitHub's default is kebab case or one hump camel case + const defaultRegexp = /^[a-z0-9-]+(.[a-z0-9-]+)?$/ const conventionRegexp = context.options[0] ? new RegExp(context.options[0]) : defaultRegexp const ignoreExporting = context.options[1] ? context.options[1] : false diff --git a/test-examples/flat/eslint.config.mjs b/test-examples/flat/eslint.config.mjs index 2d4f781e..0ff163c1 100644 --- a/test-examples/flat/eslint.config.mjs +++ b/test-examples/flat/eslint.config.mjs @@ -13,6 +13,7 @@ export default [ 'github/no-then': 'error', 'github/no-blur': 'error', 'github/async-preventdefault': 'error', + 'github/filenames-match-regex': ['error', '^([a-z0-9]+)([A-Z][a-z0-9]+)*$'], }, }, ] From 5bb2f9c48f02d5b260a5344f5f1e94b73291ee29 Mon Sep 17 00:00:00 2001 From: Grace Park Date: Wed, 4 Dec 2024 10:41:04 -0800 Subject: [PATCH 2/4] update grammar --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 43109452..baf32798 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ export default [ > [!NOTE] > If you configured the `filenames/match-regex` rule, please note we have adapted the match regex rule into `eslint-plugin-github` as the original `eslint-filenames-plugin` is no longer maintained and needed a flat config support update. > -> Please update the name to `github/filenames-match-regex`. Please note, the default rule is kebab case or camelCase with one hump. For custom configuration, such as matching for camelCase regex, here's an example: +> Please update the name to `github/filenames-match-regex`, and note, the default rule is kebab case or camelCase with one hump. For custom configuration, such as matching for camelCase regex, here's an example: > > `'github/filenames-match-regex': ['error', '^([a-z0-9]+)([A-Z][a-z0-9]+)*$'],` From 996a56d12293113d0fde89e6796b9f43fedfc5f4 Mon Sep 17 00:00:00 2001 From: Grace Park Date: Wed, 4 Dec 2024 10:44:45 -0800 Subject: [PATCH 3/4] update doc --- docs/rules/filenames-match-regex.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/rules/filenames-match-regex.md b/docs/rules/filenames-match-regex.md index 5fda99fa..1bba31b8 100644 --- a/docs/rules/filenames-match-regex.md +++ b/docs/rules/filenames-match-regex.md @@ -24,18 +24,18 @@ Default: ```json { "filenames-match-regex": [ - "error", + "error" ] } ``` -If you want to add custom regex such as matching all camelCase, this would be the option: +If you want to add custom regex such as matching all camelCase, add the regex as a string. For example, for camelCase it would look like: ```json { - 'filenames-match-regex': [ - 'error', - '^([a-z0-9]+)([A-Z][a-z0-9]+)*$' + "filenames-match-regex": [ + "error", + "^([a-z0-9]+)([A-Z][a-z0-9]+)*$" ] } ``` From 2b0173cad4f04d437ef318d8bb73f5c12ee7975f Mon Sep 17 00:00:00 2001 From: Grace Park Date: Wed, 4 Dec 2024 10:45:17 -0800 Subject: [PATCH 4/4] remove dash --- docs/rules/filenames-match-regex.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/filenames-match-regex.md b/docs/rules/filenames-match-regex.md index 1bba31b8..4d153880 100644 --- a/docs/rules/filenames-match-regex.md +++ b/docs/rules/filenames-match-regex.md @@ -17,7 +17,7 @@ Rule to ensure that filenames match a convention, with a default of kebab case o ## Options -- regex - Regex to match the filename structure. Defaults to kebab case or camelCase with one hump. +regex - Regex to match the filename structure. Defaults to kebab case or camelCase with one hump. Default: