问题
I've read the docs on how to disable rules from within a file, however I'm wondering if there is a way to disable or overwrite rules from .eslintrc
without overwriting other previous rules & presets I defined. I'm working in an AngularJS project so I used extends
property inside my .eslintrc
file.
There are 3 specific rules from the angular ESlint plugin that I would like to disable, without disabling everything else I was using previously.
Without the rules
property all of my linting rules work fine (spacing, grammar errors etc), but the two lint errors I don't want show up, naturally. However, with the rules
property attached, all of my previous rules no longer get applied (spacing grammar errors etc).
I could just declare a rule to disable the specific rule I don't want applied at the top of my file, but that get's very repetitive (that's what I had done previously).
{
"rules": {
"wrap-iife": [
2,
"inside"
],
"max-len": [
2,
120
],
"indent": [
2,
2
],
"no-with": 2,
"no-implicit-coercion": [
2, {
"string": true
}
],
"camelcase": [
2, {
"properties": "never"
}
],
"quotes": [
2,
"single"
],
"linebreak-style": [
2,
"unix"
],
"semi": [
2,
"always"
]
},
"env": {
"es6": true,
"browser": true,
"node": true
},
"ecmaFeatures": {
"modules": true
},
"globals": {
"angular": true
},
"extends": "angular",
//I just want to disable these rules & still use everything else
//but when I add this, everything else I had previously no longer
//applies
"rules": {
"angular/controller-as-vm": "off",
"angular/document-service": "off",
"angular/window-service": "off"
}
}
回答1:
In you .eslintrc you have two rules
keys. The second will overwrite the first. Here's the file with the rules merged together:
{
"rules": {
"wrap-iife": [
2,
"inside"
],
"max-len": [
2,
120
],
"indent": [
2,
2
],
"no-with": 2,
"no-implicit-coercion": [
2, {
"string": true
}
],
"camelcase": [
2, {
"properties": "never"
}
],
"quotes": [
2,
"single"
],
"linebreak-style": [
2,
"unix"
],
"semi": [
2,
"always"
],
"angular/controller-as-vm": "off",
"angular/document-service": "off",
"angular/window-service": "off"
},
"env": {
"es6": true,
"browser": true,
"node": true
},
"ecmaFeatures": {
"modules": true
},
"globals": {
"angular": true
},
"extends": "angular"
}
回答2:
ESLint config file that disables all rules individually.
This is a Eslint config (eslintrc.json) file that has all the rules turned off so that you can change your code on a rule by rule basis rather than changing all the code to fit all the rules?
https://github.com/ajmaurya99/eslint-rules
来源:https://stackoverflow.com/questions/37002574/eslint-turning-off-a-specific-rule-across-a-project