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

Jon*_*ney 1 typescript tslint

我想在将ignoreParameters 选项设置为false 的情况下使用此规则。我的 eslint 配置了一个.eslintrc.json文件,但我无法找到如何设置该文件中规则的选项。我查看了文档并用谷歌搜索,我查看了这个问题,但我找不到如何使用 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
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的,总是导致规则不再被应用(有错误 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
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

或者 :

{
 "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
     }
   ]
 }
}

Run Code Online (Sandbox Code Playgroud)

感谢您的帮助。

Jon*_*ney 6

所以我尝试的所有事情实际上都是使用正确的语法(我仍然会提出这个问题,因为我没有找到带有选项的文件示例的明确资源.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
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)