English 中文(简体)
Eslint无视我的规则环境,即“无所利用的”
原标题:Eslint ignoring my rule settings "no-unused-vars"

在我行走时,仍然把这一规则视为错误。 此前,我已制定了<条码>无使用-瓦尔<>/代码>和<条码>@打字-eslint/no-unuse-vars,以便在文件上发出警告。

我曾尝试过<条码>“无使用-惯例”: 1和-no-un used-vars”:“warn”,但无效果。

Why is eslint ignoring my rule settings?

eslintrc案

{
  "root": true,
  "env": {
    "node": false,
    "browser": true
  },
  "globals": {
    "google": true,
    "process": true
  },
  "parser": "@babel/eslint-parser",
  "parserOptions": {
    "sourceType": "module",
    "ecmaVersion": "latest",
    "requireConfigFile": false
  },
  "overrides": [
    {
      "files": ["*.{ts,tsx}"],
      "parser": "@typescript-eslint/parser",
      "plugins": ["@typescript-eslint"],
      "extends": ["plugin:@typescript-eslint/recommended"] // needed for ts
    }
  ],
  "rules": {
    "@typescript-eslint/no-unused-vars": 1, // < ----- this wont set it to a warning
    "no-unused-vars": 1, // < ----- this wont set it to a warning, still error
  }
}
问题回答

The "overrides" > "extends": ["plugin:@typescript-eslint/recommended"] is setting the rule to a new setting for you. overrides does what the name suggests: it overrides the base settings. Move the rules object into the "overrides".

"overrides": [
    {
      // etc. etc.
      "extends": ["plugin:@typescript-eslint/recommended"],
      "rules": { /* reconfigure rules here */ }
    }
  ]

https://eslint.org/docs/latest/use/configure/configuration-filesconfiguration-based-on-glob-patterns#, 供查阅的ESLint config文档格式上的文件。

new ESLint “flat” config file Format,使这一点更加清楚。





相关问题
My VSCode is not showing errors and fixing on save

I configured my eslint to display errors in my code and also configured vscode to fix on save. The problem is that the errors are displayed in the terminal but not in vscode and the fix on save does ...

热门标签