Skip to content

Commit 0a0edef

Browse files
authored
exclude function body from ModifierOrderCheck, fixes #332 (#333)
1 parent 9fd0281 commit 0a0edef

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/checkstyle/checks/modifier/ModifierOrderCheck.hx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package checkstyle.checks.modifier;
22

3+
import haxe.macro.PositionTools;
4+
35
@name("ModifierOrder", "AccessOrder")
46
@desc("Checks that the order of modifiers conforms to the standards.")
57
class ModifierOrderCheck extends Check {
@@ -31,13 +33,26 @@ class ModifierOrderCheck extends Check {
3133
var modifier:ModifierOrderCheckModifier = access;
3234
index = modifiers.indexOf(modifier);
3335
if (index < lastIndex) {
34-
warnOrder(f.name, modifier, f.pos);
36+
var pos = calcPos(f);
37+
warnOrder(f.name, modifier, pos);
3538
return;
3639
}
3740
lastIndex = index;
3841
}
3942
}
4043

44+
function calcPos(f:Field):Position {
45+
switch (f.kind) {
46+
case FVar(_, _), FProp(_, _, _, _):
47+
return f.pos;
48+
case FFun(fun):
49+
if (fun.expr == null) {
50+
return f.pos;
51+
}
52+
return PositionTools.make({min: f.pos.min, max: fun.expr.pos.min, file: f.pos.file});
53+
}
54+
}
55+
4156
function warnOrder(name:String, modifier:ModifierOrderCheckModifier, pos:Position) {
4257
logPos('"${name}" modifier order is invalid (modifier: "${modifier}")', pos);
4358
}

test/checks/modifier/ModifierOrderCheckTest.hx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import checkstyle.checks.modifier.ModifierOrderCheck;
44

55
class ModifierOrderCheckTest extends CheckTestCase<ModifierOrderCheckTests> {
66

7+
static inline var ERROR:String = '"test" modifier order is invalid (modifier: "PUBLIC_PRIVATE")';
8+
79
public function testCorrectOrder() {
810
var check = new ModifierOrderCheck();
911
assertNoMsg(check, TEST1);
@@ -14,7 +16,9 @@ class ModifierOrderCheckTest extends CheckTestCase<ModifierOrderCheckTests> {
1416
assertMsg(check, TEST2, '"test" modifier order is invalid (modifier: "OVERRIDE")');
1517
assertMsg(check, TEST3, '"test" modifier order is invalid (modifier: "STATIC")');
1618
assertMsg(check, TEST4, '"test" modifier order is invalid (modifier: "MACRO")');
17-
assertMsg(check, TEST5, '"test" modifier order is invalid (modifier: "PUBLIC_PRIVATE")');
19+
assertMsg(check, TEST5, ERROR);
20+
assertMsg(check, TEST7, ERROR);
21+
assertMsg(check, TEST8, ERROR);
1822
}
1923

2024
public function testModifiers() {
@@ -25,6 +29,7 @@ class ModifierOrderCheckTest extends CheckTestCase<ModifierOrderCheckTests> {
2529
assertNoMsg(check, TEST3);
2630
assertNoMsg(check, TEST4);
2731
assertNoMsg(check, TEST5);
32+
assertNoMsg(check, TEST6);
2833
}
2934

3035
public function testIgnore() {
@@ -65,4 +70,19 @@ abstract ModifierOrderCheckTests(String) to String {
6570
"abstractAndClass Test {
6671
dynamic public function test() {}
6772
}";
68-
}
73+
74+
var TEST6 =
75+
"interface Test {
76+
dynamic public function test();
77+
}";
78+
79+
var TEST7 =
80+
"abstractAndClass Test {
81+
inline public var test:String=0;
82+
}";
83+
84+
var TEST8 =
85+
"abstractAndClass Test {
86+
inline public var test(default,null):String=0;
87+
}";
88+
}

0 commit comments

Comments
 (0)