Skip to content

Update filenames default since it is now in our repo #584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`, 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-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"
]
}
```

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-z0-9-]+)?$"
"^([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]+)*$'],
},
},
]
Loading