gpt4 book ai didi

typescript - 如何覆盖此 ESLint TypeScript 规则?

转载 作者:行者123 更新时间:2023-12-05 08:26:14 25 4
gpt4 key购买 nike

我想覆盖 @typescript/type-annotation-spacing 规则,该规则决定在类型注释中 : 前后放置多少空格。

我想覆盖它以在 : 前后各留一个空格,但默认情况下它后面只有一个空格。

文档描述了这个规则的几个选项,但它没有给出在 eslintrc.* 文件中覆盖它的完整语法的任何示例。

https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/type-annotation-spacing.md

This rule has an object option:

"before": false, (default for colon) disallows spaces before the colon/arrow.
"before": true, (default for arrow) requires a space before the colon/arrow.
"after": true, (default) requires a space after the colon/arrow.
"after": false, disallows spaces after the colon/arrow.
"overrides", overrides the default options for type annotations with colon (e.g. const foo: string) and function types with arrow (e.g. type Foo = () => {}).

我尝试将其添加到我的 eslintrc 文件中

"rules": {
"@typescript-eslint/type-annotation-spacing": {
before: true,
after: true,
severity: "warn"
}
}

但是我得到了这个错误:

   Configuration for rule "@typescript-eslint/type-annotation-spacing" is invalid:
Severity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '{ before: true, after: true, severity: "warn" }').

我尝试了其他几种变体,但它们都会导致类似的错误。

正确的语法是什么?

最佳答案

我查看了 ESLint 文档,它显示了将规则的多个选项放入一个数组中。这有效:

 "rules": {
"@typescript-eslint/type-annotation-spacing": ["warn", {
before: true,
after: true
}]
}

关于typescript - 如何覆盖此 ESLint TypeScript 规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55680096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com