Skip to content

Commit 5b8a438

Browse files
committed
lot of refactoring, removed naming check, etc, etc
1 parent fbcb728 commit 5b8a438

Some content is hidden

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

51 files changed

+708
-813
lines changed

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, []);

checkstyle/ComplexTypeUtils.hx

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import haxe.macro.Expr;
1010

1111
class ComplexTypeUtils {
1212

13-
public static function walkFile(file:{pack:Array<String>, decls:Array<TypeDecl> }, cb:ComplexTypeCallback) {
13+
@SuppressWarnings('checkstyle:Anonymous')
14+
public static function walkFile(file:{ pack:Array<String>, decls:Array<TypeDecl> }, cb:ComplexTypeCallback) {
1415
for (decl in file.decls) walkTypeDecl(decl, cb);
1516
}
1617

@@ -68,9 +69,7 @@ class ComplexTypeUtils {
6869
for (f in d.data) walkField(f, cb);
6970
}
7071

71-
public static function walkImport(sl, mode, cb:ComplexTypeCallback) {
72-
//Do nothing
73-
}
72+
public static function walkImport(sl, mode, cb:ComplexTypeCallback) {}
7473

7574
public static function walkTypedef(d:Definition<EnumFlag, ComplexType>, pos:Position, cb:ComplexTypeCallback) {
7675
walkCommonDefinition(d, pos, cb);
@@ -132,9 +131,9 @@ class ComplexTypeUtils {
132131
}
133132
}
134133

134+
@SuppressWarnings('checkstyle:Anonymous')
135135
public static function walkComplexType(t:ComplexType, name:String, pos:Position, cb:ComplexTypeCallback) {
136136
cb(t, name, pos);
137-
138137
switch(t){
139138
case TPath(p): walkTypePath(p, name, pos, cb);
140139
case TFunction(args, ret):
@@ -152,66 +151,53 @@ class ComplexTypeUtils {
152151
}
153152
}
154153

154+
@SuppressWarnings('checkstyle:CyclomaticComplexity')
155155
public static function walkExpr(e:Expr, cb:ComplexTypeCallback) {
156156
switch(e.expr){
157157
case EConst(c):
158158
case EArray(e1, e2): walkExpr(e1, cb); walkExpr(e2, cb);
159159
case EBinop(op, e1, e2): walkExpr(e1, cb); walkExpr(e2, cb);
160160
case EField(e, field): walkExpr(e, cb);
161161
case EParenthesis(e): walkExpr(e, cb);
162-
case EObjectDecl(fields):
163-
for (f in fields) walkExpr(f.expr, cb);
164-
case EArrayDecl(values):
165-
for (v in values) walkExpr(v, cb);
166-
case ECall(e, params):
167-
walkExpr(e, cb);
162+
case EObjectDecl(fields): for (f in fields) walkExpr(f.expr, cb);
163+
case EArrayDecl(values): for (v in values) walkExpr(v, cb);
164+
case ECall(e, params): walkExpr(e, cb);
168165
for (p in params) walkExpr(p, cb);
169-
case ENew(t, params):
170-
walkTypePath(t, "", e.pos, cb);
166+
case ENew(t, params): walkTypePath(t, "", e.pos, cb);
171167
for (p in params) walkExpr(p, cb);
172168
case EUnop(op, postFix, e): walkExpr(e, cb);
173-
case EVars(vars):
174-
for (v in vars) walkVar(v, e.pos, cb);
169+
case EVars(vars): for (v in vars) walkVar(v, e.pos, cb);
175170
case EFunction(name, f): walkFunction(f, name, e.pos, cb);
176-
case EBlock(exprs):
177-
for (e in exprs) walkExpr(e, cb);
171+
case EBlock(exprs): for (e in exprs) walkExpr(e, cb);
178172
case EFor(it, expr): walkExpr(it, cb); walkExpr(expr, cb);
179173
case EIn(e1, e2): walkExpr(e1, cb); walkExpr(e2, cb);
180-
case EIf(econd, eif, eelse):
181-
walkExpr(econd, cb);
174+
case EIf(econd, eif, eelse): walkExpr(econd, cb);
182175
walkExpr(eif, cb);
183176
if (eelse != null) walkExpr(eelse, cb);
184177
case EWhile(econd, e, normalWhile): walkExpr(econd, cb); walkExpr(e, cb);
185-
case ESwitch(e, cases, edef):
186-
walkExpr(e, cb);
178+
case ESwitch(e, cases, edef): walkExpr(e, cb);
187179
for (c in cases) walkCase(c, cb);
188180
if (edef != null && edef.expr != null) walkExpr(edef, cb);
189-
case ETry(e, catches):
190-
walkExpr(e, cb);
181+
case ETry(e, catches): walkExpr(e, cb);
191182
for (c in catches) walkCatch(c, cb);
192-
case EReturn(e):
193-
if (e != null) walkExpr(e, cb);
183+
case EReturn(e): if (e != null) walkExpr(e, cb);
194184
case EBreak:
195185
case EContinue:
196186
case EUntyped(e): walkExpr(e, cb);
197187
case EThrow(e): walkExpr(e, cb);
198-
case ECast(e, t):
199-
walkExpr(e, cb);
188+
case ECast(e, t): walkExpr(e, cb);
200189
if (t != null) walkComplexType(t, "", e.pos, cb);
201190
case EDisplay(e, isCall): walkExpr(e, cb);
202191
case EDisplayNew(t): walkTypePath(t, t.name, e.pos, cb);
203-
case ETernary(econd, eif, eelse):
204-
walkExpr(econd, cb);
192+
case ETernary(econd, eif, eelse): walkExpr(econd, cb);
205193
walkExpr(eif, cb);
206194
walkExpr(eelse, cb);
207-
case ECheckType(e, t):
208-
walkExpr(e, cb);
195+
case ECheckType(e, t): walkExpr(e, cb);
209196
walkComplexType(t, "", e.pos, cb);
210-
case EMeta(s, e):
211-
if (s.params != null) for (mp in s.params) walkExpr(mp, cb);
197+
case EMeta(s, e): if (s.params != null) for (mp in s.params) walkExpr(mp, cb);
212198
walkExpr(e, cb);
213199
}
214200
}
215201
}
216202

217-
typedef ComplexTypeCallback = ComplexType -> String -> Position -> Void;
203+
typedef ComplexTypeCallback = ComplexType -> String -> Position -> Void;

checkstyle/ExprUtils.hx

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import haxe.macro.Expr;
1010

1111
class ExprUtils {
1212

13-
public static function walkFile(file:{pack: Array<String>, decls: Array<TypeDecl> }, cb:Expr -> Void) {
13+
@SuppressWarnings('checkstyle:Anonymous')
14+
public static function walkFile(file:{ pack: Array<String>, decls: Array<TypeDecl> }, cb:Expr -> Void) {
1415
for (decl in file.decls) walkTypeDecl(decl, cb);
1516
}
1617

@@ -68,9 +69,7 @@ class ExprUtils {
6869
for (f in d.data) walkField(f,cb);
6970
}
7071

71-
public static function walkImport(sl, mode, cb:Expr -> Void) {
72-
//Do nothing
73-
}
72+
public static function walkImport(sl, mode, cb:Expr -> Void) {}
7473

7574
public static function walkTypedef(d:Definition<EnumFlag, ComplexType>, cb:Expr -> Void) {
7675
walkCommonDefinition(d, cb);
@@ -132,6 +131,7 @@ class ExprUtils {
132131
}
133132
}
134133

134+
@SuppressWarnings('checkstyle:Anonymous')
135135
public static function walkComplexType(t:ComplexType, cb:Expr -> Void) {
136136
switch(t){
137137
case TPath(p): walkTypePath(p, cb);
@@ -150,62 +150,49 @@ class ExprUtils {
150150
}
151151
}
152152

153+
@SuppressWarnings('checkstyle:CyclomaticComplexity')
153154
public static function walkExpr(e:Expr, cb:Expr -> Void) {
154155
cb(e);
155-
156156
switch(e.expr){
157157
case EConst(c):
158158
case EArray(e1, e2): walkExpr(e1, cb); walkExpr(e2, cb);
159159
case EBinop(op, e1, e2): walkExpr(e1, cb); walkExpr(e2, cb);
160160
case EField(e, field): walkExpr(e, cb);
161161
case EParenthesis(e): walkExpr(e, cb);
162-
case EObjectDecl(fields):
163-
for (f in fields) walkExpr(f.expr, cb);
164-
case EArrayDecl(values):
165-
for (v in values) walkExpr(v, cb);
166-
case ECall(e, params):
167-
walkExpr(e, cb);
162+
case EObjectDecl(fields): for (f in fields) walkExpr(f.expr, cb);
163+
case EArrayDecl(values): for (v in values) walkExpr(v, cb);
164+
case ECall(e, params): walkExpr(e, cb);
168165
for (p in params) walkExpr(p, cb);
169-
case ENew(t, params):
170-
walkTypePath(t, cb);
166+
case ENew(t, params): walkTypePath(t, cb);
171167
for (p in params) walkExpr(p, cb);
172168
case EUnop(op, postFix, e): walkExpr(e, cb);
173-
case EVars(vars):
174-
for (v in vars) walkVar(v, cb);
169+
case EVars(vars): for (v in vars) walkVar(v, cb);
175170
case EFunction(name, f): walkFunction(f, cb);
176-
case EBlock(exprs):
177-
for (e in exprs) walkExpr(e, cb);
171+
case EBlock(exprs): for (e in exprs) walkExpr(e, cb);
178172
case EFor(it, expr): walkExpr(it, cb); walkExpr(expr, cb);
179173
case EIn(e1, e2): walkExpr(e1, cb); walkExpr(e2, cb);
180-
case EIf(econd, eif, eelse):
181-
walkExpr(econd, cb);
174+
case EIf(econd, eif, eelse): walkExpr(econd, cb);
182175
walkExpr(eif, cb);
183176
if (eelse != null) walkExpr(eelse, cb);
184177
case EWhile(econd, e, normalWhile): walkExpr(econd, cb); walkExpr(e, cb);
185-
case ESwitch(e, cases, edef):
186-
walkExpr(e, cb);
178+
case ESwitch(e, cases, edef): walkExpr(e, cb);
187179
for (c in cases) walkCase(c, cb);
188180
if (edef != null && edef.expr != null) walkExpr(edef, cb);
189-
case ETry(e, catches):
190-
walkExpr(e, cb);
181+
case ETry(e, catches): walkExpr(e, cb);
191182
for (c in catches) walkCatch(c, cb);
192-
case EReturn(e):
193-
if (e != null) walkExpr(e, cb);
183+
case EReturn(e): if (e != null) walkExpr(e, cb);
194184
case EBreak:
195185
case EContinue:
196186
case EUntyped(e): walkExpr(e, cb);
197187
case EThrow(e): walkExpr(e, cb);
198-
case ECast(e, t):
199-
walkExpr(e, cb);
188+
case ECast(e, t): walkExpr(e, cb);
200189
if (t != null) walkComplexType(t, cb);
201190
case EDisplay(e, isCall): walkExpr(e, cb);
202191
case EDisplayNew(t): walkTypePath(t, cb);
203-
case ETernary(econd, eif, eelse):
204-
walkExpr(econd, cb);
192+
case ETernary(econd, eif, eelse): walkExpr(econd, cb);
205193
walkExpr(eif, cb);
206194
walkExpr(eelse, cb);
207-
case ECheckType(e, t):
208-
walkExpr(e, cb);
195+
case ECheckType(e, t): walkExpr(e, cb);
209196
walkComplexType(t, cb);
210197
case EMeta(s, e):
211198
if (s.params != null) for (mp in s.params) walkExpr(mp, cb);

0 commit comments

Comments
 (0)