8000 [indent] Multiline type declaration with arrow functions and implicit return results in indent error · Issue #398 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content
< 8000 template class="js-flash-template">

[indent] Multiline type declaration with arrow functions and implicit return results in indent error #398

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
renodesu opened this issue Apr 2, 2019 · 3 comments
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@renodesu
Copy link
renodesu commented Apr 2, 2019

Defining type with multiline arrow function with implicit return causes falsy indent error.

Repro

{
  "rules": {
    "@typescript-eslint/indent": [2, 2]
  }
}
type SomeType = () =>
  string // Expected indentation of 0 spaces but found 2. (@typescript-eslint/indent)
type SomeOtherType = () => string // No error

const SomeConst = () =>
  'test' // No error
const SomeOtherConst = () => 'test' // No error

Expected Result
Expect (arrow function) type declarations behave identically to (arrow function) const declarations when using implicit return.

Actual Result
First test case (SomeType) throws indent error, seemingly not respecting set indent rules.
Same rule demonstrated to work with const.

Additional Info
If the same "arrow function logic" doesn't apply here when indenting , make it clear what does.

Versions

package version
@typescript-eslint/eslint-plugin 1.5.0
@typescript-eslint/parser 1.5.0
TypeScript 3.4.0
ESLint 5.16.0
node 10.13.0
npm 6.4.1
@renodesu renodesu added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Apr 2, 2019
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for team members to take a look labels Apr 7, 2019
@bradzacher bradzacher added this to the indent rewrite milestone Apr 19, 2019
@JaceHensley
Copy link
JaceHensley 8000 commented Apr 29, 2019

I'm having a similar issue but with combining multiple types with a type literal

// No Error
type MyType = Type1 & Type2 & {
  otherField: string
}

// Errors
type MyType = Type1 &
  Type2 & { // Expected indentation of 0 spaces but found 2
    otherField: string // Expected indentation of 2 spaces but found 4
  } // Expected indentation of 0 spaces but found 2

@bradzacher
Copy link
Member

@JaceHensley - you mightn't realise, but eslint doesn't actually care about indentation of binary expressions.
https://eslint.org/demo/#eyJ0ZXh0IjoiLyogZXNsaW50IGluZGVudDogW1wiZXJyb3JcIl0gKi9cbmNvbnN0IHggPSAxXG4mIDJcbnwgMyIsIm9wdGlvbnMiOnsicGFyc2VyT3B0aW9ucyI6eyJlY21hVmVyc2lvbiI6OSwic291cmNlVHlwZSI6Im1vZHVsZSIsImVjbWFGZWF0dXJlcyI6e319LCJydWxlcyI6eyJpbmRlbnQiOjJ9LCJlbnYiOnsiY29tbW9uanMiOmZhbHNlLCJub2RlIjpmYWxzZX19fQ==

It asking for 0 indentation for type is indeed a bug. When I looked into fixing it, I found out they specifically don't enforce indentation. It's relatively easy to add like-for-like support so that it ignores indentation of binary type expressions. I just left it as is and instead decided to work on a complete rewrite of the indent rule to add true, non-hacky support for TS nodes, but that is a while away.

@bradzacher
Copy link
Member

Merging into #1824

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

3 participants
0