admin管理员组文章数量:1236577
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?
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?
Share Improve this question asked Jun 5, 2016 at 21:14 WitVaultWitVault 24.1k20 gold badges106 silver badges137 bronze badges 3- Hmm, I suspect that rule was created specifically to catch the code you want to allow. – Barmar Commented Jun 5, 2016 at 22:18
- @Barmar Should I remove this rule then? – WitVault Commented Jun 6, 2016 at 12:48
- Probably, I doubt there's any way to get it to distinguish the two cases. – Barmar Commented Jun 6, 2016 at 15:53
1 Answer
Reset to default 16This 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.
本文标签: javascriptHow to add exception to a eslint ruleStack Overflow
版权声明:本文标题:javascript - How to add exception to a eslint rule? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739478383a2165024.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论