Skip to content

Commit 76f1819

Browse files
authored
fix token tree structure for Sharp(If) inside Kwd(KwdCase) (#394)
* fix token tree structure for Sharp(If) inside Kwd(KwdCase) * updated CHANGES.md * expanded test case
1 parent 8bd9000 commit 76f1819

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## next version (2.x.x)
22

33
- Fixed handling of default setters/getters in indentation check [#391](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/391)
4+
- Fixed token tree structure for Sharp(If) inside Kwd(KwdCase) [#394](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/394)
45
- Added unittests for ParserQueue and CheckerPool [#393](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/393)
56
- Improved wrapped code detection [#392](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/392)
67

src/checkstyle/token/walk/WalkSwitch.hx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,31 @@ class WalkSwitch {
8585
WalkComment.walkComment(stream, parent);
8686
case Sharp(_):
8787
WalkSharp.walkSharp(stream, parent, WalkSwitch.walkSwitchCases);
88+
/*
89+
* relocate sharp subtree from:
90+
* |- BrOpen
91+
* |- Kwd(KwdCase)
92+
* | |- expression
93+
* | |- DblDot
94+
* | |- statement
95+
* |- Sharp(If)
96+
* | |- condition
97+
* | |- statement (if not a new case)
98+
* to:
99+
* |- Kwd(KwdCase)
100+
* | |- expression
101+
* | |- DblDot
102+
* | |- statement
103+
* | |- Sharp(If)
104+
* | |- condition
105+
* | |- statement
106+
*/
107+
var sharp:TokenTree = parent.getLastChild();
108+
if (sharp.children.length < 2) continue;
109+
var body:TokenTree = sharp.children[1];
110+
if (body.is(Kwd(KwdCase))) continue;
111+
parent.children.pop();
112+
dblDot.addChild(sharp);
88113
default:
89114
WalkStatement.walkStatement(stream, dblDot);
90115
}

test/checks/whitespace/IndentationCheckTest.hx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ long comment
131131
4,
132132
5:
133133
doSomething();
134+
case 6:
135+
#if php
136+
doSomething();
137+
#else
138+
doSomething();
139+
#end
140+
doSomething();
141+
#if (haxe_ver < 4.0)
142+
case 7:
143+
doSomething();
144+
#end
134145
default:
135146
doSomething();
136147
}

0 commit comments

Comments
 (0)