Skip to content

Commit 1a13453

Browse files
authored
deprecated is operator (#501)
* deprecated is operator * tokentree api changes * disabled nightly builds due to missing abstract support in haxeparser
1 parent e7f7d5f commit 1a13453

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+706
-256
lines changed

.github/workflows/checkstyle-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
haxe-version: ['3.4.7', '4.0.5', '4.1.2', 'nightly']
18+
haxe-version: ['3.4.7', '4.0.5', '4.1.2']
1919
env:
2020
CC_TEST_REPORTER_ID: 1dff6f89d7179dff5db635c6b4fe64acdd5694c9ed44d7da5f12f0f7d3d163b7
2121
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- Added support for final in `MagicNumber`, fixes [#494](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/494) ([#495](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/495))
77
- Fixed handling `OBJECT_DECL` token in `RightCurly`, fixes [#496](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/496) ([#497](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/497))
88
- Reorganised build files ([#498](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/498))
9-
- Refactored for tokentree API change ([#500](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/500))
9+
- Refactored for tokentree API change ([#500](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/500) + [#501](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/501))
1010

1111
## version 2.6.1 (2019-12-17)
1212

haxe3_libraries/tokentree.hxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/tokentree#7bada801831488a3bed105838c263ec819c69dfb" into tokentree/1.0.28/github/7bada801831488a3bed105838c263ec819c69dfb
2-
-cp ${HAXE_LIBCACHE}/tokentree/1.0.28/github/7bada801831488a3bed105838c263ec819c69dfb/src
1+
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/tokentree#afc7afd91b15758c871bd59b6ebdf7916a400f7f" into tokentree/1.0.28/github/afc7afd91b15758c871bd59b6ebdf7916a400f7f
2+
-cp ${HAXE_LIBCACHE}/tokentree/1.0.28/github/afc7afd91b15758c871bd59b6ebdf7916a400f7f/src
33
-D tokentree=1.0.28

haxe_libraries/tokentree.hxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/tokentree#7bada801831488a3bed105838c263ec819c69dfb" into tokentree/1.0.28/github/7bada801831488a3bed105838c263ec819c69dfb
2-
-cp ${HAXE_LIBCACHE}/tokentree/1.0.28/github/7bada801831488a3bed105838c263ec819c69dfb/src
1+
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/tokentree#afc7afd91b15758c871bd59b6ebdf7916a400f7f" into tokentree/1.0.28/github/afc7afd91b15758c871bd59b6ebdf7916a400f7f
2+
-cp ${HAXE_LIBCACHE}/tokentree/1.0.28/github/afc7afd91b15758c871bd59b6ebdf7916a400f7f/src
33
-D tokentree=1.0.28

src/checkstyle/checks/block/BlockBreakingConditionalCheck.hx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ class BlockBreakingConditionalCheck extends Check {
1212

1313
override function actualRun() {
1414
var root:TokenTree = checker.getTokenTree();
15-
var allBrs:Array<TokenTree> = root.filter([BrOpen, BrClose], All);
15+
var allBrs:Array<TokenTree> = root.filterCallback(function(token:TokenTree, index:Int):FilterResult {
16+
return switch (token.tok) {
17+
case BrOpen | BrClose:
18+
FoundGoDeeper;
19+
default:
20+
GoDeeper;
21+
}
22+
});
1623

1724
for (br in allBrs) {
1825
if (isPosSuppressed(br.pos)) continue;
@@ -21,7 +28,7 @@ class BlockBreakingConditionalCheck extends Check {
2128
if (br.access().firstOf(BrClose).exists()) continue;
2229
logPos("Left curly has no matching right curly", br.pos);
2330
case BrClose:
24-
if (br.access().parent().is(BrOpen).exists()) continue;
31+
if (br.access().parent().matches(BrOpen).exists()) continue;
2532
logPos("Right curly has no matching left curly", br.pos);
2633
default:
2734
continue;

src/checkstyle/checks/block/ConditionalCompilationCheck.hx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ class ConditionalCompilationCheck extends Check {
2929

3030
override function actualRun() {
3131
var root:TokenTree = checker.getTokenTree();
32-
checkSharpIf(root.filter([Sharp("if")], All));
32+
checkSharpIf(root.filterCallback(function(token:TokenTree, index:Int):FilterResult {
33+
return switch (token.tok) {
34+
case Sharp("if"):
35+
FoundGoDeeper;
36+
default:
37+
GoDeeper;
38+
}
39+
}));
3340
}
3441

3542
function checkSharpIf(tokens:Array<TokenTree>) {

src/checkstyle/checks/block/EmptyBlockCheck.hx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ class EmptyBlockCheck extends Check {
5959

6060
override function actualRun() {
6161
var root:TokenTree = checker.getTokenTree();
62-
var allBrOpen:Array<TokenTree> = root.filter([BrOpen], All);
62+
var allBrOpen:Array<TokenTree> = root.filterCallback(function(token:TokenTree, index:Int):FilterResult {
63+
return switch (token.tok) {
64+
case BrOpen:
65+
FoundGoDeeper;
66+
default:
67+
GoDeeper;
68+
}
69+
});
6370

6471
for (brOpen in allBrOpen) {
6572
if (isPosSuppressed(brOpen.pos)) continue;
@@ -128,7 +135,7 @@ class EmptyBlockCheck extends Check {
128135
return;
129136
}
130137
var lastChild:TokenTree = brOpen.getLastChild();
131-
if ((brOpen.children.length == 2) && lastChild.is(Semicolon)) {
138+
if ((brOpen.children.length == 2) && lastChild.matches(Semicolon)) {
132139
logPos("Empty block should contain a comment or a statement", brOpen.getPos());
133140
return;
134141
}
@@ -140,7 +147,7 @@ class EmptyBlockCheck extends Check {
140147
return;
141148
}
142149
var lastChild:TokenTree = brOpen.getLastChild();
143-
if ((brOpen.children.length == 2) && lastChild.is(Semicolon)) {
150+
if ((brOpen.children.length == 2) && lastChild.matches(Semicolon)) {
144151
logPos("Empty block should contain a statement", brOpen.getPos());
145152
return;
146153
}
@@ -163,14 +170,14 @@ class EmptyBlockCheck extends Check {
163170
if (brOpen.children.length <= 0) return;
164171

165172
var lastChild:TokenTree = brOpen.getLastChild();
166-
if (brOpen.access().lastChild().is(Semicolon).exists()) {
173+
if (brOpen.access().lastChild().matches(Semicolon).exists()) {
167174
if (brOpen.children.length > 2) return;
168175
}
169176
else {
170177
if (brOpen.children.length > 1) return;
171178
}
172179

173-
var brClose:TokenTree = brOpen.access().firstChild().is(BrClose).token;
180+
var brClose:TokenTree = brOpen.access().firstChild().matches(BrClose).token;
174181
if (brClose == null) return;
175182
if (brOpen.pos.max != brClose.pos.min) logPos('Empty block should be written as "{}"', brOpen.getPos());
176183
}

src/checkstyle/checks/block/LeftCurlyCheck.hx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ class LeftCurlyCheck extends Check {
7272

7373
override function actualRun() {
7474
var root:TokenTree = checker.getTokenTree();
75-
var allBrOpen:Array<TokenTree> = root.filter([BrOpen], All);
75+
var allBrOpen:Array<TokenTree> = root.filterCallback(function(token:TokenTree, index:Int):FilterResult {
76+
return switch (token.tok) {
77+
case BrOpen:
78+
FoundGoDeeper;
79+
default:
80+
GoDeeper;
81+
}
82+
});
7683

7784
for (brOpen in allBrOpen) {
7885
if (isPosSuppressed(brOpen.pos)) continue;

src/checkstyle/checks/block/NeedBracesCheck.hx

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,34 @@ class NeedBracesCheck extends Check {
3636
}
3737

3838
override function actualRun() {
39-
var tokenList:Array<TokenTreeDef> = [];
39+
var wantFunction = hasToken(FUNCTION);
40+
var wantFor = hasToken(FOR);
41+
var wantIf = hasToken(IF);
42+
var wantWhile = hasToken(WHILE);
43+
var wantDoWhile = hasToken(DO_WHILE);
44+
var wantCatch = hasToken(CATCH);
4045

41-
if (hasToken(FUNCTION)) tokenList.push(Kwd(KwdFunction));
42-
if (hasToken(FOR)) tokenList.push(Kwd(KwdFor));
43-
if (hasToken(IF)) {
44-
tokenList.push(Kwd(KwdIf));
45-
tokenList.push(Kwd(KwdElse));
46-
}
47-
if (hasToken(WHILE)) tokenList.push(Kwd(KwdWhile));
48-
if (hasToken(DO_WHILE)) tokenList.push(Kwd(KwdDo));
49-
if (hasToken(CATCH)) tokenList.push(Kwd(KwdCatch));
50-
51-
if (tokenList.length <= 0) return;
46+
if (!(wantFunction || wantFor || wantIf || wantWhile || wantDoWhile || wantCatch)) return;
5247

5348
var root:TokenTree = checker.getTokenTree();
54-
var allTokens:Array<TokenTree> = root.filter(tokenList, All);
49+
var allTokens:Array<TokenTree> = root.filterCallback(function(token:TokenTree, depth:Int):FilterResult {
50+
return switch (token.tok) {
51+
case Kwd(KwdFunction) if (wantFunction):
52+
FoundGoDeeper;
53+
case Kwd(KwdFor) if (wantFor):
54+
FoundGoDeeper;
55+
case Kwd(KwdIf) | Kwd(KwdElse) if (wantIf):
56+
FoundGoDeeper;
57+
case Kwd(KwdWhile) if (wantWhile):
58+
FoundGoDeeper;
59+
case Kwd(KwdDo) if (wantDoWhile):
60+
FoundGoDeeper;
61+
case Kwd(KwdCatch) if (wantCatch):
62+
FoundGoDeeper;
63+
default:
64+
GoDeeper;
65+
}
66+
});
5567

5668
for (tok in allTokens) {
5769
if (isPosSuppressed(tok.pos)) continue;
@@ -61,7 +73,7 @@ class NeedBracesCheck extends Check {
6173
case Kwd(KwdElse):
6274
var firstChild = tok.getFirstChild();
6375
if (firstChild == null) continue;
64-
if (firstChild.is(Kwd(KwdIf))) checkIfChild(firstChild);
76+
if (firstChild.matches(Kwd(KwdIf))) checkIfChild(firstChild);
6577
else checkLastChild(tok);
6678
case Kwd(KwdFunction):
6779
checkFunctionChild(tok);
@@ -102,14 +114,14 @@ class NeedBracesCheck extends Check {
102114
return;
103115
}
104116
body = body.nextSibling;
105-
if (body.is(DblDot)) {
117+
if (body.matches(DblDot)) {
106118
var lastChild:TokenTree = TokenTreeCheckUtils.getLastToken(token);
107-
if (lastChild.is(Semicolon)) {
119+
if (lastChild.matches(Semicolon)) {
108120
return;
109121
}
110122
body = body.nextSibling;
111123
}
112-
if ((body == null) || (body.is(BrOpen))) {
124+
if ((body == null) || (body.matches(BrOpen))) {
113125
return;
114126
}
115127
checkNoBraces(token, body);

src/checkstyle/checks/block/RightCurlyCheck.hx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ class RightCurlyCheck extends Check {
6060

6161
override function actualRun() {
6262
var root:TokenTree = checker.getTokenTree();
63-
var allBrClose:Array<TokenTree> = root.filter([BrClose], All);
63+
var allBrClose:Array<TokenTree> = root.filterCallback(function(token:TokenTree, index:Int):FilterResult {
64+
return switch (token.tok) {
65+
case BrClose:
66+
FoundGoDeeper;
67+
default:
68+
GoDeeper;
69+
}
70+
});
6471

6572
for (brClose in allBrClose) {
6673
if (isPosSuppressed(brClose.pos)) continue;

0 commit comments

Comments
 (0)