简体   繁体   English

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

[英]ESlint: Turning off a specific rule across a project

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.我已经阅读了有关如何从文件中禁用规则的文档,但是我想知道是否有一种方法可以禁用或覆盖.eslintrc规则而不覆盖我定义的其他以前的规则和预设。 I'm working in an AngularJS project so I used extends property inside my .eslintrc file.我在一个 AngularJS 项目中工作,所以我在我的.eslintrc文件中使用了extends属性。

There are 3 specific rules from the angular ESlint plugin that I would like to disable, without disabling everything else I was using previously.我想禁用 angular ESlint 插件中的 3 个特定规则,而不禁用我以前使用的所有其他规则。

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.如果没有rules属性,我的所有 lint 规则都可以正常工作(间距、语法错误等),但是我自然不想出现两个 lint 错误。 However, with the rules property attached, all of my previous rules no longer get applied (spacing grammar errors etc).但是,附加了rules属性后,我以前的所有规则都不再适用(间距语法错误等)。

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"
  }
}

In you .eslintrc you have two rules keys.在您.eslintrc 中,您有两个rules键。 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 config file that disables all rules individually.单独禁用所有规则的 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?这是一个 Eslint 配置 (eslintrc.json) 文件,它关闭了所有规则,以便您可以逐个规则地更改代码,而不是更改所有代码以适应所有规则?

https://github.com/ajmaurya99/eslint-rules https://github.com/ajmaurya99/eslint-rules

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM