【问题标题】:How do you resolve conflicting linting rules in VSCode between eslint and typescript-eslint如何解决 VSCode 中 eslint 和 typescript-eslint 之间冲突的 linting 规则
【发布时间】:2019-12-19 11:33:51
【问题描述】:

我的 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',
  ],
}

当我打开一个未正确格式化为选项卡的新文件时,我得到:

很公平,所以我使用 VScode 将缩进更改为制表符,现在我得到:

???

我已经配置了我的设置,以便所有扩展都从项目根目录中的一个 eslintrc 文件中读取...

【问题讨论】:

    标签: typescript visual-studio-code eslint


    【解决方案1】:

    由于您没有发布您的漏洞.eslintrc.js 配置,我只能假设您已扩展到推荐的规则集之外的一些规则集,这会导致您不希望出现多个规则正在运行的行为...

    根据您想要的这两条规则中的哪一条,您只需将其添加到您的规则中即可简单地停用另一条,例如:

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

    这将为您的项目停用@typescript-eslint/indent 规则。

    【讨论】:

    • 嗯,好的,谢谢,我会试试的。添加了我的.eslintrc.js 文件
    • 看了一眼你扩展的"standard-with-typescript",似乎这打开了"@typescript-eslint/indent"。如果可以停用其中一个,请将答案标记为已接受;)
    • 确实有效。我最终回到了带有 typescript 的标准,只是卸载了 typescript-eslint 扩展
    【解决方案2】:

    我的首选解决方案是禁用基本 indent 规则并按照此处的建议配置覆盖 @typescript-eslint/indent 规则:https://github.com/typescript-eslint/typescript-eslint/blob/87b7dbbc8d25d059e34888ec28026bfb4ade2215/packages/eslint-plugin/docs/rules/indent.md

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

    我发现禁用@typescript-eslint/indent 规则以支持基本indent 规则只是在代码编辑器中隐藏了错误,同时仍然导致编译失败!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-16
      • 1970-01-01
      • 2020-08-04
      • 2020-06-19
      • 2018-07-18
      • 2021-04-14
      • 2019-11-10
      • 2021-01-02
      相关资源
      最近更新 更多