Weird indentation when using switch-case
See original GitHub issueswitch (v) { case 1: break; case 2: break; case 3: break; default: break; }
…becomes…
switch (v) {
case 1:
break;
case 2:
break;
case 3:
break;
default:
break;
}
Maybe this is intentional, but I would expect the case
to be indented by 1 level (based on the settings).
Issue Analytics
- State:
- Created 13 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
java - Why the strange indentation on switch statements?
To put it another way, the contents of the switch block are indented one level from the switch itself, but the case s...
Read more >Swift's SWITCH indenting is driving me mad... any way to fix ...
Cases are part of the switch statement, therefore is their indentation different from what you may be familiar with from other languages.
Read more >Incorrect indentation in switch statements with scope inside
Format this code to reproduce (the contents of case 0 get incorrect indented, should be one indentation higher): void Foo() { int i...
Read more >How to change indentation in "case" with curly braces?
Probably best is to settle for one of the options above, or perhaps manually fix the indentation (with Ctrl + D and similar...
Read more >D43183 clang-format: introduce `CaseBlockIndent` to ... - LLVM
Block mode is syntaxically correct, but somewhat breaks the switch layout by moving break to different indentation levels depending on the use ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
IMHO, that really doesn’t make sense. Crockford’s reasoning to omit the extra indents is the following: “Each case is aligned with the switch. This avoids over-indentation.” ORLY?
I see your point though. If it’s by design, and you like it that way, just leave it the way it is!
I disagree with Crockford, with his idea it’s exceedingly more difficult to ascertain the actual ending of the switch statement. By his line of reasoning, why indent any control structures at all? They all yield an indention penalty.
I think this would be better, if one just so happened to work on an 800x600 resolution:
Would love to have an option for this; either the “normal” way (like I have seen switch statements written my entire life), or the way I demonstrated above; anything but the default. Would you be open to a patch, if you don’t personally agree or see the need for it?