Skip to content

Commit

Permalink
Merge pull request #220 from HaxeCheckstyle/info
Browse files Browse the repository at this point in the history
Info
  • Loading branch information
adireddy committed Mar 28, 2016
2 parents 3aac97f + 69f1dd2 commit 285b58c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 29 deletions.
7 changes: 0 additions & 7 deletions checkstyle.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,6 @@
},
"type": "Return"
},
{
"props": {
"max": 2,
"severity": "IGNORE"
},
"type": "ReturnCount"
},
{
"props": {
"tokens": [
Expand Down
28 changes: 14 additions & 14 deletions src/checkstyle/Checker.hx
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ class Checker {
}
}
catch (e:Dynamic) {
#if debug
#if debug
Lib.println(e);
Lib.println("Stacktrace: " + CallStack.toString(CallStack.exceptionStack()));
#end
#end
}
}

Expand All @@ -155,10 +155,10 @@ class Checker {
return parser.parse();
}
catch (e:Dynamic) {
#if debug
#if debug
Lib.println(e);
Lib.println("Stacktrace: " + CallStack.toString(CallStack.exceptionStack()));
#end
#end
}
return null;
}
Expand All @@ -172,29 +172,29 @@ class Checker {
#end

for (reporter in reporters) reporter.start();
for (lintFile in files) {
loadFileContent(lintFile);
if (createContext(lintFile)) run();
unloadFileContent(lintFile);
for (checkFile in files) {
loadFileContent(checkFile);
if (createContext(checkFile)) run();
unloadFileContent(checkFile);
advanceFrame();
}
advanceFrame();
for (reporter in reporters) reporter.finish();
advanceFrame();
}

function loadFileContent(lintFile:CheckFile) {
function loadFileContent(checkFile:CheckFile) {
// unittests set content before running Checker
// real checks load content here
if (lintFile.content == null) lintFile.content = File.getContent(lintFile.name);
if (checkFile.content == null) checkFile.content = File.getContent(checkFile.name);
}

function unloadFileContent(lintFile:CheckFile) {
lintFile.content = null;
function unloadFileContent(checkFile:CheckFile) {
checkFile.content = null;
}

function createContext(lintFile:CheckFile):Bool {
this.file = lintFile;
function createContext(checkFile:CheckFile):Bool {
file = checkFile;
for (reporter in reporters) reporter.fileStart(file);
try {
findLineSeparator();
Expand Down
19 changes: 15 additions & 4 deletions src/checkstyle/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,23 @@ class Main {
Sys.exit(0);
}

function getCheckCount():Int {
var count = 0;
for (check in info.checks()) {
if (~/\[DEPRECATED/.match(check.description)) continue;
count++;
}
return count;
}

function createReporter(numFiles:Int):IReporter {
var totalChecks = getCheckCount();
var checksUsed = checker.checks.length;
return switch (REPORT_TYPE) {
case "xml": new XMLReporter(numFiles, XML_PATH, STYLE, NO_STYLE);
case "json": new JSONReporter(numFiles, JSON_PATH, NO_STYLE);
case "text": new TextReporter(numFiles, TEXT_PATH, NO_STYLE);
case "codeclimate": new CodeClimateReporter(numFiles, null, NO_STYLE);
case "xml": new XMLReporter(numFiles, totalChecks, checksUsed, XML_PATH, STYLE, NO_STYLE);
case "json": new JSONReporter(numFiles, totalChecks, checksUsed, JSON_PATH, NO_STYLE);
case "text": new TextReporter(numFiles, totalChecks, checksUsed, TEXT_PATH, NO_STYLE);
case "codeclimate": new CodeClimateReporter(numFiles, totalChecks, checksUsed, null, NO_STYLE);
default: failWith('Unknown reporter: $REPORT_TYPE'); null;
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/checkstyle/reporter/BaseReporter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ class BaseReporter implements IReporter {
var report:StringBuf;
var file:FileOutput;
var numFiles:Int;
var numChecks:Int;
var numUsedChecks:Int;
var noStyle:Bool;

public function new(fileCount:Int, path:String, ns:Bool) {
public function new(fileCount:Int, checkCount:Int, usedCheckCount:Int, path:String, ns:Bool) {
numFiles = fileCount;
numChecks = checkCount;
numUsedChecks = usedCheckCount;
noStyle = ns;
if (path != null) {
var folder = Path.directory(path);
Expand All @@ -34,8 +38,11 @@ class BaseReporter implements IReporter {
warnings = 0;
infos = 0;
total = 0;

var version = CompileTime.parseJsonFile("package.json").version;

Sys.println("");
Sys.println(styleText("Running Checkstyle v" + CompileTime.parseJsonFile("package.json").version + ' on $numFiles source files...', Style.BOLD));
Sys.println(styleText('Running Checkstyle v$version using $numUsedChecks/$numChecks checks on $numFiles source files...', Style.BOLD));
Sys.println("");
}

Expand Down
4 changes: 2 additions & 2 deletions src/checkstyle/reporter/XMLReporter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class XMLReporter extends BaseReporter {

static var ENTITY_RE:EReg = ~/[&<>"'\/]/g;

public function new(numFiles:Int, path:String, s:String, ns:Bool) {
super(numFiles, path, ns);
public function new(numFiles:Int, checkCount:Int, usedCheckCount:Int, path:String, s:String, ns:Bool) {
super(numFiles, checkCount, usedCheckCount, path, ns);
style = s;
}

Expand Down

0 comments on commit 285b58c

Please sign in to comment.