ESlint:关闭项目中的特定规则 [英] ESlint: Turning off a specific rule across a project
问题描述
我已经阅读了有关如何从文件中禁用规则的文档,但是我想知道是否存在一种方法,可以从.eslintrc
禁用或覆盖规则而不覆盖其他先前的规则& ;;我定义的预设.我在AngularJS项目中工作,所以我在.eslintrc
文件中使用了extends
属性.
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.
在不禁用我以前使用的所有其他功能的情况下,我想禁用有角度的ESlint插件中的3条特定规则.
There are 3 specific rules from the angular ESlint plugin that I would like to disable, without disabling everything else I was using previously.
没有rules
属性,我所有的整理规则都可以正常工作(间隔,语法错误等),但是我不想出现的两个皮棉错误自然而然地出现了.但是,附加了rules
属性后,我以前的所有规则都不再适用(语法错误等).
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"
}
}
推荐答案
在您的 .eslintrc 中,您有两个rules
键.第二个将覆盖第一个.这是规则合并在一起的文件:
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"
}
这篇关于ESlint:关闭项目中的特定规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!