我想覆盖@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 = () => {}).
Run Code Online (Sandbox Code Playgroud)
我尝试将其添加到我的eslintrc文件中
"rules": {
"@typescript-eslint/type-annotation-spacing": {
before: true,
after: true,
severity: "warn"
}
}
Run Code Online (Sandbox Code Playgroud)
但后来我收到了这个错误:
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" }').
Run Code Online (Sandbox Code Playgroud)
我尝试了其他几种变体,但它们都导致了类似的错误。
什么是正确的语法?
我查看了 ESLint 文档,它显示了将规则的多个选项放入数组中。这有效:
"rules": {
"@typescript-eslint/type-annotation-spacing": ["warn", {
before: true,
after: true
}]
}
Run Code Online (Sandbox Code Playgroud)