Skip to content

Commit

Permalink
update filenames default since it is now in our repo
Browse files Browse the repository at this point in the history
  • Loading branch information
gracepark committed Dec 4, 2024
1 parent 5bb75fb commit 1373fa2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
22 changes: 17 additions & 5 deletions docs/rules/filenames-match-regex.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)*$'
]
}
```
Expand Down
2 changes: 1 addition & 1 deletion lib/configs/flat/recommended.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/filenames-match-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions test-examples/flat/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)*$'],
},
},
]

0 comments on commit 1373fa2

Please sign in to comment.