Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

[indent] regression with typescript-eslint-parser@20.1.0 #271

Closed
scottohara opened this issue Jan 2, 2019 · 2 comments
Closed

[indent] regression with typescript-eslint-parser@20.1.0 #271

scottohara opened this issue Jan 2, 2019 · 2 comments

Comments

@scottohara
Copy link
Contributor

This issue was originally posted over at eslint/typescript-eslint-parser#586; but it was suggested that it be raised here as well. Please refer to the original issue for additional commentary/discussion.

Repro

{
  "parser": "typescript-eslint-parser",
  "plugins": ["typescript"],
  "rules": {
    "indent": "off",
    "typescript/indent": ["error", "tab", {"VariableDeclarator": {"const": 3}}]
  }
}

(in the code below, ^ represents a tab character)

interface Foo {
  a: number;
  b: number;
}

const foo: Foo = {
^ ^ ^ ^ a: 1,
^ ^ ^ ^ b: 2
^ ^ ^ },
^ ^ ^ bar = 1;

Expected Result
No errors

Actual Result
In typescript-eslint-parser@20.0.0, code passes with no errors.

With typescript-eslint-parser@20.1.0 onwards, the errors below occur:

7:1  error  Expected indentation of 1 tab but found 4   indent
8:1  error  Expected indentation of 1 tab but found 4   indent
9:1  error  Expected indentation of 0 tabs but found 3  indent

Additional Info
The code can be modified like below to pass, but clearly this is not what the config intends:

const foo: Foo = {
  a: 1,
  b: 2
},
      bar = 1

Vanilla JS code without a type annotation passes as expected:

const foo = {
        a: 1,
		b: 2
      },
      bar = 1;

It also worth noting that the same issue occurs when using:

  • spaces instead of tabs
  • the main indent rule from eslint instead of the typescript/indent rule from eslint-plugin-typescript
eslint-plugin-typescript typescript-eslint-parser indent typescript/indent
0.14.0 20.0.0 N/A
1.0.0-rc.0 20.0.0
0.14.0 20.1.0+ N/A
1.0.0-rc.0 20.1.0+

Versions

package version
eslint 5.11.1
typescript 3.1.1
eslint-plugin-typescript 0.14.0+
typescript-eslint-parser 20.1.0+
@bradzacher bradzacher changed the title Indent rule regression starting with typescript-eslint-parser@20.1.0 [indent] regression with typescript-eslint-parser@20.1.0 Jan 2, 2019
@bradzacher bradzacher added bug/incomplete rule requires investigation bug that require more investigation parser bug bugs with typescript-eslint-parser / typescript-estree labels Jan 2, 2019
@bradzacher
Copy link
Owner

It is known that v20+ of the parser breaks when using plugin version 0.14. They released a number of breaking changes which we had to handle ourselves. IIRC the only supported version for plugin v0.14 was parser@^17.

For the plugin 1.0.0 rc - we have moved the parser dependency into our plugin, so that we can control which version users are using.

Could you please try to switch your parser to use our exposed version, and let me know if it's still an issue?


Excerpt from: https://github.com/bradzacher/eslint-plugin-typescript/releases/tag/1.0.0-rc.0

  1. Update your config to use our exported parser:
 {
-    "parser": "typescript-eslint-parser",
+    "parser": "eslint-plugin-typescript/parser",
     "plugins": ["typescript"]
 }
  1. remove your direct dependency on the parser:
$ yarn remove typescript-eslint-parser
$ npm uninstall typescript-eslint-parser

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP and removed requires investigation bug that require more investigation labels Jan 2, 2019
@scottohara
Copy link
Contributor Author

scottohara commented Jan 2, 2019

Thanks @bradzacher.

Unfortunately, the problem is the same when using "parser": "eslint-plugin-typescript/parser".

package.json

"dependencies": {
  "eslint": "5.11.1",
  "eslint-plugin-typescript": "1.0.0-rc.1",
  "typescript": "3.1.1"
}

.eslintrc.json

{
  "parser": "eslint-plugin-typescript/parser",
  "plugins": ["typescript"],
  "rules": {
    "indent": "off",
    "typescript/indent": ["error", "tab", {"VariableDeclarator": {"const": 3}}]
  }
}

index.ts

interface Foo {
  a: number;
  b: number;
}

const foo: Foo = {
        a: 1,
        b: 2
      },
      bar = 1;

output

7:1  error  Expected indentation of 1 tab but found 4   typescript/indent
8:1  error  Expected indentation of 1 tab but found 4   typescript/indent
9:1  error  Expected indentation of 0 tabs but found 3  typescript/indent

@no-response no-response bot removed the awaiting response Issues waiting for a reply from the OP label Jan 2, 2019
@bradzacher bradzacher added requires investigation bug that require more investigation and removed parser bug bugs with typescript-eslint-parser / typescript-estree requires investigation bug that require more investigation labels Jan 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants