5
votes

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.

3
Just came across this and discovered that as of a week ago the package linked above now "supports all eslint core rules and 3rd-party plugins(except for scoped packages)." - Ben

3 Answers

6
votes

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.

0
votes

Ok here’s another idea. Convert you .eslinrc file into .eslintrc.js. This will allow you to programmatically set eslint config.

Then you could use the commander library to detect the —fix flag and set a Boolean to determine which eslint rules you would like to disable.

0
votes

Using an .eslintrc.js file you can do something like this:

const isFixMode = process.argv.includes('--fix');

const config = {
  rules: {
    'no-console': 'error',
    ...(isFixMode && {
      'no-console': 'warn',
    }),
  },
};

export.modules = config;