在 .eslintrc.json 中设置规则选项

set options for rule in .eslintrc.json

我想使用 this rule with the ignoreParameters option set to false. My eslint is configured with a .eslintrc.json file and I can't manage to find how to set the options for a rule in this file. I've looked the doc and googled, and I looked at ,但我找不到如何使用 eslint 和 .eslintrc.json 文件为规则设置选项的示例。

这是我尝试添加此规则之前的 .eslintrc.json 文件(已应用该规则,但使用默认选项而不是我想要的选项):

{
  "parser": "@typescript-eslint/parser",
  "extends": [
    "react-app",
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "rules": {
    "@typescript-eslint/explicit-function-return-type": 0,
    "@typescript-eslint/no-explicit-any": 0,
    "no-return-await": 2,
    "curly": 2
  }
}

这是我尝试过的方法,总是导致规则不再适用(出现错误 Definition for rule '@typescript-eslint/no-inferable-types' was not found @typescript-eslint/no-inferable-types):

{
  "parser": "@typescript-eslint/parser",
  "extends": [
    "react-app",
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "rules": {
    "@typescript-eslint/explicit-function-return-type": 0,
    "@typescript-eslint/no-explicit-any": 0,
    "no-return-await": 2,
    "curly": 2,
    "@typescript-eslint/no-inferable-types": [
      "error",
      {
        "ignoreParameters": true
      }
    ]
  }
}

或:

{
 "parser": "@typescript-eslint/parser",
 "extends": [
   "react-app",
   "eslint:recommended",
   "plugin:@typescript-eslint/recommended",
   "prettier/@typescript-eslint",
   "plugin:prettier/recommended"
 ],
 "rules": {
   "@typescript-eslint/explicit-function-return-type": 0,
   "@typescript-eslint/no-explicit-any": 0,
   "no-return-await": 2,
   "curly": 2,
   "@typescript-eslint/no-inferable-types": [
     2,
     {
       "ignoreParameters": true,
       "ignoreProperties": false
     }
   ]
 }
}

感谢您的帮助。

所以我尝试的所有事情实际上都使用了正确的语法(我仍然会提出这个问题,因为我没有找到带有选项的 .eslinrc.json 文件示例的明确资源,导致我在错误的地方搜索问题)。

我的问题是我试图更改规则 no-inferrable-types 并且我在我的 .eslintrc.json 文件 no-inferable-types 中写了规则(少了一个 "r")。

因此我的(工作).eslintrc.json 是这样的:

{
  "parser": "@typescript-eslint/parser",
  "extends": [
    "react-app",
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "rules": {
    "@typescript-eslint/explicit-function-return-type": 0,
    "@typescript-eslint/no-explicit-any": 0,
    "no-return-await": 2,
    "curly": 2,
    "@typescript-eslint/no-inferrable-types": [
      2,
      {
        "ignoreParameters": true
      }
    ]
  }
}