簡體   English   中英

你如何解決 eslint 和 typescript-eslint 之間 VSCode 中沖突的 linting 規則

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

我的 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 文件中讀取...

由於您沒有發布您的漏洞.eslintrc.js配置,我只能假設您.eslintrc.js一些推薦的規則集,這會導致您不想要的行為,即多個規則正在運行......

根據您想要的這兩個規則中的哪一個,您可以通過將其添加到您的規則中來簡單地停用另一個規則,例如:

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

這將為您的項目停用@typescript-eslint/indent規則。

我的首選解決方案是禁用基本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]
}

我發現禁用@typescript-eslint/indent規則而支持基本indent規則只會隱藏代碼編輯器中的錯誤,同時仍然導致編譯失敗!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM