简体   繁体   English

你如何解决 eslint 和 typescript-eslint 之间 VSCode 中冲突的 linting 规则

[英]How do you resolve conflicting linting rules in VSCode between eslint and typescript-eslint

I have my eslinting rules as follows我的 eslinting 规则如下

module.exports = {
  env: {
    es6: true,
    node: true,
    mocha: true
  },
  extends: [
    "standard-with-typescript"
  ],
  parser: '@typescript-eslint/parser',
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly'
  },
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: 'module',
    project: "./tsconfig.json"
  },
  rules: {
    "quotes": ["warn", "single"],
    "indent": ["warn", "tab", { "ignoreComments": true }],
    "no-tabs": 0,
    "padded-blocks": 0,
    "semi": 0,
    "no-trailing-spaces": 0,
    "spaced-comment": 0,
    "no-multiple-empty-lines": 0,
    "space-before-function-paren": 0,
    "camelcase": 0,
    "prefer-const": "warn",
    "space-infix-ops": "warn",
    "@typescript-eslint/strict-boolean-expressions": ["warn", {"allowNullable": true}]
  },
  plugins: [
    '@typescript-eslint',
  ],
}

When I open a new file that is not properly formatted to tabs, I get:当我打开一个没有正确格式化为标签的新文件时,我得到:

预期误差

Fair enough, so I change indentation to tabs using VScode and now I get:很公平,所以我使用 VScode 将缩进更改为制表符,现在我得到:

在此处输入图片说明

??? ???

I have my settings configured so that all the extensions read from just one eslintrc file in the project root...我配置了我的设置,以便所有扩展名都只从项目根目录中的一个 eslintrc 文件中读取...

As you didn't posted your hole .eslintrc.js config i can only assume that you have extends to a few off the recommended rule sets which leads to your unwanted behavior that multiple rules are running...由于您没有发布您的漏洞.eslintrc.js配置,我只能假设您.eslintrc.js一些推荐的规则集,这会导致您不想要的行为,即多个规则正在运行......

Depending on which one of these two rules you want you can just simply deactivate the other one by adding this to you rules eg.:根据您想要的这两个规则中的哪一个,您可以通过将其添加到您的规则中来简单地停用另一个规则,例如:

"@typescript-eslint/indent": "off"

This will deactivate the @typescript-eslint/indent rule for your project.这将为您的项目停用@typescript-eslint/indent规则。

My preferred solution was to disable the base indent rule and configure an overriding @typescript-eslint/indent rule as suggested here: https://github.com/typescript-eslint/typescript-eslint/blob/87b7dbbc8d25d059e34888ec28026bfb4ade2215/packages/eslint-plugin/docs/rules/indent.md我的首选解决方案是禁用基本indent规则并按照此处的建议配置覆盖@typescript-eslint/indent规则: https : //github.com/typescript-eslint/typescript-eslint/blob/87b7dbbc8d25d059e34888ec28026bfb4ade2215/packages/eslint /docs/rules/indent.md

"rules": {
    "indent": "off",
    "@typescript-eslint/indent": ["error", 2]
}

I found disabling the @typescript-eslint/indent rule in favour of the base indent rule simply hid the errors in the code editor, while still causing compilation to fail!我发现禁用@typescript-eslint/indent规则而支持基本indent规则只会隐藏代码编辑器中的错误,同时仍然导致编译失败!

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

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