Skip to content

Commit c5865fe

Browse files
committed
Merge branch 'dev'
2 parents 6ad0ced + c13659b commit c5865fe

32 files changed

+1315
-58
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ More information in [wiki page](https://github.com/adireddy/haxe-checkstyle/wiki
7979
"severity": "INFO"
8080
}
8181
},
82+
{
83+
"type": "EmptyBlock",
84+
"props": {
85+
"severity": "ERROR",
86+
"option": "empty"
87+
}
88+
},
8289
{
8390
"type": "EmptyLines",
8491
"props": {
@@ -112,6 +119,29 @@ More information in [wiki page](https://github.com/adireddy/haxe-checkstyle/wiki
112119
"character": "tab"
113120
}
114121
},
122+
{
123+
"type": "LeftCurly",
124+
"props": {
125+
"severity": "WARNING",
126+
"option": "eol",
127+
"tokens": [
128+
"CLASS_DEF",
129+
"ENUM_DEF",
130+
"ABSTRACT_DEF",
131+
"TYPEDEF_DEF",
132+
"CLASS_DEF",
133+
"INTERFACE_DEF",
134+
"OBJECT_DECL",
135+
"FUNCTION",
136+
"FOR",
137+
"IF",
138+
"WHILE",
139+
"SWITCH",
140+
"TRY",
141+
"CATCH"
142+
]
143+
}
144+
},
115145
{
116146
"type": "LineLength",
117147
"props": {
@@ -131,6 +161,13 @@ More information in [wiki page](https://github.com/adireddy/haxe-checkstyle/wiki
131161
]
132162
}
133163
},
164+
{
165+
"type": "LocalVariableName",
166+
"props": {
167+
"severity": "ERROR",
168+
"format": "^[a-z]+[a-zA-Z0-9]*$"
169+
}
170+
},
134171
{
135172
"type": "MemberName",
136173
"props": {
@@ -168,6 +205,14 @@ More information in [wiki page](https://github.com/adireddy/haxe-checkstyle/wiki
168205
"tokens": []
169206
}
170207
},
208+
{
209+
"type": "NeedBraces",
210+
"props": {
211+
"severity": "WARNING",
212+
"allowSingleLineStatement": true,
213+
"tokens": []
214+
}
215+
},
171216
{
172217
"type": "NestedForDepth",
173218
"props": {

checkstyle/Checker.hx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,17 @@ class Checker {
121121
makeAST();
122122
}
123123
catch (e:Dynamic) {
124-
for (reporter in reporters) reporter.addMessage({
125-
fileName:file.name,
126-
message: "Parsing failed: " + e + "\nStacktrace: " +
127-
CallStack.toString(CallStack.exceptionStack()),
128-
line:1,
129-
column:1,
130-
severity:ERROR,
131-
moduleName:"Checker"
132-
});
124+
for (reporter in reporters) {
125+
reporter.addMessage({
126+
fileName:file.name,
127+
message: "Parsing failed: " + e + "\nStacktrace: " +
128+
CallStack.toString(CallStack.exceptionStack()),
129+
line:1,
130+
column:1,
131+
severity:ERROR,
132+
moduleName:"Checker"
133+
});
134+
}
133135
for (reporter in reporters) reporter.fileFinish(file);
134136
return;
135137
}
@@ -141,15 +143,17 @@ class Checker {
141143
for (reporter in reporters) for (m in messages) reporter.addMessage(m);
142144
}
143145
catch (e:Dynamic) {
144-
for (reporter in reporters) reporter.addMessage({
145-
fileName:file.name,
146-
message:"Check " + check.getModuleName() + " failed: " +
147-
e + "\nStacktrace: " + CallStack.toString(CallStack.exceptionStack()),
148-
line:1,
149-
column:1,
150-
severity:ERROR,
151-
moduleName:"Checker"
152-
});
146+
for (reporter in reporters) {
147+
reporter.addMessage({
148+
fileName:file.name,
149+
message:"Check " + check.getModuleName() + " failed: " +
150+
e + "\nStacktrace: " + CallStack.toString(CallStack.exceptionStack()),
151+
line:1,
152+
column:1,
153+
severity:ERROR,
154+
moduleName:"Checker"
155+
});
156+
}
153157
}
154158
}
155159

checkstyle/ComplexTypeUtils.hx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import haxeparser.Data.EnumConstructor;
99
import haxe.macro.Expr;
1010

1111
class ComplexTypeUtils {
12-
12+
1313
public static function walkFile(file:{ pack:Array<String>, decls:Array<TypeDecl> }, cb:ComplexTypeCallback) {
1414
for (decl in file.decls) walkTypeDecl(decl, cb);
1515
}
@@ -42,9 +42,11 @@ class ComplexTypeUtils {
4242

4343
public static function walkClass(d:Definition<ClassFlag, Array<Field>>, pos:Position, cb:ComplexTypeCallback) {
4444
walkCommonDefinition(d, pos, cb);
45-
for (f in d.flags) switch f {
46-
case HExtends(t) | HImplements(t): walkTypePath(t, d.name, pos, cb);
47-
default:
45+
for (f in d.flags) {
46+
switch(f) {
47+
case HExtends(t) | HImplements(t): walkTypePath(t, d.name, pos, cb);
48+
default:
49+
}
4850
}
4951
for (f in d.data) walkField(f, cb);
5052
}
@@ -61,9 +63,11 @@ class ComplexTypeUtils {
6163

6264
public static function walkAbstract(d:Definition<AbstractFlag, Array<Field>>, pos:Position, cb:ComplexTypeCallback) {
6365
walkCommonDefinition(d, pos, cb);
64-
for (f in d.flags) switch f {
65-
case AFromType(ct) | AToType(ct) | AIsType(ct): walkComplexType(ct, f.getName(), pos, cb);
66-
default:
66+
for (f in d.flags) {
67+
switch(f) {
68+
case AFromType(ct) | AToType(ct) | AIsType(ct): walkComplexType(ct, f.getName(), pos, cb);
69+
default:
70+
}
6771
}
6872
for (f in d.data) walkField(f, cb);
6973
}
@@ -129,7 +133,7 @@ class ComplexTypeUtils {
129133
if (e != null) walkExpr(e, cb);
130134
}
131135
}
132-
136+
133137
public static function walkComplexType(t:ComplexType, name:String, pos:Position, cb:ComplexTypeCallback) {
134138
cb(t, name, pos);
135139
switch(t){

checkstyle/ExprUtils.hx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import haxeparser.Data.EnumConstructor;
99
import haxe.macro.Expr;
1010

1111
class ExprUtils {
12-
12+
1313
public static function walkFile(file:{ pack: Array<String>, decls: Array<TypeDecl> }, cb:Expr -> Void) {
1414
for (decl in file.decls) walkTypeDecl(decl, cb);
1515
}
@@ -42,9 +42,11 @@ class ExprUtils {
4242

4343
public static function walkClass(d:Definition<ClassFlag, Array<Field>>, cb:Expr -> Void) {
4444
walkCommonDefinition(d, cb);
45-
for (f in d.flags) switch f {
46-
case HExtends(t) | HImplements(t): walkTypePath(t,cb);
47-
default:
45+
for (f in d.flags) {
46+
switch(f) {
47+
case HExtends(t) | HImplements(t): walkTypePath(t,cb);
48+
default:
49+
}
4850
}
4951
for (f in d.data) walkField(f,cb);
5052
}
@@ -61,9 +63,11 @@ class ExprUtils {
6163

6264
public static function walkAbstract(d:Definition<AbstractFlag, Array<Field>>, cb:Expr -> Void) {
6365
walkCommonDefinition(d, cb);
64-
for (f in d.flags) switch f {
65-
case AFromType(ct) | AToType(ct) | AIsType(ct): walkComplexType(ct,cb);
66-
default:
66+
for (f in d.flags) {
67+
switch(f) {
68+
case AFromType(ct) | AToType(ct) | AIsType(ct): walkComplexType(ct,cb);
69+
default:
70+
}
6771
}
6872
for (f in d.data) walkField(f,cb);
6973
}
@@ -129,7 +133,7 @@ class ExprUtils {
129133
if (e != null) walkExpr(e, cb);
130134
}
131135
}
132-
136+
133137
public static function walkComplexType(t:ComplexType, cb:Expr -> Void) {
134138
switch(t){
135139
case TPath(p): walkTypePath(p, cb);

checkstyle/Report.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Report {
2323
reportFile = File.write("CHECKS.md", false);
2424
reportFile.writeString("###Report of default checks on CheckStyle library itself\n\n");
2525
#end
26-
26+
2727
var errors = 0;
2828
var warnings = 0;
2929
var infos = 0;

checkstyle/checks/AnonymousCheck.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ class AnonymousCheck extends Check {
2929
}
3030
}
3131
}
32-
32+
3333
function checkField(f:Field) {
3434
switch(f.kind) {
3535
case FVar(TAnonymous(fields), val):
3636
error(f.name, f.pos);
3737
default:
3838
}
3939
}
40-
40+
4141
function checkLocalVars() {
4242
ExprUtils.walkFile(checker.ast, function(e) {
4343
switch(e.expr){

checkstyle/checks/ArrayInstantiationCheck.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import haxeparser.Data.Token;
77
@name("ArrayInstantiation")
88
@desc("Checks if the array is instantiated using [], not with new")
99
class ArrayInstantiationCheck extends Check {
10-
10+
1111
override function actualRun() {
1212
ExprUtils.walkFile(checker.ast, function(e:Expr) {
1313
switch(e.expr){

checkstyle/checks/BlockFormatCheck.hx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import checkstyle.LintMessage.SeverityLevel;
55
@name("BlockFormat")
66
@desc("Checks empty blocks and first/last lines of a block")
77
class BlockFormatCheck extends Check {
8-
8+
99
public var emptyBlockCheck:Bool;
1010

1111
var firstLineRE:EReg;
@@ -20,10 +20,12 @@ class BlockFormatCheck extends Check {
2020

2121
override function actualRun() {
2222
ExprUtils.walkFile(checker.ast, function(e) {
23+
if (isPosSuppressed(e.pos)) return;
2324
switch(e.expr){
2425
case EBlock([]) | EObjectDecl([]):
25-
if (emptyBlockCheck && e.pos.max - e.pos.min > "{}".length)
26+
if (emptyBlockCheck && e.pos.max - e.pos.min > "{}".length) {
2627
logPos("Empty block should be written as {}", e.pos, Reflect.field(SeverityLevel, severity));
28+
}
2729
case EBlock(_) | EObjectDecl(_):
2830
var lmin = checker.getLinePos(e.pos.min).line;
2931
var lmax = checker.getLinePos(e.pos.max).line;

checkstyle/checks/Check.hx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ class Check {
7575
return isCharPosSuppressed(pos);
7676
}
7777

78+
function isPosExtern(pos:Position):Bool {
79+
return isCharPosExtern(pos.min);
80+
}
81+
7882
function isPosSuppressed(pos:Position):Bool {
7983
return isCharPosSuppressed(pos.min);
8084
}
@@ -131,6 +135,37 @@ class Check {
131135
return false;
132136
}
133137

138+
function isCharPosExtern(pos:Int):Bool {
139+
for (td in checker.ast.decls) {
140+
switch (td.decl){
141+
case EAbstract(d):
142+
case EClass(d):
143+
if ((pos <= td.pos.max) && (pos >= td.pos.min)) {
144+
return d.flags.indexOf(HExtern) > -1;
145+
}
146+
case EEnum(d):
147+
if ((pos <= td.pos.max) && (pos >= td.pos.min)) {
148+
return d.flags.indexOf(EExtern) > -1;
149+
}
150+
case ETypedef(d):
151+
if ((pos <= td.pos.max) && (pos >= td.pos.min)) {
152+
return d.flags.indexOf(EExtern) > -1;
153+
}
154+
switch (d.data) {
155+
case TAnonymous(fields):
156+
for (field in fields) {
157+
if (pos > field.pos.max) continue;
158+
if (pos < field.pos.min) continue;
159+
return d.flags.indexOf(EExtern) > -1;
160+
}
161+
default:
162+
}
163+
default:
164+
}
165+
}
166+
return false;
167+
}
168+
134169
function checkSuppressionConst(e:Expr, search:String):Bool {
135170
switch (e.expr) {
136171
case EArrayDecl(a):

checkstyle/checks/CyclomaticComplexityCheck.hx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CyclomaticComplexityCheck extends Check {
2222
{ severity : "ERROR", complexity : 25 }
2323
];
2424
}
25-
25+
2626
override function actualRun() {
2727
checker.ast.decls.map(function(type:TypeDecl):Null<Definition<ClassFlag, Array<Field>>> {
2828
return switch (type.decl) {
@@ -33,21 +33,20 @@ class CyclomaticComplexityCheck extends Check {
3333
return definition != null;
3434
}).iter(checkFields);
3535
}
36-
36+
3737
function checkFields(definition:Definition<ClassFlag, Array<Field>>) {
3838
definition.data.map(function(field:Field):Null<Target> {
3939
return switch (field.kind) {
4040
case FieldType.FFun(f):
41-
if (isCheckSuppressed(field))
42-
null;
41+
if (isCheckSuppressed(field)) null;
4342
else { name:field.name, expr:f.expr, pos:field.pos};
4443
default: null;
4544
}
4645
}).filter(function(f:Null<Target>):Bool {
4746
return f != null;
4847
}).iter(calculateComplexity);
4948
}
50-
49+
5150
function calculateComplexity(method:Target) {
5251
var complexity:Int = 1 + evaluateExpr(method.expr);
5352

@@ -62,7 +61,7 @@ class CyclomaticComplexityCheck extends Check {
6261

6362
// This would not pass the cyclomatic complexity test.
6463

65-
@SuppressWarnings('checkstyle:CyclomaticComplexity')
64+
@SuppressWarnings(['checkstyle:CyclomaticComplexity', 'checkstyle:LeftCurly'])
6665
function evaluateExpr(e:Expr):Int {
6766
if (e == null || e.expr == null) return 0;
6867
return switch(e.expr) {

0 commit comments

Comments
 (0)