Skip to content
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

formatter: allow custom switch-case indentation #18682

Closed
andreineculau opened this issue Sep 22, 2017 · 25 comments · Fixed by #53733
Closed

formatter: allow custom switch-case indentation #18682

andreineculau opened this issue Sep 22, 2017 · 25 comments · Fixed by #53733
Labels
Domain: Formatter The issue relates to the built-in formatter Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue
Milestone

Comments

@andreineculau
Copy link

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).

andreineculau pushed a commit to tobiipro/support-firecloud that referenced this issue Sep 22, 2017
andreineculau pushed a commit to tobiipro/support-firecloud that referenced this issue Sep 22, 2017
andreineculau pushed a commit to tobiipro/support-firecloud that referenced this issue Sep 22, 2017
@mhegazy mhegazy added Domain: Formatter The issue relates to the built-in formatter Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Sep 22, 2017
@mjbvz mjbvz added the VS Code Tracked There is a VS Code equivalent to this issue label Oct 27, 2017
@vincenzovitale
Copy link

Hi guys,
any news on this?

@kenjisiu-ibmhk
Copy link

@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!

@andreineculau
Copy link
Author

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

@maxcurzi
Copy link

maxcurzi commented Apr 3, 2018

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

@Sanae6
Copy link

Sanae6 commented Aug 4, 2018

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

@dingcang
Copy link

dingcang commented Jan 9, 2019

hi guys, how is the progress

@ricardolpd
Copy link

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?

@xmedeko
Copy link

xmedeko commented Sep 20, 2019

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 IDEs have configurable indentations.

@phamminhkhac
Copy link

any good news?

@IllanRULDACUNHA
Copy link

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?

@orielz
Copy link

orielz commented Apr 12, 2020

any good news? very annoying issue

@cdrapes
Copy link

cdrapes commented Apr 23, 2020

this feature would be very helpful for my team!

@SoapyMan
Copy link

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

@ftzi
Copy link

ftzi commented Feb 4, 2021

There should be a setting for it. Shame that it hasn't been done yet. ESLint does it well.

@phamminhkhac
Copy link

4 years later:

@nfearnleyx
Copy link

cough

@pedroalles
Copy link

4.5 years later:

@iqapps
Copy link

iqapps commented Oct 15, 2021

cough, cough

@andrewbranch andrewbranch added Experience Enhancement Noncontroversial enhancements and removed Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Oct 15, 2021
@andrewbranch andrewbranch added Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this labels Oct 15, 2021
@andrewbranch andrewbranch added this to the Backlog milestone Oct 15, 2021
@andrewbranch
Copy link
Member

I would be happy to look at a PR adding a formatter setting for this. Implementer be warned; our indenter code (“SmartIndenter” 🙄) is not the easiest to work with.

@itzmanish
Copy link

Almost 5 years later, same issue no fix 🙄.

@andrewbranch
Copy link
Member

Are you volunteering? All the other “N years” commenters have been pretty quiet since I marked it “Help Wanted.” I thought for sure somebody would have given this a shot by now. 😄

@donaldnevermore
Copy link
Contributor

I'll have a try.

@donaldnevermore
Copy link
Contributor

@andrewbranch Needs help here. The code worked, but I'm not sure if there are more test cases that can be added. I don't really know what is behind the tests folder. It's not like using a testing framework.

@a-pav
Copy link

a-pav commented Aug 24, 2024

What is the equivalent setting for javascript?

I have
"typescript.format.indentSwitchCase"
but no
"javascript.format.indentSwitchCase"

@xmedeko
Copy link

xmedeko commented Dec 3, 2024

@a-pav I have created new issue for JavaScript microsoft/vscode#235085 Please, vote for it if it still affects you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Formatter The issue relates to the built-in formatter Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.