microsoft / microsoft/TypeScript

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

Open
#53,548 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: LS: Smart Indentation Rescheduled Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

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

type Foo =
    | "hello"
    | "world";

{| "indentation": 0 |}
let x = 10,
    y = 2;
{| "indentation": 0 |}
let x = 10,
    y = 2,
    {| "indentation": 4 |}
let obj = {
    x: "hello" +
        "world",
    {| "indentation": 4 |}
}
class C {
    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 |}
class C {
    x = "hello" +
        "world"
    {| "indentation": 4 |}
}

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

let obj = {
    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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation files or tests are named. Start by locating TypeScript's smart-indentation entry point and compare its behavior against the separated-union, multiline-variable, object, and class examples; review the relationship to #52899. Done means the examples use the prior element's starting base indentation, including the stated ASI cases, with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.