首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在.eslintrc.json中设置规则选项

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

Stack Overflow用户
提问于 2020-01-15 00:20:39
回答 1查看 2.9K关注 0票数 1

我想使用ignoreParameters选项设置为false的this rule。我的eslint是使用.eslintrc.json文件配置的,我无法找到如何在此文件中为规则设置选项。我已经查看了文档和谷歌,我查看了this question,但我找不到如何使用eslint和.eslintrc.json文件为规则设置选项的示例。

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

代码语言:javascript
复制
{
  "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):

代码语言:javascript
复制
{
  "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
      }
    ]
  }
}

或者:

代码语言:javascript
复制
{
 "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
     }
   ]
 }
}

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-15 17:42:43

因此,我尝试的所有内容实际上都使用了正确的语法(我仍然会让这个问题继续存在,因为我没有找到带有选项的.eslinrc.json文件示例的清晰资源,这导致我在错误的位置搜索问题)。

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

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

代码语言:javascript
复制
{
  "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
      }
    ]
  }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59737848

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档