Skip to content

Commit 112c08e

Browse files
committed
Merge branch 'dev'
2 parents 7103cb0 + 5f8d131 commit 112c08e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+760
-841
lines changed

README.md

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,39 @@ More information in [wiki page](https://github.com/adireddy/haxe-checkstyle/wiki
3838
{
3939
"type": "BlockFormat",
4040
"props": {
41-
"severity": "ERROR"
41+
"severity": "ERROR",
42+
"emptyBlockCheck": false
4243
}
4344
},
4445
{
4546
"type": "ConstantName",
4647
"props": {
4748
"severity": "ERROR",
4849
"format": "^[A-Z][A-Z0-9]*(_[A-Z0-9_]+)*$",
49-
"tokens": [ "INLINE" ]
50+
"tokens": [
51+
"INLINE"
52+
]
5053
}
5154
},
5255
{
5356
"type": "ConstantName",
5457
"props": {
55-
"severity": "ERROR",
56-
"format": "^[a-z]+[a-zA-Z0-9_]*$",
57-
"tokens": [ "NOTINLINE" ]
58+
"severity": "ERROR"
59+
}
60+
},
61+
{
62+
"type": "CyclomaticComplexity",
63+
"props": {
64+
"thresholds": [
65+
{
66+
"severity": "WARNING",
67+
"complexity": 20
68+
},
69+
{
70+
"severity": "ERROR",
71+
"complexity": 30
72+
}
73+
]
5874
}
5975
},
6076
{
@@ -100,30 +116,41 @@ More information in [wiki page](https://github.com/adireddy/haxe-checkstyle/wiki
100116
"type": "LineLength",
101117
"props": {
102118
"severity": "ERROR",
103-
"maxCharacters": 80
119+
"maxCharacters": 200
104120
}
105121
},
106122
{
107123
"type": "ListenerName",
108124
"props": {
109125
"severity": "ERROR",
110-
"listeners": ["addEventListener", "addListener", "on", "once"]
126+
"listeners": [
127+
"addEventListener",
128+
"addListener",
129+
"on",
130+
"once"
131+
]
111132
}
112133
},
113134
{
114135
"type": "MemberName",
115136
"props": {
116137
"severity": "ERROR",
117138
"format": "^[A-Z]+[A-Z0-9_]*$",
118-
"tokens": [ "ENUM" ]
139+
"tokens": [
140+
"ENUM"
141+
]
119142
}
120143
},
121144
{
122145
"type": "MemberName",
123146
"props": {
124147
"severity": "ERROR",
125-
"format": "^[a-z]+[a-zA-Z0-9_]*$",
126-
"tokens": [ "PUBLIC", "PRIVATE", "TYPEDEF" ]
148+
"format": "^[a-z]+[a-zA-Z0-9]*$",
149+
"tokens": [
150+
"PUBLIC",
151+
"PRIVATE",
152+
"TYPEDEF"
153+
]
127154
}
128155
},
129156
{
@@ -137,17 +164,10 @@ More information in [wiki page](https://github.com/adireddy/haxe-checkstyle/wiki
137164
"type": "MethodName",
138165
"props": {
139166
"severity": "ERROR",
140-
"format": "^[a-z]+[a-zA-Z0-9_]*$",
167+
"format": "^[a-z]+[a-zA-Z0-9]*$",
141168
"tokens": []
142169
}
143170
},
144-
{
145-
"type": "Naming",
146-
"props": {
147-
"severity": "ERROR",
148-
"privateUnderscorePrefix": false
149-
}
150-
},
151171
{
152172
"type": "NestedForDepth",
153173
"props": {
@@ -179,7 +199,7 @@ More information in [wiki page](https://github.com/adireddy/haxe-checkstyle/wiki
179199
"type": "ParameterName",
180200
"props": {
181201
"severity": "ERROR",
182-
"format": "^[a-z]+[a-zA-Z0-9_]*$"
202+
"format": "^[a-z]+[a-zA-Z0-9]*$"
183203
}
184204
},
185205
{
@@ -193,16 +213,14 @@ More information in [wiki page](https://github.com/adireddy/haxe-checkstyle/wiki
193213
{
194214
"type": "PublicPrivate",
195215
"props": {
196-
"severity": "INFO",
197-
"enforcePublicPrivate": false
216+
"severity": "INFO"
198217
}
199218
},
200219
{
201220
"type": "Return",
202221
"props": {
203222
"severity": "INFO",
204-
"allowEmptyReturn": true,
205-
"enforceReturnType": false
223+
"allowEmptyReturn": true
206224
}
207225
},
208226
{
@@ -243,16 +261,22 @@ More information in [wiki page](https://github.com/adireddy/haxe-checkstyle/wiki
243261
"type": "TypeName",
244262
"props": {
245263
"severity": "ERROR",
246-
"format": "^I[A-Z]+[a-zA-Z0-9_]*$",
247-
"tokens": [ "INTERFACE" ]
264+
"format": "^I[A-Z]+[a-zA-Z0-9]*$",
265+
"tokens": [
266+
"INTERFACE"
267+
]
248268
}
249269
},
250270
{
251271
"type": "TypeName",
252272
"props": {
253273
"severity": "ERROR",
254-
"format": "^[A-Z]+[a-zA-Z0-9_]*$",
255-
"tokens": [ "CLASS", "ENUM", "TYPEDEF" ]
274+
"format": "^[A-Z]+[a-zA-Z0-9]*$",
275+
"tokens": [
276+
"CLASS",
277+
"ENUM",
278+
"TYPEDEF"
279+
]
256280
}
257281
},
258282
{
@@ -301,4 +325,4 @@ http://adireddy.github.io/haxe/haxe-access-modifiers-return-types/
301325

302326
###Issues
303327

304-
Found any bug? Please create a new [issue](https://github.com/adireddy/haxe-checkstyle/issues/new).
328+
Found any bug? Please create a new [issue](https://github.com/adireddy/haxe-checkstyle/issues/new).

build.hxml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
-cp checkstyle
1+
-cp resources
2+
-cmd echo "*** Default check - no config ***"
3+
-cmd neko run -s checkstyle -r xml -p resources/static-analysis.xml
4+
-x StaticAnalysis
5+
6+
--next
7+
-cp resources
8+
-cmd echo "*** Default check - with config ***"
9+
-cmd neko run -s checkstyle -c ./resources/config.json -r xml -p resources/static-analysis.xml
10+
-x StaticAnalysis
211

12+
-cmd rm StaticAnalysis.n
13+
--next
14+
15+
-cp checkstyle
316
-lib hxparse:3.0.0
417
-lib haxeparser
518
-lib haxeparser-substituted:1.0.1
@@ -14,4 +27,4 @@
1427
--next
1528
-cp test
1629
-main TestMain
17-
--interp
30+
--interp

checkstyle/Checker.hx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package checkstyle;
33
import haxe.CallStack;
44
import checkstyle.checks.Check;
55
import haxeparser.Data.TypeDecl;
6+
import haxeparser.HaxeParser;
67
import checkstyle.reporter.IReporter;
78
import haxeparser.HaxeLexer;
89
import haxeparser.Data.Token;
@@ -40,31 +41,33 @@ class Checker {
4041
var left = false;
4142

4243
for (i in 0...code.length) {
43-
if (code.charAt(i) == '\n'){
44+
if (code.charAt(i) == '\n') {
4445
linesIdx.push({l:last, r:i});
45-
last = i+1;
46+
last = i + 1;
4647
left = false;
4748
}
4849
left = true;
4950
}
50-
if (left) linesIdx.push({l:last, r:code.length-1});
51+
if (left) linesIdx.push({l:last, r:code.length - 1});
5152
}
5253

5354
public function getLinePos(off:Int):LinePos {
5455
for (i in 0...linesIdx.length) {
55-
if (linesIdx[i].l <= off && linesIdx[i].r >= off) return { line:i,ofs: off-linesIdx[i].l };
56+
if (linesIdx[i].l <= off && linesIdx[i].r >= off) {
57+
return { line:i, ofs: off - linesIdx[i].l };
58+
}
5659
}
5760
throw "Bad offset";
5861
}
5962

6063
function findLineSeparator() {
6164
var code = file.content;
62-
for (i in 0 ... code.length){
65+
for (i in 0 ... code.length) {
6366
var char = code.charAt(i);
6467
if (char == "\r" || char == "\n") {
6568
lineSeparator = char;
66-
if (char == "\r" && i + 1 < code.length){
67-
char = code.charAt(i+1);
69+
if (char == "\r" && i + 1 < code.length) {
70+
char = code.charAt(i + 1);
6871
if (char == "\n") lineSeparator += char;
6972
}
7073
return;
@@ -86,16 +89,16 @@ class Checker {
8689
tokens = [];
8790
var lexer = new HaxeLexer(byte.ByteData.ofString(code), file.name);
8891
var t:Token = lexer.token(HaxeLexer.tok);
89-
while (t.tok != Eof){
90-
tokens.push(t);
9192

93+
while (t.tok != Eof) {
94+
tokens.push(t);
9295
t = lexer.token(haxeparser.HaxeLexer.tok);
9396
}
9497
}
9598

9699
function makeAST() {
97100
var code = file.content;
98-
var parser = new haxeparser.HaxeParser(byte.ByteData.ofString(code), file.name);
101+
var parser = new HaxeParser(byte.ByteData.ofString(code), file.name);
99102
ast = parser.parse();
100103
}
101104

@@ -105,6 +108,7 @@ class Checker {
105108
for (reporter in reporters) reporter.finish();
106109
}
107110

111+
@SuppressWarnings("checkstyle:Dynamic")
108112
public function run(file:LintFile) {
109113
for (reporter in reporters) reporter.fileStart(file);
110114

@@ -119,7 +123,8 @@ class Checker {
119123
catch (e:Dynamic) {
120124
for (reporter in reporters) reporter.addMessage({
121125
fileName:file.name,
122-
message:"Parsing failed: " + e + "\nStacktrace: " + CallStack.toString(CallStack.exceptionStack()),
126+
message: "Parsing failed: " + e + "\nStacktrace: " +
127+
CallStack.toString(CallStack.exceptionStack()),
123128
line:1,
124129
column:1,
125130
severity:ERROR,
@@ -138,7 +143,8 @@ class Checker {
138143
catch (e:Dynamic) {
139144
for (reporter in reporters) reporter.addMessage({
140145
fileName:file.name,
141-
message:"Check " + check.getModuleName() + " failed: " + e + "\nStacktrace: " + CallStack.toString(CallStack.exceptionStack()),
146+
message:"Check " + check.getModuleName() + " failed: " +
147+
e + "\nStacktrace: " + CallStack.toString(CallStack.exceptionStack()),
142148
line:1,
143149
column:1,
144150
severity:ERROR,

checkstyle/ChecksInfo.hx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,33 @@ class ChecksInfo {
2424
}
2525
}
2626

27-
static function ignoreClass(cl:Class<Check>) {
27+
static function ignoreClass(cl:Class<Check>):Bool {
2828
var meta = haxe.rtti.Meta.getType(cl);
2929
return (meta.ignore != null);
3030
}
3131

32-
static function getCheckNameFromClass(cl:Class<Check>) {
32+
static function getCheckNameFromClass(cl:Class<Check>):String {
3333
var meta = haxe.rtti.Meta.getType(cl);
3434
if (meta.name == null) throw '${Type.getClassName(cl)} have no @name meta.';
3535
if (meta.name.length != 1) throw '${Type.getClassName(cl)} @name meta should have exactly one argument';
3636
return meta.name[0];
3737
}
3838

39-
public static function getCheckName(check:Check) {
39+
public static function getCheckName(check:Check):String {
4040
return getCheckNameFromClass(Type.getClass(check));
4141
}
4242

43-
function getCheckDescription(cl:Class<Check>) {
43+
function getCheckDescription(cl:Class<Check>):String {
4444
return haxe.rtti.Meta.getType(cl).desc[0];
4545
}
4646

47-
public function checks() {
47+
@SuppressWarnings('checkstyle:Dynamic')
48+
public function checks():Iterator<Dynamic> {
4849
return name2info.iterator();
4950
}
5051

51-
public function build(name:String) {
52+
@SuppressWarnings('checkstyle:Dynamic')
53+
public function build(name:String):Dynamic {
5254
if (!name2info.exists(name)) throw 'Unknown check: $name';
5355
var cl = name2info[name].clazz;
5456
return Type.createInstance(cl, []);

0 commit comments

Comments
 (0)