【问题标题】:set options for rule in .eslintrc.json在 .eslintrc.json 中设置规则选项
【发布时间】:2020-01-15 17:42:42
【问题描述】:

我想使用 this rule 并将 ignoreParameters 选项设置为 false。我的 eslint 配置了 .eslintrc.json 文件,我无法找到如何在此文件中设置规则的选项。我查看了文档并在 Google 上搜索,并查看了 this question,但我找不到如何使用 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
     }
   ]
 }
}

感谢您的帮助。

【问题讨论】:

    标签: typescript tslint


    【解决方案1】:

    所以我尝试的所有东西实际上都使用了正确的语法(我仍然会提出这个问题,因为我没有找到带有选项的 .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
          }
        ]
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-12
      • 2015-09-06
      • 2021-08-12
      • 1970-01-01
      • 1970-01-01
      • 2017-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多