我想覆盖规则@typescript/type-annotation-spacing
,该规则确定在类型注释中在:
之前和之后放置多少空格。
我想重写它,使其在:
之前和之后都有一个空格,但是默认情况下,它在后面只有一个空格。
文档描述了此规则的几个选项,但未在eslintrc.*
文件中提供用于覆盖此规则的完整语法的任何示例。
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" }').
我尝试了其他几种变体,但是它们都会导致类似的错误。
正确的语法是什么?
答案 0 :(得分:0)
我签出了ESLint文档,它显示了将规则的多个选项放入数组中。这有效:
"rules": {
"@typescript-eslint/type-annotation-spacing": ["warn", {
before: true,
after: true
}]
}