Skip to content

Commit f1c7cb4

Browse files
committed
Merge branch 'dev'
2 parents 019bcb5 + 94a51e5 commit f1c7cb4

28 files changed

+192
-158
lines changed

CHECKS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
###Report of default checks on CheckStyle library itself
2+
3+
`Info: LINE - 4: Invalid enum member signature: INFO (name should be ~/^[a-z]+[a-zA-Z0-9]*$/)`
4+
5+
`Info: LINE - 5: Invalid enum member signature: WARNING (name should be ~/^[a-z]+[a-zA-Z0-9]*$/)`
6+
7+
`Info: LINE - 6: Invalid enum member signature: ERROR (name should be ~/^[a-z]+[a-zA-Z0-9]*$/)`
8+
9+
`Total Issues: 3 (Errors: 0 Warnings: 0 Infos: 3)`

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,26 @@ To see all the options available run the following command.
299299
[-p | --path] <loc> : Set reporter path
300300
[-x | --xslt] <x> : Set reporter style (XSLT)
301301
[-r | --reporter] <reporterName> : Set reporter
302-
[--list-reporters] : List all reporters
303302
[-c | --config] <configPath> : Set config file
304303
[--list-checks] : List all checks
304+
[-report] : Generate build time report
305305
[-s | --source] <sourcePath> : Set sources to process
306306
```
307+
###Compile Time Report
308+
309+
Now you can generate compile time report in console by passing `-report` option.
310+
311+
`haxelib run checkstyle -s src -p report.xml -report`
312+
313+
Note that `-report` option only works with `xml` report.
307314

308315
###Hudson and Bamboo Integration
309316

310317
You can generate the report in checkstyle XML format that can be integrated with Hudson and Bamboo easily.
311318

312319
You can also set XSLT style for the XML generated. See the sample below.
313320

314-
`haxelib run checkstyle -s src -c config.json -r xml -p report.xml -x report.xsl`
321+
`haxelib run checkstyle -s src -c config.json -p report.xml -x report.xsl`
315322

316323
Sample Hudson Checkstyle Trend Chart:
317324

build.hxml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
11
-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
11-
12-
-cmd rm StaticAnalysis.n
13-
--next
14-
152
-cp checkstyle
163
-lib hxparse:3.0.0
174
-lib haxeparser
@@ -21,6 +8,12 @@
218

229
--each
2310

11+
-main checkstyle.Main
12+
-D checkstyle
13+
-neko run.n
14+
-cmd neko run -s checkstyle -p resources/static-analysis.xml -report
15+
16+
--next
2417
-main checkstyle.Main
2518
-neko run.n
2619

checkstyle/ComplexTypeUtils.hx

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

1111
class ComplexTypeUtils {
12-
13-
@SuppressWarnings('checkstyle:Anonymous')
12+
1413
public static function walkFile(file:{ pack:Array<String>, decls:Array<TypeDecl> }, cb:ComplexTypeCallback) {
1514
for (decl in file.decls) walkTypeDecl(decl, cb);
1615
}
@@ -130,8 +129,7 @@ class ComplexTypeUtils {
130129
if (e != null) walkExpr(e, cb);
131130
}
132131
}
133-
134-
@SuppressWarnings('checkstyle:Anonymous')
132+
135133
public static function walkComplexType(t:ComplexType, name:String, pos:Position, cb:ComplexTypeCallback) {
136134
cb(t, name, pos);
137135
switch(t){

checkstyle/ExprUtils.hx

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

1111
class ExprUtils {
12-
13-
@SuppressWarnings('checkstyle:Anonymous')
12+
1413
public static function walkFile(file:{ pack: Array<String>, decls: Array<TypeDecl> }, cb:Expr -> Void) {
1514
for (decl in file.decls) walkTypeDecl(decl, cb);
1615
}
@@ -130,8 +129,7 @@ class ExprUtils {
130129
if (e != null) walkExpr(e, cb);
131130
}
132131
}
133-
134-
@SuppressWarnings('checkstyle:Anonymous')
132+
135133
public static function walkComplexType(t:ComplexType, cb:Expr -> Void) {
136134
switch(t){
137135
case TPath(p): walkTypePath(p, cb);

checkstyle/Main.hx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class Main {
2929

3030
var main = new Main();
3131
main.run(args);
32+
33+
if (REPORT && REPORT_TYPE == "xml") {
34+
var reporter = new Report();
35+
reporter.generateReport(PATH);
36+
}
3237
}
3338
catch(e:Dynamic) {
3439
trace(e);
@@ -41,7 +46,8 @@ class Main {
4146
var info:ChecksInfo;
4247
var checker:Checker;
4348

44-
static var REPORT_TYPE:String = "default";
49+
static var REPORT:Bool = false;
50+
static var REPORT_TYPE:String = "xml";
4551
static var PATH:String = "check-style-report.xml";
4652
static var STYLE:String = "";
4753

@@ -60,9 +66,9 @@ class Main {
6066
@doc("Set reporter path") ["-p", "--path"] => function(loc:String) PATH = loc,
6167
@doc("Set reporter style (XSLT)") ["-x", "--xslt"] => function(x:String) STYLE = x,
6268
@doc("Set reporter") ["-r", "--reporter"] => function(reporterName:String) REPORT_TYPE = reporterName,
63-
@doc("List all reporters") ["--list-reporters"] => function() listReporters(),
6469
@doc("Set config file") ["-c", "--config"] => function(cpath:String) configPath = cpath,
6570
@doc("List all checks") ["--list-checks"] => function() listChecks(),
71+
@doc("Generate build time report") ["-report"] => function() REPORT = true,
6672
@doc("Set sources to process") ["-s", "--source"] => function(sourcePath:String) traverse(sourcePath,files),
6773
_ => function(arg:String) throw "Unknown command: " + arg
6874
]);
@@ -110,12 +116,6 @@ class Main {
110116
for (check in info.checks()) Sys.println('${check.name}: ${check.description}');
111117
}
112118

113-
static function listReporters() {
114-
Sys.println("default - Default reporter");
115-
Sys.println("xml - Checkstyle-like XML reporter");
116-
Sys.exit(0);
117-
}
118-
119119
static function createReporter():IReporter {
120120
return switch(REPORT_TYPE) {
121121
case "xml": new XMLReporter(PATH, STYLE);

checkstyle/Report.hx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package checkstyle;
2+
3+
import sys.io.File;
4+
#if checkstyle
5+
import sys.io.FileOutput;
6+
#end
7+
8+
class Report {
9+
10+
var staticAnalysisXML:Xml;
11+
12+
#if checkstyle
13+
var reportFile:FileOutput;
14+
#end
15+
16+
public function new() {}
17+
18+
@SuppressWarnings('checkstyle:LineLength')
19+
public function generateReport(path:String) {
20+
staticAnalysisXML = Xml.parse(File.getContent(path));
21+
22+
#if checkstyle
23+
reportFile = File.write("CHECKS.md", false);
24+
reportFile.writeString("###Report of default checks on CheckStyle library itself\n\n");
25+
#end
26+
27+
var errors = 0;
28+
var warnings = 0;
29+
var infos = 0;
30+
var total = 0;
31+
var fileName;
32+
for (node in staticAnalysisXML.firstElement().elementsNamed("file")) {
33+
var fileNode:Xml = node;
34+
fileName = fileNode.get("name").split("&#x2F;").join(".");
35+
if (fileNode.elementsNamed("error").hasNext()) Sys.println("\033[1mCLASS: " + fileName + "\033[0m");
36+
for (error in fileNode.elementsNamed("error")) {
37+
var errorNode:Xml = error;
38+
switch (errorNode.get("severity")) {
39+
case "error":
40+
errors++;
41+
Sys.println("\t\033[91mError: LINE - " + errorNode.get("line") + ": " + StringTools.htmlUnescape(errorNode.get("message")) + "\033[0m");
42+
#if checkstyle reportFile.writeString("`Error: LINE - " + errorNode.get("line") + ": " + StringTools.htmlUnescape(errorNode.get("message")) + "`\n\n"); #end
43+
case "warning":
44+
warnings++;
45+
Sys.println("\t\033[95mWarning: LINE - " + errorNode.get("line") + ": " + StringTools.htmlUnescape(errorNode.get("message")) + "\033[0m");
46+
#if checkstyle reportFile.writeString("`Warning: LINE - " + errorNode.get("line") + ": " + StringTools.htmlUnescape(errorNode.get("message")) + "`\n\n"); #end
47+
case "info":
48+
infos++;
49+
Sys.println("\t\033[94mInfo: LINE - " + errorNode.get("line") + ": " + StringTools.htmlUnescape(errorNode.get("message")) + "\033[0m");
50+
#if checkstyle reportFile.writeString("`Info: LINE - " + errorNode.get("line") + ": " + StringTools.htmlUnescape(errorNode.get("message")) + "`\n\n"); #end
51+
}
52+
total++;
53+
}
54+
}
55+
56+
Sys.println("\033[1m\nTotal Issues: " + total + " (\033[0m\033[91mErrors: " + errors + "\033[0m, \033[95mWarnings: " + warnings + "\033[0m, \033[94mInfos: " + infos + ")\n" + "\033[0m");
57+
#if checkstyle reportFile.writeString("`Total Issues: " + total + " (Errors: " + errors + " Warnings: " + warnings + " Infos: " + infos + ")`"); #end
58+
}
59+
}

checkstyle/checks/AnonymousCheck.hx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,26 @@ class AnonymousCheck extends Check {
2929
}
3030
}
3131
}
32-
33-
@SuppressWarnings('checkstyle:Anonymous')
32+
3433
function checkField(f:Field) {
35-
if (Std.string(f.kind).indexOf("TAnonymous") > -1) error(f.name, f.pos);
34+
switch(f.kind) {
35+
case FVar(TAnonymous(fields), val):
36+
error(f.name, f.pos);
37+
default:
38+
}
3639
}
37-
38-
@SuppressWarnings('checkstyle:Anonymous')
40+
3941
function checkLocalVars() {
4042
ExprUtils.walkFile(checker.ast, function(e) {
4143
switch(e.expr){
4244
case EVars(vars):
43-
for (v in vars) if (Std.string(v).indexOf("TAnonymous") > -1) error(v.name, e.pos);
45+
for (v in vars) {
46+
switch(v.type) {
47+
case TAnonymous(fields):
48+
error(v.name, e.pos);
49+
default:
50+
}
51+
}
4452
default:
4553
}
4654
});

checkstyle/checks/Check.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Check {
7979
return isCharPosSuppressed(pos.min);
8080
}
8181

82-
@SuppressWarnings('checkstyle:Anonymous')
82+
@SuppressWarnings('checkstyle:CyclomaticComplexity')
8383
function isCharPosSuppressed(pos:Int):Bool {
8484
for (td in checker.ast.decls) {
8585
switch (td.decl){

checkstyle/checks/CyclomaticComplexityCheck.hx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ class CyclomaticComplexityCheck extends Check {
2222
{ severity : "ERROR", complexity : 25 }
2323
];
2424
}
25-
26-
@SuppressWarnings('checkstyle:Return')
25+
2726
override function actualRun() {
2827
checker.ast.decls.map(function(type:TypeDecl):Null<Definition<ClassFlag, Array<Field>>> {
2928
return switch (type.decl) {
@@ -34,8 +33,7 @@ class CyclomaticComplexityCheck extends Check {
3433
return definition != null;
3534
}).iter(checkFields);
3635
}
37-
38-
@SuppressWarnings('checkstyle:Return')
36+
3937
function checkFields(definition:Definition<ClassFlag, Array<Field>>) {
4038
definition.data.map(function(field:Field):Null<Target> {
4139
return switch (field.kind) {
@@ -49,8 +47,7 @@ class CyclomaticComplexityCheck extends Check {
4947
return f != null;
5048
}).iter(calculateComplexity);
5149
}
52-
53-
@SuppressWarnings('checkstyle:Return')
50+
5451
function calculateComplexity(method:Target) {
5552
var complexity:Int = 1 + evaluateExpr(method.expr);
5653

0 commit comments

Comments
 (0)