bradzacher/eslint-plugin-typescript

[indent] Extend base rule to support typescript nodes

Closed this issue ยท 9 comments

#174 adds some tests for indent which covers some default eslint cases.

Unfortunately the rule is designed such that it completely ignores non-standard nodes (i.e. all of the new typescript nodes introduced in parser v20+).

Specifically we need to support:

  • TSTypeLiteral
  • TSInterfaceBody
  • TSImportEqualsDeclaration

@bradzacher tests for this are done in parser, but sure, more test is always better

You added the test here!
https://github.com/armano2/eslint-plugin-typescript/blob/7cf0b229504e3539fe9bf832cd0352c38234c1c9/tests/lib/rules/indent.js

However, it has valid cases only.
If we add invalid cases we can ensure that decorators/types/interfaces are correctly fixed so we can detect regressions.

Hmm yeah instantly can see the value in this...

I added this invalid test case, and it fails:

        {
            code: `
interface Foo {
bar : string,
age : number,
}
            `,
            output: `
interface Foo {
    bar : string,
    age : number,
}
            `,
            errors: [
                {
                    message: `Expected indentation of 4 spaces but found 0.`,
                    line: 3,
                    column: 1,
                },
                {
                    message: `Expected indentation of 4 spaces but found 0.`,
                    line: 4,
                    column: 1,
                },
            ],
        },

it means that its working as expected, eslint is not supporting TS nodes, and there is/was bunch of issues that nodes was handled incorrectly.

we should write new rule that extends eslint rule to support indent in TS specific nodes

As a plugin developer that knows its purposely designed to not support typescript ast nodes, sure it's working correctly.

As a user that wants their interfaces and type literals indented; the rule is broken.

i can work on this after i solving issue with array-type

I'm already hacking away at it!

Is it possible to add a fix (if not already fixed) for eslint/typescript-eslint-parser#577 too?