Skip to content

Commit f874f80

Browse files
authored
a child class with a static var and a constructor should not trigger … (#335)
* a child class with a static var and a constructor should not trigger an unnecessary constructor warning * updated Haxe version to 3.4.2
1 parent 0a0edef commit f874f80

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ git:
33

44
language: haxe
55
haxe:
6-
- 3.4.0
6+
- 3.4.2
77
- development
88
install:
99
- haxelib install haxeparser 3.3.0

src/checkstyle/checks/design/UnnecessaryConstructorCheck.hx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class UnnecessaryConstructorCheck extends Check {
1414
var root:TokenTree = checker.getTokenTree();
1515
var classes:Array<TokenTree> = root.filter([Kwd(KwdClass)], ALL);
1616
for (cls in classes) {
17+
if (extendsBaseClass(cls)) {
18+
continue;
19+
}
1720
var acceptableTokens:Array<TokenTree> = cls.filter([
1821
Kwd(KwdFunction),
1922
Kwd(KwdVar)
@@ -40,4 +43,14 @@ class UnnecessaryConstructorCheck extends Check {
4043
}
4144
}
4245
}
43-
}
46+
47+
function extendsBaseClass(cls:TokenTree):Bool {
48+
var clsName:TokenTree = cls.getFirstChild();
49+
for (child in clsName.children) {
50+
if (child.is(Kwd(KwdExtends))) {
51+
return true;
52+
}
53+
}
54+
return false;
55+
}
56+
}

test/checks/design/UnnecessaryConstructorCheckTest.hx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class UnnecessaryConstructorCheckTest extends CheckTestCase<UnnecessaryConstruct
3131
public function testStaticOnlyWithNew() {
3232
assertNoMsg(new UnnecessaryConstructorCheck(), TEST_STATIC_ONLY_WITH_NEW);
3333
}
34+
35+
public function testChildClass() {
36+
assertNoMsg(new UnnecessaryConstructorCheck(), TEST_CHILD_CLASS);
37+
}
3438
}
3539

3640
@:enum
@@ -104,4 +108,15 @@ abstract UnnecessaryConstructorCheckTests(String) to String {
104108
VAR1 = new String();
105109
}
106110
}";
107-
}
111+
112+
var TEST_CHILD_CLASS = "
113+
class Test extends Base
114+
{
115+
public static var VAR1:String = 'test';
116+
117+
public function new()
118+
{
119+
super(VAR1);
120+
}
121+
}";
122+
}

0 commit comments

Comments
 (0)