ESlint:关闭项目中的特定规则

ESlint: Turning off a specific rule across a project

我已经阅读了有关如何从文件中禁用规则的文档,但是我想知道是否有一种方法可以在不覆盖其他以前的规则和预设的情况下禁用或覆盖 .eslintrc 中的规则我定义。我在一个 AngularJS 项目中工作,所以我在我的 .eslintrc 文件中使用了 extends 属性。

我想禁用 angular ESlint 插件中的 3 个特定规则,而不禁用我之前使用的所有其他内容。

没有 rules 属性 我所有的 linting 规则都可以正常工作(间距、语法错误等),但是我不希望出现的两个 lint 错误自然会出现。但是,随着 rules 属性 的附加,我以前的所有规则都不再适用(间距语法错误等)。

我可以只声明一个规则来禁用我不想在我的文件顶部应用的特定规则,但是这非常重复(这是我之前所做的)。

{
  "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 键。第二个将覆盖第一个。这是合并了规则的文件:

{
  "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 配置文件。

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