errors thrown for config and test/spec files (babel.config.js, jest.config.js, index.test.ts)
ttristan opened this issue · comments
I would like to use KEBAB_CASE for almost all files and overall it seems to work well, however I think some cases are matched too loosely.
This is my config:
“check-file/filename-naming-convention”: [
“error”,
{
“*.{js,ts,jsx,tsx,json}“: “KEBAB_CASE”
}
],
“check-file/folder-naming-convention”: [
“error”,
{
“src/**“: “KEBAB_CASE”,
“packages/**“: “KEBAB_CASE”
}
]
However I think these errors are false positives:
1:1 error The filename “babel.config.js” does not match the “KEBAB_CASE” style check-file/filename-naming-convention
7:1 error The filename “jest.config.js” does not match the “KEBAB_CASE” style check-file/filename-naming-convention
3:1 error The filename “index.test.ts” does not match the “KEBAB_CASE” style check-file/filename-naming-convention
3:1 error The filename “index.spec.ts” does not match the “KEBAB_CASE” style check-file/filename-naming-convention
3:1 error The filename “some-test.spec.ts” does not match the “KEBAB_CASE” style check-file/filename-naming-convention
Also I could not make it work with other cases:
3:1 error The filename “some-test.spec.ts” does not match the “CAMEL_CASE” style check-file/filename-naming-convention
3:1 error The filename “some_test.spec.ts” does not match the “SNAKE_CASE” style check-file/filename-naming-convention
I could not find away to adjust the file matching to make it work or exclude the rule for these files without disabling eslint for them entirely.
I think .config
, .test
and .spec
should be valid for KEBAB_CASE and most other as well.
Any suggestions to change my config or could this be improved in the file name matching?
*.{js,ts,jsx,tsx,json}
matches all js
and ts
files, of course including babel.config.js
, jest.config.js
and index.test.ts
files.
If you want to exclude these keywords (.config
, .test
and .spec
), you can try !(*.spec|*.test|*.config).{js,ts}
to match the target files.
I guess that was the matcher I was looking for to fix it. Although it would not enforce the file naming for files like apiTest.spec.ts
it is acceptable for me. Thanks!
Currently, you can add an additional rule for the *.spec.ts
file if you really wish to lint it, but it will require a more complex glob expression.
In the future, I will add support for ignoring common keywords. Thank you for your feedback.
I am getting next error:
The folder "__tests__" does not match the "KEBAB_CASE" style
__tests__
can be located inside src
.
I am trying ignore __tests__
folder with next syntax bit it does not work.
check-file/folder-naming-convention:
- error
- src/**/: KEBAB_CASE
"src/**/__tests__/": SNAKE_CASE
mocks/*/: KEBAB_CASE
You can try src/!(__tests__)/**/
to ignore __tests__
folder in src
.
Using the glob pattern, it doesn't report the cases, it just ignore all folders
Tried with src/!(__tests__)/**/
or src/**/!(__tests__)/*
"check-file/folder-naming-convention": [
"error",
{
"src/!(__tests__)/**/": "KEBAB_CASE",
},
],