Typescript: formatter: allow custom switch-case indentation

Created on 22 Sep 2017  路  13Comments  路  Source: microsoft/TypeScript



TypeScript Version: 2.5.2

Code

Format the following

switch (foo) {
case 'bar':
  break;
}

Expected behavior:

Keep it the same.

Actual behavior:

case is indented.

switch (foo) {
  case 'bar':
    break;
}

This becomes more problematic when used with tslint or javascript code with eslint, because on different systems we can see one winning over the other randomly i.e. sometimes the case is indented, sometimes it's not (eslint rule says do not indent).

Awaiting More Feedback Formatter Suggestion VS Code Tracked

Most helpful comment

Hi guys,
any news on this?

All 13 comments

Hi guys,
any news on this?

@andreineculau It has been almost half a year, is there any news on this? I suggest adding a setting (configurable in settings.json) for this, and making the default the new behavior (same indent level for switch and case, one more indent for statement in a case). Thanks!

I have no news. Running with a disabled tsformatter. The issue is marked with "awaiting more feedback" but not sure from who.

I'm programming in C and I'm quite happy with how the autoformat formats the code (it's reasonably close to our coding standard, and MISRA guidelines). However, it is desired in my case that there are indents for switch case statements.

What I obtain now after pressing ALT+SHIFT+F:
image

What I would like:
image

And, ideally, the "case" keywords should be the same color as "switch"'s (although, if I remove the brackets after "case" the "case" word does become the expected color.

Is that possible?
VSCode 1.21.1

I'd want a setting made for this specific issue because of some cases of people wanting indent or not.
I'm one of the people who wants indenting like
image
instead of
image
since it is in every way less confusing for me to look at. I use Java in another IDE and Node.js with vscode and it'd be nice if I could see my switch case setup look like my Java ones (case is indented)
using 1.25.1

edit: oof i didn't actually format the second picture properly and this time i used the keybind for reformatting
image

hi guys, how is the progress

I guess this has a really low priority, as its annoying but not a big deal. Does anyone from the vscode have an expected release for this?

This is really a severe issue for me using autoformat in VS Code, so I cannot use autoformat due to this bug. And for me, one of the main tasks of IDE is to do code autoformat. IMO it's a major failure of VS Code. All mature IDE's have configurable indentations.

any good news?

I'm also interested in the feature, to be able to configure the auto-indent for switchs/cases. I don't like the current behavior.

Any news on this, please?

any good news? very annoying issue

this feature would be very helpful for my team!

I kinda find flat annoying to eyes too so I prefer indented variant.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uber5001 picture uber5001  路  3Comments

MartynasZilinskas picture MartynasZilinskas  路  3Comments

CyrusNajmabadi picture CyrusNajmabadi  路  3Comments

Roam-Cooper picture Roam-Cooper  路  3Comments

wmaurer picture wmaurer  路  3Comments