9
votes

I am trying to use linting rule -- Disallow multiple spaces (no-multi-spaces) in my eslint configuration file. I am using current latest version of eslint.

I know that this rule does not allows multiple spaces in statments e.g

if(foo  === "bar") {}

It will fail here, which is perfectly fine. But It will fail in this case also

var React          = require('react');
var ReactRouter    = require('react-router');

I don't want the rule to be applied here.

Is there any way I can stop lint rule from being applied in this case of variable declaration?

1
Hmm, I suspect that rule was created specifically to catch the code you want to allow.Barmar
@Barmar Should I remove this rule then?WitVault
Probably, I doubt there's any way to get it to distinguish the two cases.Barmar

1 Answers

12
votes

This rule (no-multi-spaces) has an option exceptions that you can configure to ignore all variable declarations. Configuration should look something like this:

no-multi-spaces: ["error", { exceptions: { "VariableDeclarator": true } }]

This will skip all of the variable declarations from the check.

In general, you can also use comments to disable any of the ESLint rules. ESLint supports block style comments: /* eslint-disable */ /* eslint-enable */ to disable all rules or /* eslint-disable rule-name */ /* eslint-enable rule-name*/ to disable specific rule. Everything between disable and enable comments will be ignored. You can also use inline comments as well: // eslint-disable-line to disable all rules for current line, or // eslint-disable-line rule-name to disable specific rule. Same applies to // eslint-disable-next-line but for the following line.

If all else fails, you can just disable the rule in the configuration. If you find yourself in the situation were you need to use comments constantly, most likely this rule just doesn't fit your coding style. Not every rule fits everyone, and there's no prize for enabling as many rules as possible.