Skip to content

Commit f138323

Browse files
committed
Merge pull request #28 from AlexHaxe/dev
added new AccessOrderCheck to replace OverrideCheck
2 parents ddecb8a + d4eb927 commit f138323

File tree

8 files changed

+218
-94
lines changed

8 files changed

+218
-94
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ More information in [wiki page](https://github.com/adireddy/haxe-checkstyle/wiki
2121
```json
2222
{
2323
"checks": [
24+
{
25+
"type": "AccessOrder",
26+
"props": {
27+
"modifiers": [
28+
"MACRO",
29+
"OVERRIDE",
30+
"PUBLIC_PRIVATE",
31+
"STATIC",
32+
"INLINE",
33+
"DYNAMIC"
34+
]
35+
}
36+
},
2437
{
2538
"type": "Anonymous",
2639
"props": {
@@ -393,4 +406,4 @@ This content is released under the [MIT](http://opensource.org/licenses/MIT) Lic
393406

394407
### Contributor Code of Conduct ###
395408

396-
[Code of Conduct](https://github.com/CoralineAda/contributor_covenant) is adapted from [Contributor Covenant, version 1.2.0](http://contributor-covenant.org/version/1/2/0/)
409+
[Code of Conduct](https://github.com/CoralineAda/contributor_covenant) is adapted from [Contributor Covenant, version 1.2.0](http://contributor-covenant.org/version/1/2/0/)

check-style-report.xml

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,65 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<checkstyle version="5.0">
3-
<file name="checkstyle&#x2F;Checker.hx">
3+
<file name="checkstyle&#x2F;checks&#x2F;DynamicCheck.hx">
44
</file>
5-
<file name="checkstyle&#x2F;checks&#x2F;AnonymousCheck.hx">
5+
<file name="checkstyle&#x2F;checks&#x2F;EmptyLinesCheck.hx">
66
</file>
7-
<file name="checkstyle&#x2F;checks&#x2F;ArrayInstantiationCheck.hx">
7+
<file name="checkstyle&#x2F;checks&#x2F;FileLengthCheck.hx">
88
</file>
9-
<file name="checkstyle&#x2F;checks&#x2F;BlockFormatCheck.hx">
9+
<file name="checkstyle&#x2F;checks&#x2F;HexadecimalLiteralsCheck.hx">
1010
</file>
11-
<file name="checkstyle&#x2F;checks&#x2F;Check.hx">
11+
<file name="checkstyle&#x2F;checks&#x2F;IndentationCharacterCheck.hx">
1212
</file>
13-
<file name="checkstyle&#x2F;checks&#x2F;ConstantNameCheck.hx">
13+
<file name="checkstyle&#x2F;checks&#x2F;MethodLengthCheck.hx">
1414
</file>
15-
<file name="checkstyle&#x2F;checks&#x2F;CyclomaticComplexityCheck.hx">
15+
<file name="checkstyle&#x2F;checks&#x2F;NestedForDepthCheck.hx">
1616
</file>
17-
<file name="checkstyle&#x2F;checks&#x2F;DynamicCheck.hx">
17+
<file name="checkstyle&#x2F;checks&#x2F;TypeCheck.hx">
1818
</file>
19-
<file name="checkstyle&#x2F;checks&#x2F;EmptyLinesCheck.hx">
19+
<file name="checkstyle&#x2F;checks&#x2F;LineLengthCheck.hx">
2020
</file>
21-
<file name="checkstyle&#x2F;checks&#x2F;ERegInstantiationCheck.hx">
21+
<file name="checkstyle&#x2F;checks&#x2F;OverrideCheck.hx">
2222
</file>
23-
<file name="checkstyle&#x2F;checks&#x2F;FileLengthCheck.hx">
23+
<file name="checkstyle&#x2F;checks&#x2F;ParameterNameCheck.hx">
2424
</file>
25-
<file name="checkstyle&#x2F;checks&#x2F;HexadecimalLiteralsCheck.hx">
25+
<file name="checkstyle&#x2F;checks&#x2F;TabForAligningCheck.hx">
2626
</file>
27-
<file name="checkstyle&#x2F;checks&#x2F;IndentationCharacterCheck.hx">
27+
<file name="checkstyle&#x2F;checks&#x2F;VariableInitialisationCheck.hx">
2828
</file>
29-
<file name="checkstyle&#x2F;checks&#x2F;LineLengthCheck.hx">
29+
<file name="checkstyle&#x2F;checks&#x2F;ConstantNameCheck.hx">
3030
</file>
3131
<file name="checkstyle&#x2F;checks&#x2F;ListenerNameCheck.hx">
3232
</file>
33-
<file name="checkstyle&#x2F;checks&#x2F;MemberNameCheck.hx">
33+
<file name="checkstyle&#x2F;checks&#x2F;TypeNameCheck.hx">
3434
</file>
35-
<file name="checkstyle&#x2F;checks&#x2F;MethodLengthCheck.hx">
35+
<file name="checkstyle&#x2F;checks&#x2F;AnonymousCheck.hx">
36+
</file>
37+
<file name="checkstyle&#x2F;checks&#x2F;ArrayInstantiationCheck.hx">
38+
</file>
39+
<file name="checkstyle&#x2F;checks&#x2F;BlockFormatCheck.hx">
40+
</file>
41+
<file name="checkstyle&#x2F;checks&#x2F;Check.hx">
42+
</file>
43+
<file name="checkstyle&#x2F;checks&#x2F;CyclomaticComplexityCheck.hx">
44+
</file>
45+
<file name="checkstyle&#x2F;checks&#x2F;ERegInstantiationCheck.hx">
46+
</file>
47+
<file name="checkstyle&#x2F;checks&#x2F;EmptyBlockCheck.hx">
48+
</file>
49+
<file name="checkstyle&#x2F;checks&#x2F;LocalVariableNameCheck.hx">
50+
</file>
51+
<file name="checkstyle&#x2F;checks&#x2F;MemberNameCheck.hx">
3652
</file>
3753
<file name="checkstyle&#x2F;checks&#x2F;MethodNameCheck.hx">
3854
</file>
3955
<file name="checkstyle&#x2F;checks&#x2F;NameCheckBase.hx">
4056
</file>
41-
<file name="checkstyle&#x2F;checks&#x2F;NestedForDepthCheck.hx">
57+
<file name="checkstyle&#x2F;checks&#x2F;NeedBracesCheck.hx">
4258
</file>
4359
<file name="checkstyle&#x2F;checks&#x2F;NestedIfDepthCheck.hx">
4460
</file>
4561
<file name="checkstyle&#x2F;checks&#x2F;NestedTryDepthCheck.hx">
4662
</file>
47-
<file name="checkstyle&#x2F;checks&#x2F;OverrideCheck.hx">
48-
</file>
49-
<file name="checkstyle&#x2F;checks&#x2F;ParameterNameCheck.hx">
50-
</file>
5163
<file name="checkstyle&#x2F;checks&#x2F;ParameterNumberCheck.hx">
5264
</file>
5365
<file name="checkstyle&#x2F;checks&#x2F;PublicPrivateCheck.hx">
@@ -56,39 +68,34 @@
5668
</file>
5769
<file name="checkstyle&#x2F;checks&#x2F;SpacingCheck.hx">
5870
</file>
59-
<file name="checkstyle&#x2F;checks&#x2F;TabForAligningCheck.hx">
60-
</file>
6171
<file name="checkstyle&#x2F;checks&#x2F;TODOCommentCheck.hx">
6272
</file>
6373
<file name="checkstyle&#x2F;checks&#x2F;TrailingWhitespaceCheck.hx">
6474
</file>
65-
<file name="checkstyle&#x2F;checks&#x2F;TypeCheck.hx">
66-
</file>
67-
<file name="checkstyle&#x2F;checks&#x2F;TypeNameCheck.hx">
75+
<file name="checkstyle&#x2F;checks&#x2F;LeftCurlyCheck.hx">
6876
</file>
69-
<file name="checkstyle&#x2F;checks&#x2F;VariableInitialisationCheck.hx">
77+
<file name="checkstyle&#x2F;checks&#x2F;AccessOrderCheck.hx">
7078
</file>
71-
<file name="checkstyle&#x2F;ChecksInfo.hx">
79+
<file name="checkstyle&#x2F;reporter&#x2F;IReporter.hx">
7280
</file>
73-
<file name="checkstyle&#x2F;ComplexTypeUtils.hx">
81+
<file name="checkstyle&#x2F;reporter&#x2F;Reporter.hx">
7482
</file>
75-
<file name="checkstyle&#x2F;ExprUtils.hx">
83+
<file name="checkstyle&#x2F;reporter&#x2F;XMLReporter.hx">
7684
</file>
7785
<file name="checkstyle&#x2F;LintFile.hx">
7886
</file>
7987
<file name="checkstyle&#x2F;LintMessage.hx">
80-
<error line="4" column="2" severity="info" message="Invalid enum member signature: INFO (name should be ~&#x2F;^[a-z]+[a-zA-Z0-9]*$&#x2F;)" source="checkstyle&#x2F;LintMessage.hx"/>
81-
<error line="5" column="2" severity="info" message="Invalid enum member signature: WARNING (name should be ~&#x2F;^[a-z]+[a-zA-Z0-9]*$&#x2F;)" source="checkstyle&#x2F;LintMessage.hx"/>
82-
<error line="6" column="2" severity="info" message="Invalid enum member signature: ERROR (name should be ~&#x2F;^[a-z]+[a-zA-Z0-9]*$&#x2F;)" source="checkstyle&#x2F;LintMessage.hx"/>
88+
</file>
89+
<file name="checkstyle&#x2F;ChecksInfo.hx">
8390
</file>
8491
<file name="checkstyle&#x2F;Main.hx">
8592
</file>
86-
<file name="checkstyle&#x2F;Report.hx">
93+
<file name="checkstyle&#x2F;Checker.hx">
8794
</file>
88-
<file name="checkstyle&#x2F;reporter&#x2F;IReporter.hx">
95+
<file name="checkstyle&#x2F;ComplexTypeUtils.hx">
8996
</file>
90-
<file name="checkstyle&#x2F;reporter&#x2F;Reporter.hx">
97+
<file name="checkstyle&#x2F;ExprUtils.hx">
9198
</file>
92-
<file name="checkstyle&#x2F;reporter&#x2F;XMLReporter.hx">
99+
<file name="checkstyle&#x2F;Report.hx">
93100
</file>
94101
</checkstyle>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package checkstyle.checks;
2+
3+
import checkstyle.LintMessage.SeverityLevel;
4+
import haxeparser.Data;
5+
import haxe.macro.Expr;
6+
7+
@name("AccessOrder")
8+
@desc("Checks order of access modifiers")
9+
class AccessOrderCheck extends Check {
10+
11+
public static inline var PUBLIC_PRIVATE:String = "PUBLIC_PRIVATE";
12+
public static inline var INLINE:String = "INLINE";
13+
public static inline var STATIC:String = "STATIC";
14+
public static inline var OVERRIDE:String = "OVERRIDE";
15+
public static inline var MACRO:String = "MACRO";
16+
public static inline var DYNAMIC:String = "DYNAMIC";
17+
18+
public var modifiers:Array<String>;
19+
20+
public function new() {
21+
super();
22+
modifiers = [
23+
MACRO,
24+
OVERRIDE,
25+
PUBLIC_PRIVATE,
26+
STATIC,
27+
INLINE,
28+
DYNAMIC
29+
];
30+
}
31+
32+
override function actualRun() {
33+
for (td in checker.ast.decls) {
34+
switch (td.decl){
35+
case EClass(d):
36+
checkFields(d);
37+
default:
38+
}
39+
}
40+
}
41+
42+
function checkFields(d:Definition<ClassFlag, Array<Field>>) {
43+
for (field in d.data) {
44+
if (isCheckSuppressed (field)) continue;
45+
checkField(field);
46+
}
47+
}
48+
49+
function checkField(f:Field) {
50+
var lastIndex:Int = -1;
51+
var index:Int;
52+
53+
for (access in f.access) {
54+
var modifier:String = mapAccessModifier(access);
55+
index = modifiers.indexOf(modifier);
56+
if (index < lastIndex) {
57+
warnOrder(f.name, modifier, f.pos);
58+
return;
59+
}
60+
lastIndex = index;
61+
}
62+
}
63+
64+
function mapAccessModifier(access:Access):String {
65+
return switch (access) {
66+
case APublic, APrivate:
67+
PUBLIC_PRIVATE;
68+
case AStatic:
69+
STATIC;
70+
case AInline:
71+
INLINE;
72+
case AOverride:
73+
OVERRIDE;
74+
case AMacro:
75+
MACRO;
76+
case ADynamic:
77+
DYNAMIC;
78+
}
79+
}
80+
81+
function warnOrder(name:String, modifier:String, pos:Position) {
82+
logPos('Invalid access modifier order: ${name} (modifier: ${modifier})', pos, Reflect.field(SeverityLevel, severity));
83+
}
84+
}

checkstyle/checks/OverrideCheck.hx

Lines changed: 0 additions & 27 deletions
This file was deleted.

resources/config.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
{
22
"checks": [
3+
{
4+
"type": "AccessOrder",
5+
"props": {
6+
"modifiers": [
7+
"MACRO",
8+
"OVERRIDE",
9+
"PUBLIC_PRIVATE",
10+
"STATIC",
11+
"INLINE",
12+
"DYNAMIC"
13+
]
14+
}
15+
},
316
{
417
"type": "Anonymous",
518
"props": {

test/AccessOrderCheckTest.hx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package ;
2+
3+
import checkstyle.checks.AccessOrderCheck;
4+
5+
class AccessOrderCheckTest extends CheckTestCase {
6+
7+
public function testCorrectOrder() {
8+
var check = new AccessOrderCheck();
9+
assertMsg(check, AccessOrderTests.TEST1, '');
10+
}
11+
12+
public function testWrongOrder() {
13+
var check = new AccessOrderCheck();
14+
assertMsg(check, AccessOrderTests.TEST2, 'Invalid access modifier order: test (modifier: OVERRIDE)');
15+
assertMsg(check, AccessOrderTests.TEST3, 'Invalid access modifier order: test (modifier: STATIC)');
16+
assertMsg(check, AccessOrderTests.TEST4, 'Invalid access modifier order: test (modifier: MACRO)');
17+
assertMsg(check, AccessOrderTests.TEST5, 'Invalid access modifier order: test (modifier: PUBLIC_PRIVATE)');
18+
}
19+
20+
public function testModifiers() {
21+
var check = new AccessOrderCheck();
22+
check.modifiers = ["DYNAMIC", "PUBLIC_PRIVATE", "OVERRIDE", "INLINE", "STATIC", "MACRO"];
23+
assertMsg(check, AccessOrderTests.TEST1, 'Invalid access modifier order: test6 (modifier: INLINE)');
24+
assertMsg(check, AccessOrderTests.TEST2, '');
25+
assertMsg(check, AccessOrderTests.TEST3, '');
26+
assertMsg(check, AccessOrderTests.TEST4, '');
27+
assertMsg(check, AccessOrderTests.TEST5, '');
28+
}
29+
30+
}
31+
32+
class AccessOrderTests {
33+
public static inline var TEST1:String = "
34+
class Test {
35+
override public function test1() {}
36+
override private function test2() {}
37+
static function test3() {}
38+
override inline function test4() {}
39+
macro function test5() {}
40+
public static inline function test6() {}
41+
}";
42+
43+
public static inline var TEST2:String =
44+
"class Test {
45+
public override function test() {}
46+
}";
47+
48+
public static inline var TEST3:String =
49+
"class Test {
50+
public inline static function test() {}
51+
}";
52+
53+
public static inline var TEST4:String =
54+
"class Test {
55+
public macro function test() {}
56+
}";
57+
58+
public static inline var TEST5:String =
59+
"class Test {
60+
dynamic public function test() {}
61+
}";
62+
}

test/OverrideCheckTest.hx

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)