eslint 缩进 - 多行三元表达式上标记的间距错误

问题描述 投票:0回答:1

我有以下代码片段,其中 eslint indent lints 我的多行三元表达式:

code snippet with error linting

这是我收到的错误:

Expected indentation of 8 spaces but found 16. eslint(indent)

因此 eslint 预计每个缩进有 2 个空格,尽管我指定应该有 4 个空格。我之前在 Switch Case 上也遇到过同样的问题,但通过编辑

.eslintrc.json
可以轻松解决该问题。这次,我找不到这样的修复方法。

我的

.eslintrc.json

{
  "env": { "browser": true, "node": true },
  "plugins": ["@typescript-eslint"],
  "parser": "@typescript-eslint/parser",
  "parserOptions": { "ecmaVersion": 2020 },
  "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
  "rules": {
    "@typescript-eslint/explicit-module-boundary-types": "off",
    "@typescript-eslint/member-ordering": "error",
    "@typescript-eslint/no-non-null-assertion": "off",
    "@typescript-eslint/no-use-before-define": ["error", { "functions": false }],
    "@typescript-eslint/no-var-requires": "off",
    "indent": ["error", 4, {"SwitchCase": 1}],
    "prettier/prettier": ["error", { "endOfLine": "auto" }]
  }
}

我想知道如何修复这个 linting 错误。

javascript typescript eslint
1个回答
0
投票

我明白了:

"indent": ["error", 4, {"SwitchCase": 1, "offsetTernaryExpressions": 1}]

...特别是“offsetTernaryExpressions”部分修复了问题。但是,请记住之后重新启动 eslint 服务器!我之前没有这样做,因此规则从未更新并且错误仍然存在。

这是在 vsCode 中通过

Ctrl + Shift + P
打开命令面板,然后选择
ESLint: Restart ESLint Server

来完成的
© www.soinside.com 2019 - 2024. All rights reserved.