Skip to content

Commit 67073cf

Browse files
authored
fixed comments in typedef (#404)
* fixed comments in typedef
1 parent 51c4330 commit 67073cf

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- Fixed BkOpen childs in token tree parser [#398](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/398)
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)
10+
- 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)
1012
- 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)
1113
- Added unittests for ParserQueue and CheckerPool [#393](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/393)
1214
- Added unittests for TokenTree structure verification [#400](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/400)

src/checkstyle/token/walk/WalkTypedefBody.hx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class WalkTypedefBody {
99
while (progress.streamHasChanged()) {
1010
switch (stream.token()) {
1111
case BrClose: break;
12+
case Comment(_), CommentLine(_):
13+
WalkComment.walkComment(stream, openTok);
1214
default:
1315
WalkFieldDef.walkFieldDef(stream, openTok);
1416
}

test/token/TokenTreeBuilderParsingTest.hx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class TokenTreeBuilderParsingTest {
3535
assertCodeParses(BLOCK_OBJECT_DECL_SAMPLES_ISSUE_396_2);
3636
assertCodeParses(BLOCK_OBJECT_DECL_SAMPLES_ISSUE_396_3);
3737
assertCodeParses(BLOCK_OBJECT_DECL_WITH_TERNARY);
38+
assertCodeParses(TYPEDEF_COMMENTS);
3839
}
3940

4041
public function assertCodeParses(code:String, ?pos:PosInfos) {
@@ -456,4 +457,15 @@ abstract TokenTreeBuilderParsingTests(String) to String {
456457
};
457458
}
458459
}";
460+
461+
var TYPEDEF_COMMENTS = "
462+
typedef CheckFile = {
463+
// °
464+
var name:String;
465+
// öäü
466+
var content:String;
467+
// €łµ
468+
var index:Int;
469+
// æ@ð
470+
}";
459471
}

test/token/verify/VerifyTokenTreeTest.hx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,38 @@ class VerifyTokenTreeTest {
7474
block.childLast().is(BrClose).noChilds();
7575
}
7676

77+
@Test
78+
public function testTypedefComments() {
79+
var root:IVerifyTokenTree = buildTokenTree(TokenTreeBuilderParsingTests.TYPEDEF_COMMENTS);
80+
81+
// typedef CheckFile
82+
var type:IVerifyTokenTree = root.childFirst().is(Kwd(KwdTypedef)).oneChild().childFirst().is(Const(CIdent("CheckFile")));
83+
var brOpen:IVerifyTokenTree = type.childFirst().is(Binop(OpAssign)).oneChild().childFirst().is(BrOpen).childCount(8);
84+
brOpen.childAt(0).is(CommentLine(" °"));
85+
86+
// var name:String;
87+
var v:IVerifyTokenTree = brOpen.childAt(1).is(Kwd(KwdVar)).oneChild().childFirst().is(Const(CIdent("name"))).childCount(2);
88+
v.childFirst().is(DblDot).oneChild().childFirst().is(Const(CIdent("String"))).noChilds();
89+
v.childLast().is(Semicolon).noChilds();
90+
91+
brOpen.childAt(2).is(CommentLine(" öäü")).noChilds();
92+
93+
// var content:String;
94+
v = brOpen.childAt(3).is(Kwd(KwdVar)).oneChild().childFirst().is(Const(CIdent("content"))).childCount(2);
95+
v.childFirst().is(DblDot).oneChild().childFirst().is(Const(CIdent("String"))).noChilds();
96+
v.childLast().is(Semicolon).noChilds();
97+
98+
brOpen.childAt(4).is(CommentLine(" €łµ")).noChilds();
99+
100+
// var index:Int;
101+
v = brOpen.childAt(5).is(Kwd(KwdVar)).oneChild().childFirst().is(Const(CIdent("index"))).childCount(2);
102+
v.childFirst().is(DblDot).oneChild().childFirst().is(Const(CIdent("Int"))).noChilds();
103+
v.childLast().is(Semicolon).noChilds();
104+
105+
brOpen.childAt(6).is(CommentLine(" æ@ð")).noChilds();
106+
brOpen.childLast().is(BrClose).noChilds();
107+
}
108+
77109
function buildTokenTree(content:String):IVerifyTokenTree {
78110
var builder:TestTokenTreeBuilder = new TestTokenTreeBuilder(content);
79111
var root:TokenTree = new TokenTree(null, null, -1);

0 commit comments

Comments
 (0)