Skip to content

Commit 091d730

Browse files
authored
second attempt to fix typedef comment issues (#405)
* second attempt to fix typedef comment issues
1 parent 67073cf commit 091d730

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- Fixed bad offset crash with C++ build on7 Windows 10 [#398](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/398)
99
- Fixed object declaration handling [#399](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/399)
1010
- Fixed false positives for files with UTF-8 characters when running as vscode-checkstyle [#402](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/402)
11-
- Fixed comments in typedefs [#404](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/404)
11+
- Fixed comments in typedefs [#404](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/404) + [#405](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/405)
1212
- Refactored content handling to use Bytes instead of String (should fix [#98](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/98)) [#402](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/402)
1313
- Added unittests for ParserQueue and CheckerPool [#393](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/393)
1414
- Added unittests for TokenTree structure verification [#400](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/400)

src/checkstyle/token/walk/WalkFieldDef.hx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class WalkFieldDef {
1313
parent = tok;
1414
case At:
1515
tempStore.push(WalkAt.walkAt(stream));
16+
case Comment(_), CommentLine(_):
17+
WalkComment.walkComment(stream, parent);
1618
default:
1719
break;
1820
}

test/token/TokenTreeBuilderParsingTest.hx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class TokenTreeBuilderParsingTest {
3636
assertCodeParses(BLOCK_OBJECT_DECL_SAMPLES_ISSUE_396_3);
3737
assertCodeParses(BLOCK_OBJECT_DECL_WITH_TERNARY);
3838
assertCodeParses(TYPEDEF_COMMENTS);
39+
assertCodeParses(TYPEDEF_COMMENTS_2);
3940
}
4041

4142
public function assertCodeParses(code:String, ?pos:PosInfos) {
@@ -468,4 +469,13 @@ abstract TokenTreeBuilderParsingTests(String) to String {
468469
var index:Int;
469470
// æ@ð
470471
}";
472+
473+
var TYPEDEF_COMMENTS_2 = "
474+
typedef CheckFile = {
475+
// °
476+
var name:String;
477+
var content:String;
478+
// €łµ
479+
var index:Int;
480+
}";
471481
}

test/token/verify/VerifyTokenTreeTest.hx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,35 @@ class VerifyTokenTreeTest {
106106
brOpen.childLast().is(BrClose).noChilds();
107107
}
108108

109+
@Test
110+
public function testTypedefComments2() {
111+
var root:IVerifyTokenTree = buildTokenTree(TokenTreeBuilderParsingTests.TYPEDEF_COMMENTS_2);
112+
113+
// typedef CheckFile
114+
var type:IVerifyTokenTree = root.childFirst().is(Kwd(KwdTypedef)).oneChild().childFirst().is(Const(CIdent("CheckFile")));
115+
var brOpen:IVerifyTokenTree = type.childFirst().is(Binop(OpAssign)).oneChild().childFirst().is(BrOpen).childCount(6);
116+
brOpen.childAt(0).is(CommentLine(" °"));
117+
118+
// var name:String;
119+
var v:IVerifyTokenTree = brOpen.childAt(1).is(Kwd(KwdVar)).oneChild().childFirst().is(Const(CIdent("name"))).childCount(2);
120+
v.childFirst().is(DblDot).oneChild().childFirst().is(Const(CIdent("String"))).noChilds();
121+
v.childLast().is(Semicolon).noChilds();
122+
123+
// var content:String;
124+
v = brOpen.childAt(2).is(Kwd(KwdVar)).oneChild().childFirst().is(Const(CIdent("content"))).childCount(2);
125+
v.childFirst().is(DblDot).oneChild().childFirst().is(Const(CIdent("String"))).noChilds();
126+
v.childLast().is(Semicolon).noChilds();
127+
128+
brOpen.childAt(3).is(CommentLine(" €łµ")).noChilds();
129+
130+
// var index:Int;
131+
v = brOpen.childAt(4).is(Kwd(KwdVar)).oneChild().childFirst().is(Const(CIdent("index"))).childCount(2);
132+
v.childFirst().is(DblDot).oneChild().childFirst().is(Const(CIdent("Int"))).noChilds();
133+
v.childLast().is(Semicolon).noChilds();
134+
135+
brOpen.childLast().is(BrClose).noChilds();
136+
}
137+
109138
function buildTokenTree(content:String):IVerifyTokenTree {
110139
var builder:TestTokenTreeBuilder = new TestTokenTreeBuilder(content);
111140
var root:TokenTree = new TokenTree(null, null, -1);

0 commit comments

Comments
 (0)