Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable autofix for specific rules in eslint using CLI?

Tags:

eslint

I want to be able to disable the rules that --fix fixes when running eslint in a console for a repo. The reason for this is because --fix leads to undesirable behavior for our jsdoc eslint rules. It creates invalid or sometimes empty jsdoc in our project- which typically leads to even more eslint rules (due to our configuration) and leads to tons of manual fixing or removal.

I want to just run --fix without it touching any jsdoc rules so that I can complete jsdoc manually- while eslint fixes all the rest of the rules.

I came across this SO question- but package mentioned in the answer does not support non-core plugins.

ESLint autofix ignore rule

Is there anything I can do short of modifying my eslintrc file every time I run the linter or using vscode for linting and modifying the config for the web editor instead? Its not a big deal for newer files- but linting legacy files is a chore when there's hundreds of spacing errors that I can't automatically fix easily.

like image 409
chevybow Avatar asked Jul 13 '20 22:07

chevybow


People also ask

How do I disable a specific ESLint rule?

If you want to disable an ESLint rule in a file or on a specific line, you can add a comment. On a single line: const message = 'foo'; console. log(message); // eslint-disable-line no-console // eslint-disable-next-line no-console console.

How do I disable ESLint for few lines?

To temporarily turn off ESLint, you should add a block comment /* eslint-disable */ before the lines that you're interested in: /* eslint-disable */ console.


1 Answers

Technically, that already exists, right? If a user wants to avoid auto-fixing a particular rule, they can use:

eslint somedir --fix --rule "somerule: 0"

Or, if they want to whitelist a set of rules, they can use &nbps --no-eslintrc and specify rules directly or use --config and point to a particular config that they want to use for fixes.

like image 72
Tharindu Vindula Avatar answered Sep 28 '22 05:09

Tharindu Vindula