"lint": "eslint -c .eslintrc.json --fix src/**/*.ts test/**/*.ts *.ts",
"lint:prod": "eslint -c .eslintrc.prod.json --fix src/**/*.ts test/**/*.ts *.ts",
Note the duplicative paths in these NPM scripts. And there is one more that look pretty much the same in the lint-staged
config.
It seems I cannot omit the paths, and have eslint use its config file (.eslintrc.json
) to find the files to lint:
"overrides": [
{
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"files": [
"src/**/*.ts",
"test/**/*.ts",
"*.ts"
]
}
]
At least, with that config in place, and running npx eslint -c .eslintrc.json
, no files are checked. Adding the paths to the command line does check the files.
I guess overrides[].files
only tells the related parser which files to look at, but not eslint itself.
Is it not supported to just use the config file to figure out which files to check?
2
Answers
Take advantage of npm scripts themselves and have a script that does "the shared bits", and invoke it with "the bits that are different":
(Also note the quotes around the glob, which eslint says is necessary, and that they’re double quotes rather than single quotes, to make sure things work on every OS. Single quotes will break on Windows)
If you specify a folder to lint on the command line,
eslint
uses thefiles
property from the overrides in the configuration file to find files to lint in that folder. See eslint documentation about specifying target files to lint.So instead of
npx eslint -c .eslintrc.json
you need to runnpx eslint -c .eslintrc.json .
to try this out. The only difference is the.
at the end: the folder to lint.And in your
package.json
scripts you probably want something like:While it is annoying to put the
.
there, it does not create a maintenance burden because it will not change in the future. The actual configuration about which files to lint is maintained only once in the configuration file.