1
votes

I want to override the rule @typescript/type-annotation-spacing which determines how many spaces to put before and after : in type annotations.

I would like to override it to have a space before and after :, but the default it to just have one after.

The documentation describes several options for this rule, but it does not give any example of the full syntax for overriding this in the eslintrc.* file.

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 = () => {}).

I tried adding this to my eslintrc file

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

but then I get this error:

   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" }').

I tried several other variations, but they all result in a similar error.

What is the correct syntax for this?

1
I would assume, the syntax is the same as for vanilla eslint. Check out their docs for the syntax.Peter Lehnhardt
well it would be good if you could say what you have done, instead of downvoting. and then read the doc btwjcuypers
Nothing wrong with downvoting a solutiin that doesnt workJamesFaix

1 Answers

4
votes

I checked out the ESLint documentation, and it shows putting multiple options for a rule in an array. This works:

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