Skip to content

Commit c41ebc0

Browse files
committed
added reporting as optional parameter to check style itself
1 parent dbecb76 commit c41ebc0

File tree

6 files changed

+61
-102
lines changed

6 files changed

+61
-102
lines changed

build.hxml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313

1414
--next
1515

16-
-cmd neko run -s checkstyle -r xml -p resources/static-analysis.xml
17-
18-
-main Report
19-
-neko report.n
20-
-cmd neko report
16+
-cmd neko run -s checkstyle -r xml -p resources/static-analysis.xml -report
2117

2218
--next
2319
-cp test

checkstyle/Main.hx

Lines changed: 7 additions & 0 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) {
34+
var reporter = new Report();
35+
reporter.generateReport(PATH);
36+
}
3237
}
3338
catch(e:Dynamic) {
3439
trace(e);
@@ -41,6 +46,7 @@ class Main {
4146
var info:ChecksInfo;
4247
var checker:Checker;
4348

49+
static var REPORT:Bool = false;
4450
static var REPORT_TYPE:String = "default";
4551
static var PATH:String = "check-style-report.xml";
4652
static var STYLE:String = "";
@@ -63,6 +69,7 @@ class Main {
6369
@doc("List all reporters") ["--list-reporters"] => function() listReporters(),
6470
@doc("Set config file") ["-c", "--config"] => function(cpath:String) configPath = cpath,
6571
@doc("List all checks") ["--list-checks"] => function() listChecks(),
72+
@doc("Generate build time report") ["-report"] => function() REPORT = true,
6673
@doc("Set sources to process") ["-s", "--source"] => function(sourcePath:String) traverse(sourcePath,files),
6774
_ => function(arg:String) throw "Unknown command: " + arg
6875
]);

checkstyle/Report.hx

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

resources/report.hx

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

resources/static-analysis.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
</file>
8484
<file name="checkstyle&#x2F;Main.hx">
8585
</file>
86+
<file name="checkstyle&#x2F;Report.hx">
87+
</file>
8688
<file name="checkstyle&#x2F;reporter&#x2F;IReporter.hx">
8789
</file>
8890
<file name="checkstyle&#x2F;reporter&#x2F;Reporter.hx">

run.n

11.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)