typescript - 在 .eslintrc.json 中设置规则选项
问题描述
我想将此规则与设置为 false 的 ignoreParameters 选项一起使用。我的 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
}
}
这是我尝试过的,总是导致不再应用规则(出现错误 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
}
]
}
}
推荐阅读
- android - 16:跳过密码保存,因为可能会提示用户使用 Android Autofill
- python - 如何将 pygame.Surface.scroll() 用于特定 blit() 图像
- c# - 提示用户输入通过 Process.start() 启动的应用程序
- excel - 如何从电子表格中提取数据并使用该值?节点
- mongodb - 在 M1 Apple 芯片上安装 mongodb 时无法点击 mongodb/brew:tap 中的语法无效
- python - python XLRD库如何扫描excel中的所有工作表?
- java - 覆盖具有相同类策略与策略实例的 equals 方法
- sql - 在 SQL Server 数据库中查找以小写字母开头的列并将它们列为 SELECT 语句
- php - PHP Elastic Search - 在执行搜索之前获取所有文档(以节省时间/性能)
- c - 如何实现“malloc”和“fgets”来读取和打印输入流