Skip to content

Smart indentation on separated elements should reuse the prior element's starting base indentation #53548

Description

Consider what I'd call some "ideal" smart indentation for the following code samples:

typeFoo=|"hello"|"world";{|"indentation": 0 |}
letx=10,y=2;{|"indentation": 0 |}
letx=10,y=2,{|"indentation": 4 |}
letobj={x: "hello"+"world",{|"indentation": 4 |}
}
classC{x="hello"+"world";
{| "indentation": 4 |}
}

I've specified the "expected" indentation in each of these cases; however, TypeScript today keeps indentation are the same level as the prior line which is wrong. This is especially annoying for the multi-line union case.

There is some ambiguity when one uses an ASI-assuming style though. In these cases, I would personally err on the side of expecting the start indentation.

type Foo =
| "hello"
| "world"
{| "indentation": 0 |}


```ts
let x = 10,
y = 2
{| "indentation": 0 |}
classC{x="hello"+"world"
{| "indentation": 4 |}
}

Then, even for cases where ASI doesn't really apply:

letobj={x: "hello"+"world"{|"indentation": 4 |}
}

I would say we should pick the start element's base (where x starts), since we'll start doing #52899 eventually.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: LS: Smart IndentationAutomatic indenting after a newline (not quite formatter/formatting)RescheduledThis issue was previously scheduled to an earlier milestoneSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions