Skip to content

Commit b5dbb0e

Browse files
FeepingCreaturedlang-bot
authored andcommitted
Fix issue 483: indent continuing case statements on the same level
1 parent e4f2f20 commit b5dbb0e

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

src/dfmt/formatter.d

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,14 @@ private:
17151715
}
17161716
else if (currentIs(tok!"case") || currentIs(tok!"default"))
17171717
{
1718-
if (peekBackIs(tok!"}", true) || peekBackIs(tok!";", true))
1718+
1719+
if (peekBackIs(tok!"}", true) || peekBackIs(tok!";", true)
1720+
/**
1721+
* The following code is valid and should be indented flatly
1722+
* case A:
1723+
* case B:
1724+
*/
1725+
|| peekBackIs(tok!":", true))
17191726
{
17201727
indents.popTempIndents();
17211728
if (indents.topIs(tok!"case"))

tests/allman/issue0483.d.ref

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module tests.issue0483;
2+
3+
void main()
4+
{
5+
switch (0)
6+
{
7+
case 1:
8+
case 2:
9+
label:
10+
case 3:
11+
break;
12+
default:
13+
break;
14+
}
15+
}

tests/issue0483.args

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--align_switch_statements=false

tests/issue0483.d

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module tests.issue0483;
2+
3+
void main()
4+
{
5+
switch (0)
6+
{
7+
case 1:
8+
case 2:
9+
label:
10+
case 3:
11+
break;
12+
default:
13+
break;
14+
}
15+
}

tests/otbs/issue0483.d.ref

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module tests.issue0483;
2+
3+
void main() {
4+
switch (0) {
5+
case 1:
6+
case 2:
7+
label:
8+
case 3:
9+
break;
10+
default:
11+
break;
12+
}
13+
}

0 commit comments

Comments
 (0)