For a legacy project, running ESLint is not yet meaningful as there are way too many errors.
Yet, as a first step for improvement, I want to check for one rule and one rule only, e.g. no-console
.
ESLint is installed globally, and now I want a single-line command to check my codebase only for errors of that one rule.
I don't want to create any config file, nor should anything else be installed/added in that project.
npm init @eslint/config@latest
creates a config file with way too many rules applied, and it also installs packages in the current project.
The repository shall remain completely unaware that eslint
exists, so I don't want these files and folders:
eslint.config.mjs
node_modules/
package-lock.json
package.json
I thought that:
eslint --no-config-lookup --rule "no-console: error" ./my_js_folder/
would do what I wanted, yet I see other errors for other rules as well, e.g.:
Even some warnings pop up, like:
35628:25 warning Unused eslint-disable directive (no problems were reported from 'no-new')
I was expecting only errors for usage of console.log
, console.warn
, console.error
, etc.
How do I achieve that?
It turns out that the additonal rules were added by comments within javascript files.
Example: some.js
:
console.log('this should be reported');
/* eslint quotes: ["error", "double"], curly: 2 */
const thisShouldNotBeReported = 'this is unexpected';
eslint --no-config-lookup --rule "no-console: error" some.js
eslint_example/some.js
1:1 error Unexpected console statement no-console
1:13 error Strings must use doublequote quotes
5:33 error Strings must use doublequote quotes
ā 3 problems (3 errors, 0 warnings)
2 errors and 0 warnings potentially fixable with the `--fix` option.
How to disable the in-file config so that only the rule from the command line is applied?
You need to add:
--no-inline-config Prevent comments from changing config or rules
Somewhere in your project, you have rules defined as code, and those trigger these error you then see.
This should achieve your goal:
eslint --no-inline-config --no-config-lookup --rule "no-console: error" ./my_js_folder/