From 3ad43503c55ad585d6471795b1f19236af508d4e Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 14:33:18 +0000 Subject: [PATCH 01/19] base version for excludes --- src/checkstyle/Main.hx | 134 ++++++++++++++++++++++++++++------------- 1 file changed, 92 insertions(+), 42 deletions(-) diff --git a/src/checkstyle/Main.hx b/src/checkstyle/Main.hx index b3711d94..555001dd 100644 --- a/src/checkstyle/Main.hx +++ b/src/checkstyle/Main.hx @@ -17,38 +17,12 @@ import sys.FileSystem; import sys.io.File; using checkstyle.utils.ArrayUtils; +using checkstyle.utils.StringUtils; class Main { - @SuppressWarnings('checkstyle:Dynamic') - public static function main() { - var args; - var cwd; - var oldCwd = null; - - try { - args = Sys.args(); - cwd = Sys.getCwd(); - if (Sys.getEnv("HAXELIB_RUN") != null) { - cwd = args.pop(); - oldCwd = Sys.getCwd(); - } - if (oldCwd != null) Sys.setCwd(cwd); - - new Main().run(args); - } - catch (e:Dynamic) { - Sys.stderr().writeString(e + "\n"); - Sys.stderr().writeString(CallStack.toString(CallStack.exceptionStack()) + "\n"); - } - if (oldCwd != null) Sys.setCwd(oldCwd); - Sys.exit(exitCode); - } - - var info:ChecksInfo; - var checker:Checker; - static var DEFAULT_CONFIG:String = "checkstyle.json"; + static var DEFAULT_EXCLUDE_CONFIG:String = "checkstyle-exclude.json"; static var REPORT_TYPE:String = "text"; static var XML_PATH:String = "check-style-report.xml"; static var JSON_PATH:String = "check-style-report.json"; @@ -58,19 +32,29 @@ class Main { static var EXIT_CODE:Bool = false; static var exitCode:Int; + var info:ChecksInfo; + var checker:Checker; + var paths:Array; + var allExcludes:Array; + var excludesMap:Map>; + function new() { info = new ChecksInfo(); checker = new Checker(); + paths = []; + allExcludes = []; + excludesMap = new Map(); exitCode = 0; } function run(args:Array) { - var files:Array = []; var configPath:String = null; + var excludePath:String = null; var argHandler = Args.generate([ - @doc("Set source folder to process (multiple allowed)") ["-s", "--source"] => function(path:String) traverse(path, files), + @doc("Set source folder to process (multiple allowed)") ["-s", "--source"] => function(path:String) paths.push(path), @doc("Set config file (default: checkstyle.json)") ["-c", "--config"] => function(path:String) configPath = path, + @doc("Set exclude config file (default: checkstyle-exclude.json)") ["-e", "--exclude"] => function(path:String) excludePath = path, @doc("Set reporter (xml, json or text, default: text)") ["-r", "--reporter"] => function(name:String) REPORT_TYPE = name, @doc("Set reporter output path") ["-p", "--path"] => function(path:String) { XML_PATH = path; @@ -93,19 +77,19 @@ class Main { } argHandler.parse(args); - var i:Int = 0; - var toProcess:Array = [for (file in files) {name:file, content:null, index:i++}]; - if (configPath == null && FileSystem.exists(DEFAULT_CONFIG) && !FileSystem.isDirectory(DEFAULT_CONFIG)) { configPath = DEFAULT_CONFIG; } + if (excludePath == null && FileSystem.exists(DEFAULT_EXCLUDE_CONFIG) && !FileSystem.isDirectory(DEFAULT_EXCLUDE_CONFIG)) { + excludePath = DEFAULT_EXCLUDE_CONFIG; + } + if (configPath == null) addAllChecks(); else loadConfig(configPath); - checker.addReporter(createReporter(files.length)); - if (SHOW_PROGRESS) checker.addReporter(new ProgressReporter(files.length)); - if (EXIT_CODE) checker.addReporter(new ExitCodeReporter()); - checker.process(toProcess); + + if (excludePath != null) loadExcludeConfig(excludePath); + else start(); } function loadConfig(configPath:String) { @@ -127,6 +111,32 @@ class Main { } } + function loadExcludeConfig(excludeConfigPath:String) { + var config:Config = Json.parse(File.getContent(excludeConfigPath)); + var excludes = Reflect.fields(config); + for (e in excludes) { + createExcludeMapElement(e); + var excludeValues:Array = Reflect.field(config, e); + if (excludeValues != null && excludeValues.length > 0) { + for (val in excludeValues) { + for (p in paths) { + var path = p + "/" + val.split(".").join("/"); + if (e == "all") allExcludes.push(path); + else { + if (!p.contains(":")) excludesMap.get(e).push(path); + } + } + } + } + } + + start(); + } + + function createExcludeMapElement(name:String) { + if (excludesMap.get(name) == null) excludesMap.set(name, []); + } + function createCheck(checkConf:CheckConfig):Check { var check:Check = info.build(checkConf.type); if (check == null) failWith('Unknown check \'${checkConf.type}\''); @@ -239,12 +249,27 @@ class Main { return s + "/" + t; } - function traverse(node:String, files:Array) { - if (FileSystem.isDirectory(node)) { - var nodes = FileSystem.readDirectory(node); - for (child in nodes) traverse(pathJoin(node, child), files); + function start() { + var files:Array = []; + for (path in paths) traverse(path, files); + + var i:Int = 0; + var toProcess:Array = [for (file in files) {name:file, content:null, index:i++}]; + + checker.addReporter(createReporter(files.length)); + if (SHOW_PROGRESS) checker.addReporter(new ProgressReporter(files.length)); + if (EXIT_CODE) checker.addReporter(new ExitCodeReporter()); + checker.process(toProcess, excludesMap); + } + + function traverse(path:String, files:Array) { + if (FileSystem.isDirectory(path) && !allExcludes.contains(path)) { + var nodes = FileSystem.readDirectory(path); + for (child in nodes) traverse(pathJoin(path, child), files); + } + else if (~/(.hx)$/i.match(path) && !allExcludes.contains(path.substring(0, path.indexOf(".hx")))) { + files.push(path); } - else if (~/(.hx)$/i.match(node)) files.push(node); } function failWith(message:String) { @@ -255,4 +280,29 @@ class Main { public static function setExitCode(newExitCode:Int) { exitCode = newExitCode; } + + @SuppressWarnings("checkstyle:Dynamic") + public static function main() { + var args; + var cwd; + var oldCwd = null; + + try { + args = Sys.args(); + cwd = Sys.getCwd(); + if (Sys.getEnv("HAXELIB_RUN") != null) { + cwd = args.pop(); + oldCwd = Sys.getCwd(); + } + if (oldCwd != null) Sys.setCwd(cwd); + + new Main().run(args); + } + catch (e:Dynamic) { + Sys.stderr().writeString(e + "\n"); + Sys.stderr().writeString(CallStack.toString(CallStack.exceptionStack()) + "\n"); + } + if (oldCwd != null) Sys.setCwd(oldCwd); + Sys.exit(exitCode); + } } \ No newline at end of file From c83e7a0d9d3d6ac39f3915a6df824eb1e0b9af5d Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 14:33:33 +0000 Subject: [PATCH 02/19] fixed tests --- test/checks/CheckTestCase.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/checks/CheckTestCase.hx b/test/checks/CheckTestCase.hx index e2f559a6..bf368ef4 100644 --- a/test/checks/CheckTestCase.hx +++ b/test/checks/CheckTestCase.hx @@ -44,7 +44,7 @@ class CheckTestCase extends haxe.unit.TestCase { if (defines != null) checker.defineCombinations = defines; checker.addCheck(check); checker.addReporter(reporter); - checker.process([{name:FILE_NAME, content:src, index:0}]); + checker.process([{name:FILE_NAME, content:src, index:0}], null); return reporter.message; } From 8f195019842e7c25aad5f8e9ea01c5e0cdc03c69 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 14:33:44 +0000 Subject: [PATCH 03/19] sample config --- resources/checkstyle-exclude.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 resources/checkstyle-exclude.json diff --git a/resources/checkstyle-exclude.json b/resources/checkstyle-exclude.json new file mode 100644 index 00000000..2c2020f4 --- /dev/null +++ b/resources/checkstyle-exclude.json @@ -0,0 +1,11 @@ +{ + "all": [ + "checkstyle.utils", "checkstyle.reporter.IReporter" + ], + "Dynamic": [ + "checkstyle.Main", "checkstyle.Checker" + ], + "CyclomaticComplexity": [ + "checkstyle.utils.ExprUtils:walkExpr" + ] +} \ No newline at end of file From fbea9f33d76cf91f0c492cb3a05296c5fcd232e5 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 14:55:37 +0000 Subject: [PATCH 04/19] implemented check exclusion at class level --- src/checkstyle/Checker.hx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/checkstyle/Checker.hx b/src/checkstyle/Checker.hx index e72c2d37..a63e3f1e 100644 --- a/src/checkstyle/Checker.hx +++ b/src/checkstyle/Checker.hx @@ -12,6 +12,8 @@ import sys.io.File; import checkstyle.token.TokenTree; import checkstyle.token.TokenTreeBuilder; +using checkstyle.utils.ArrayUtils; + class Checker { public var file:LintFile; @@ -27,6 +29,7 @@ class Checker { var lineSeparator:String; var tokenTree:TokenTree; var asts:Array; + var excludes:Map>; public function new() { checks = []; @@ -135,7 +138,8 @@ class Checker { return parser.parse(); } - public function process(files:Array) { + public function process(files:Array, excludesMap:Map>) { + excludes = excludesMap; var advanceFrame = function() {}; #if hxtelemetry var hxt = new hxtelemetry.HxTelemetry(); @@ -235,9 +239,9 @@ class Checker { message1.moduleName == message2.moduleName; } - @SuppressWarnings("checkstyle:Dynamic") function runCheck(check:Check):Array { try { + if (checkForExclude(check.getModuleName())) return []; return check.run(this); } catch (e:Dynamic) { @@ -246,7 +250,13 @@ class Checker { } } - @SuppressWarnings("checkstyle:Dynamic") + function checkForExclude(moduleName:String):Bool { + if (excludes == null) return false; + var excludesForCheck:Array = excludes.get(moduleName); + if (excludesForCheck == null || excludesForCheck.length == 0) return false; + return excludesForCheck.contains(file.name.substring(0, file.name.indexOf(".hx"))); + } + function getErrorMessage(e:Dynamic, fileName:String, step:String):LintMessage { return { fileName:fileName, From c43ae581570091aa724a68f643523de193224d31 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 15:50:48 +0000 Subject: [PATCH 05/19] removed all suppressions in tests --- test/checks/coding/HiddenFieldCheckTest.hx | 1 - test/checks/coding/MagicNumberCheckTest.hx | 1 - test/checks/size/FileLengthCheckTest.hx | 1 - test/checks/size/LineLengthCheckTest.hx | 1 - test/checks/size/ParameterNumberCheckTest.hx | 1 - 5 files changed, 5 deletions(-) diff --git a/test/checks/coding/HiddenFieldCheckTest.hx b/test/checks/coding/HiddenFieldCheckTest.hx index 1ac2e919..9c4564cc 100644 --- a/test/checks/coding/HiddenFieldCheckTest.hx +++ b/test/checks/coding/HiddenFieldCheckTest.hx @@ -2,7 +2,6 @@ package checks.coding; import checkstyle.checks.coding.HiddenFieldCheck; -@SuppressWarnings('checkstyle:MultipleStringLiterals') class HiddenFieldCheckTest extends CheckTestCase { public function testCorrectHidden() { diff --git a/test/checks/coding/MagicNumberCheckTest.hx b/test/checks/coding/MagicNumberCheckTest.hx index ef309440..6744e3cb 100644 --- a/test/checks/coding/MagicNumberCheckTest.hx +++ b/test/checks/coding/MagicNumberCheckTest.hx @@ -19,7 +19,6 @@ class MagicNumberCheckTest extends CheckTestCase { assertMsg(check, INT_NUMBER_FUNCTION, 'Magic number "10" detected - consider using a constant'); } - @SuppressWarnings('checkstyle:MagicNumber') public function testIgnoreNumbers() { var check = new MagicNumberCheck(); check.ignoreNumbers = [-1, 0, 2]; diff --git a/test/checks/size/FileLengthCheckTest.hx b/test/checks/size/FileLengthCheckTest.hx index 95f0f128..24479082 100644 --- a/test/checks/size/FileLengthCheckTest.hx +++ b/test/checks/size/FileLengthCheckTest.hx @@ -2,7 +2,6 @@ package checks.size; import checkstyle.checks.size.FileLengthCheck; -@SuppressWarnings('checkstyle:MagicNumber') class FileLengthCheckTest extends CheckTestCase { public function testCorrectLineCount() { diff --git a/test/checks/size/LineLengthCheckTest.hx b/test/checks/size/LineLengthCheckTest.hx index 36c9ae12..64678c44 100644 --- a/test/checks/size/LineLengthCheckTest.hx +++ b/test/checks/size/LineLengthCheckTest.hx @@ -12,7 +12,6 @@ class LineLengthCheckTest extends CheckTestCase { assertNoMsg(new LineLengthCheck(), TEST2); } - @SuppressWarnings('checkstyle:MagicNumber') public function testConfigurableLineLength() { var check = new LineLengthCheck(); check.max = 40; diff --git a/test/checks/size/ParameterNumberCheckTest.hx b/test/checks/size/ParameterNumberCheckTest.hx index 9581750d..d86b6fd3 100644 --- a/test/checks/size/ParameterNumberCheckTest.hx +++ b/test/checks/size/ParameterNumberCheckTest.hx @@ -19,7 +19,6 @@ class ParameterNumberCheckTest extends CheckTestCase assertMsg(check, TEST3, 'Too many parameters for function: test2 (> 7)'); } - @SuppressWarnings('checkstyle:MagicNumber') public function testMaxParameter() { var check = new ParameterNumberCheck(); check.max = 11; From 75be79305d4a8b3a9e770c7086812bcdb5774539 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 15:50:57 +0000 Subject: [PATCH 06/19] removed suppression --- src/checkstyle/Main.hx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/checkstyle/Main.hx b/src/checkstyle/Main.hx index 555001dd..90a0d6ad 100644 --- a/src/checkstyle/Main.hx +++ b/src/checkstyle/Main.hx @@ -281,7 +281,6 @@ class Main { exitCode = newExitCode; } - @SuppressWarnings("checkstyle:Dynamic") public static function main() { var args; var cwd; From de0afa1083aafafc113c08bf360b1fd453c69c59 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 16:08:21 +0000 Subject: [PATCH 07/19] fixed issues in test --- .../coding/MultipleVariableDeclarationsCheckTest.hx | 9 ++++----- test/checks/naming/MethodNameCheckTest.hx | 11 +++++------ test/checks/naming/TypeNameCheckTest.hx | 3 +-- test/checks/whitespace/TabForAligningCheckTest.hx | 2 +- test/checks/whitespace/WhitespaceAroundCheckTest.hx | 2 +- test/token/TokenTreeBuilderTest.hx | 1 + 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/test/checks/coding/MultipleVariableDeclarationsCheckTest.hx b/test/checks/coding/MultipleVariableDeclarationsCheckTest.hx index 9cab03ed..d46b3e4e 100644 --- a/test/checks/coding/MultipleVariableDeclarationsCheckTest.hx +++ b/test/checks/coding/MultipleVariableDeclarationsCheckTest.hx @@ -43,8 +43,7 @@ abstract MultipleVariableDeclarationsCheckTests(String) to String { function a() { var d = 10; var e; var d;var e; - var d; var e; - var d; var e; + var f; var g; } }"; @@ -58,8 +57,8 @@ abstract MultipleVariableDeclarationsCheckTests(String) to String { var TEST5 = " abstractAndClass Test { - function foo() { - var s = 'var f'; - } + function foo() { + var s = 'var f'; + } }"; } \ No newline at end of file diff --git a/test/checks/naming/MethodNameCheckTest.hx b/test/checks/naming/MethodNameCheckTest.hx index c7388611..c35e90c2 100644 --- a/test/checks/naming/MethodNameCheckTest.hx +++ b/test/checks/naming/MethodNameCheckTest.hx @@ -2,7 +2,6 @@ package checks.naming; import checkstyle.checks.naming.MethodNameCheck; -// TODO abstract tests class MethodNameCheckTest extends CheckTestCase { public function testCorrectNaming() { @@ -122,7 +121,7 @@ class MethodNameCheckTest extends CheckTestCase { @:enum abstract MethodNameCheckTests(String) to String { var TEST = " - class Test { + abstractAndClass Test { function test() {} function testName() {} public function testValue() {} @@ -132,21 +131,21 @@ abstract MethodNameCheckTests(String) to String { @SuppressWarnings('checkstyle:MethodName') function TEST2() {} } - + typedef Test3 = { function test() {}; function testName() {}; }"; var TEST1 = " - class Test { + abstractAndClass Test { static public function Test() {} public function Test2() {} static inline public function Test3() {} }"; var TEST2 = " - class Test { + abstractAndClass Test { static public function Test() {} static inline public function Test1() {} public function Test2() {} @@ -164,7 +163,7 @@ abstract MethodNameCheckTests(String) to String { }"; var TEST5 = " - class Test { + abstractAndClass Test { static function Test() {} static inline function Test1() {} function Test3() {} diff --git a/test/checks/naming/TypeNameCheckTest.hx b/test/checks/naming/TypeNameCheckTest.hx index 1370a007..6ebd6447 100644 --- a/test/checks/naming/TypeNameCheckTest.hx +++ b/test/checks/naming/TypeNameCheckTest.hx @@ -2,7 +2,6 @@ package checks.naming; import checkstyle.checks.naming.TypeNameCheck; -// TODO abstract tests class TypeNameCheckTest extends CheckTestCase { static inline var FORMAT_CLASS:String = "^C[A-Z][a-z]*$"; @@ -119,7 +118,7 @@ abstract TypeNameCheckTests(String) to String { }"; var TEST1 = " - class CTest { + abstractAndClass CTest { }"; var TEST2 = " diff --git a/test/checks/whitespace/TabForAligningCheckTest.hx b/test/checks/whitespace/TabForAligningCheckTest.hx index e2331fae..d4b31082 100644 --- a/test/checks/whitespace/TabForAligningCheckTest.hx +++ b/test/checks/whitespace/TabForAligningCheckTest.hx @@ -5,7 +5,7 @@ import checkstyle.checks.whitespace.TabForAligningCheck; class TabForAligningCheckTest extends CheckTestCase { public function testTab() { - assertMsg(new TabForAligningCheck(), TEST1, 'Tab after non-space character. Use space for aligning'); + assertMsg(new TabForAligningCheck(), TEST1, 'Tab after non-space character, Use space for aligning'); } public function testMultiline() { diff --git a/test/checks/whitespace/WhitespaceAroundCheckTest.hx b/test/checks/whitespace/WhitespaceAroundCheckTest.hx index 5e9c8200..76cb56e3 100644 --- a/test/checks/whitespace/WhitespaceAroundCheckTest.hx +++ b/test/checks/whitespace/WhitespaceAroundCheckTest.hx @@ -162,7 +162,7 @@ abstract WhitespaceAroundCheckTests(String) to String { class Test { function test() { if (re.match(line) && line.indexOf('//') == -1) { - log('Tab after non-space character. Use space for aligning', i + 1, line.length, null, Reflect.field(SeverityLevel, severity)); + log('Tab after non-space character, Use space for aligning', i + 1, line.length, null, Reflect.field(SeverityLevel, severity)); return -1; } a = 1 - -2; diff --git a/test/token/TokenTreeBuilderTest.hx b/test/token/TokenTreeBuilderTest.hx index 1be08ae6..2002e54b 100644 --- a/test/token/TokenTreeBuilderTest.hx +++ b/test/token/TokenTreeBuilderTest.hx @@ -91,6 +91,7 @@ class TokenTreeBuilderTest extends haxe.unit.TestCase { abstract TokenTreeBuilderTests(String) to String { var IMPORT = " package checkstyle.checks; + import haxeparser.*; import checkstyle.TokenTree; import checkstyle.TokenStream; From eb0ca52c888b18cb88dea334cfce3c41375e64b5 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 16:08:30 +0000 Subject: [PATCH 08/19] updated message --- src/checkstyle/checks/whitespace/TabForAligningCheck.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/checkstyle/checks/whitespace/TabForAligningCheck.hx b/src/checkstyle/checks/whitespace/TabForAligningCheck.hx index 8e1dc6eb..0832fe0c 100644 --- a/src/checkstyle/checks/whitespace/TabForAligningCheck.hx +++ b/src/checkstyle/checks/whitespace/TabForAligningCheck.hx @@ -15,7 +15,7 @@ class TabForAligningCheck extends Check { for (i in 0 ... checker.lines.length) { var line = checker.lines[i]; if (re.match(line) && !line.contains("//")) { - log("Tab after non-space character. Use space for aligning", i + 1, line.length); + log("Tab after non-space character, Use space for aligning", i + 1, line.length); } } } From b9a0043b30a9b5386aaa46caa65c680c500850c0 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 16:08:40 +0000 Subject: [PATCH 09/19] removed SuppressWarnings --- src/checkstyle/ChecksInfo.hx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/checkstyle/ChecksInfo.hx b/src/checkstyle/ChecksInfo.hx index e26b04fb..89368717 100644 --- a/src/checkstyle/ChecksInfo.hx +++ b/src/checkstyle/ChecksInfo.hx @@ -2,7 +2,6 @@ package checkstyle; import checkstyle.checks.Check; -@SuppressWarnings("checkstyle:Dynamic") class ChecksInfo { var checkInfos:Map; From b306dfbc8d8be758b1aa761b0d48ba4559666d80 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 16:09:05 +0000 Subject: [PATCH 10/19] added test and exclude json file --- build.hxml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.hxml b/build.hxml index 621aa11a..819ef2c2 100644 --- a/build.hxml +++ b/build.hxml @@ -13,6 +13,6 @@ -x TestMain --next --cmd neko run -s src -p resources/static-analysis.txt -c resources/checkstyle.json +-cmd neko run -s src -p resources/static-analysis.txt -c resources/checkstyle.json -e resources/checkstyle-exclude.json -cmd neko run --default-config resources/default-config.json -cmd neko run -c resources/default-config.json \ No newline at end of file From e31b9e74d0d55ff30acef67c11b39d2d236e5d02 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 16:09:30 +0000 Subject: [PATCH 11/19] updated to exclude classes as well --- src/checkstyle/Checker.hx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/checkstyle/Checker.hx b/src/checkstyle/Checker.hx index a63e3f1e..c31a3cd5 100644 --- a/src/checkstyle/Checker.hx +++ b/src/checkstyle/Checker.hx @@ -13,6 +13,7 @@ import checkstyle.token.TokenTree; import checkstyle.token.TokenTreeBuilder; using checkstyle.utils.ArrayUtils; +using StringTools; class Checker { @@ -170,7 +171,6 @@ class Checker { lintFile.content = null; } - @SuppressWarnings("checkstyle:Dynamic") function createContext(lintFile:LintFile):Bool { this.file = lintFile; for (reporter in reporters) reporter.fileStart(file); @@ -254,7 +254,17 @@ class Checker { if (excludes == null) return false; var excludesForCheck:Array = excludes.get(moduleName); if (excludesForCheck == null || excludesForCheck.length == 0) return false; - return excludesForCheck.contains(file.name.substring(0, file.name.indexOf(".hx"))); + + var cls = file.name.substring(0, file.name.indexOf(".hx")); + if (excludesForCheck.contains(cls)) return true; + + cls = cls.replace("/", ":"); + for (exclude in excludesForCheck) { + var regStr:String = exclude + ":.*?" + cls.substring(cls.lastIndexOf(":") + 1, cls.length) + "$"; + var r = new EReg(regStr.replace("/", ":"), "i"); + if (r.match(cls)) return true; + } + return false; } function getErrorMessage(e:Dynamic, fileName:String, step:String):LintMessage { From 0ab7156aed7e0b65ad235e752ceffe454c843893 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 16:09:46 +0000 Subject: [PATCH 12/19] added excludes for tests --- resources/checkstyle-exclude.json | 35 ++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/resources/checkstyle-exclude.json b/resources/checkstyle-exclude.json index 2c2020f4..7b3c4999 100644 --- a/resources/checkstyle-exclude.json +++ b/resources/checkstyle-exclude.json @@ -1,11 +1,36 @@ { - "all": [ - "checkstyle.utils", "checkstyle.reporter.IReporter" - ], + "all": [], "Dynamic": [ - "checkstyle.Main", "checkstyle.Checker" + "checkstyle.Main", + "checkstyle.Checker", + "checkstyle.ChecksInfo" + ], + "EmptyLines": [ + "checks" + ], + "MultipleStringLiterals": [ + "checks", + "token" + ], + "MultipleVariableDeclarations": [ + "checks.coding.MultipleVariableDeclarationsCheckTest" + ], + "TrailingWhitespace": [ + "checks.whitespace.SpacingCheckTest", + "checks.whitespace.TrailingWhitespaceCheckTest", + "checks.naming.MemberNameCheckTest" + ], + "TabForAligning": [ + "checks.whitespace.IndentationCharacterCheckTest", + "checks.whitespace.TabForAligningCheckTest" + ], + "LineLength": [ + "checks.size.LineLengthCheckTest" + ], + "IndentationCharacter": [ + "checks.whitespace.IndentationCharacterCheckTest" ], "CyclomaticComplexity": [ - "checkstyle.utils.ExprUtils:walkExpr" + "checkstyle.utils.ExprUtils" ] } \ No newline at end of file From 0404d95f49eb8ac4a3c3929ec63153d6b0cecfa9 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 16:19:50 +0000 Subject: [PATCH 13/19] removed @SuppressWarnings --- src/checkstyle/reporter/ProgressReporter.hx | 1 - src/checkstyle/token/TokenTreeBuilder.hx | 2 -- src/checkstyle/utils/ComplexTypeUtils.hx | 1 - src/checkstyle/utils/ExprUtils.hx | 1 - 4 files changed, 5 deletions(-) diff --git a/src/checkstyle/reporter/ProgressReporter.hx b/src/checkstyle/reporter/ProgressReporter.hx index c334fba9..a6292d4c 100644 --- a/src/checkstyle/reporter/ProgressReporter.hx +++ b/src/checkstyle/reporter/ProgressReporter.hx @@ -15,7 +15,6 @@ class ProgressReporter implements IReporter { clear(); } - @SuppressWarnings("checkstyle:MagicNumber") public function fileStart(f:LintFile) { clear(); var percentage = Math.floor((f.index + 1) / numFiles * 100); diff --git a/src/checkstyle/token/TokenTreeBuilder.hx b/src/checkstyle/token/TokenTreeBuilder.hx index 0eac9ebf..29983a63 100644 --- a/src/checkstyle/token/TokenTreeBuilder.hx +++ b/src/checkstyle/token/TokenTreeBuilder.hx @@ -1,7 +1,6 @@ package checkstyle.token; import haxe.macro.Expr; - import haxeparser.Data.Token; import haxeparser.Data.TokenDef; @@ -539,7 +538,6 @@ class TokenTreeBuilder { } } - @SuppressWarnings(["checkstyle:MethodLength", "checkstyle:CyclomaticComplexity"]) function walkIdentifier(parent:TokenTree) { switch (stream.token()) { case Binop(OpSub): diff --git a/src/checkstyle/utils/ComplexTypeUtils.hx b/src/checkstyle/utils/ComplexTypeUtils.hx index 418c9dad..4b972dd1 100644 --- a/src/checkstyle/utils/ComplexTypeUtils.hx +++ b/src/checkstyle/utils/ComplexTypeUtils.hx @@ -154,7 +154,6 @@ class ComplexTypeUtils { } } - @SuppressWarnings('checkstyle:CyclomaticComplexity') public static function walkExpr(e:Expr, cb:ComplexTypeCallback) { switch (e.expr){ case EConst(c): diff --git a/src/checkstyle/utils/ExprUtils.hx b/src/checkstyle/utils/ExprUtils.hx index 12ac00d4..277552ed 100644 --- a/src/checkstyle/utils/ExprUtils.hx +++ b/src/checkstyle/utils/ExprUtils.hx @@ -153,7 +153,6 @@ class ExprUtils { } } - @SuppressWarnings('checkstyle:CyclomaticComplexity') public static function walkExpr(e:Expr, cb:Expr -> Void) { cb(e); switch (e.expr){ From 61291ce87cec2ef0cd20f8bbfd00a9e0b16da361 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 16:20:07 +0000 Subject: [PATCH 14/19] removed @SuppressWarnings --- src/checkstyle/checks/CyclomaticComplexityCheck.hx | 1 - src/checkstyle/checks/naming/MethodNameCheck.hx | 1 - src/checkstyle/checks/type/ReturnCheck.hx | 1 - 3 files changed, 3 deletions(-) diff --git a/src/checkstyle/checks/CyclomaticComplexityCheck.hx b/src/checkstyle/checks/CyclomaticComplexityCheck.hx index a636d115..c95f8fcb 100644 --- a/src/checkstyle/checks/CyclomaticComplexityCheck.hx +++ b/src/checkstyle/checks/CyclomaticComplexityCheck.hx @@ -6,7 +6,6 @@ using Lambda; @name("CyclomaticComplexity") @desc("McCabe simplified cyclomatic complexity check") -@SuppressWarnings(['checkstyle:CyclomaticComplexity', 'checkstyle:LeftCurly', 'checkstyle:RightCurly']) class CyclomaticComplexityCheck extends Check { static var DEFAULT_COMPLEXITY_WARNING:Int = 20; diff --git a/src/checkstyle/checks/naming/MethodNameCheck.hx b/src/checkstyle/checks/naming/MethodNameCheck.hx index b66370ff..47c462ef 100644 --- a/src/checkstyle/checks/naming/MethodNameCheck.hx +++ b/src/checkstyle/checks/naming/MethodNameCheck.hx @@ -47,7 +47,6 @@ class MethodNameCheck extends NameCheckBase { } } - @SuppressWarnings('checkstyle:CyclomaticComplexity') function checkField(f:Field, p:ParentType) { if (f.isGetter() || f.isSetter()) return; if (hasToken(NOTINLINE) && !hasToken(INLINE) && f.isInline(p)) return; diff --git a/src/checkstyle/checks/type/ReturnCheck.hx b/src/checkstyle/checks/type/ReturnCheck.hx index aef4f745..03855e61 100644 --- a/src/checkstyle/checks/type/ReturnCheck.hx +++ b/src/checkstyle/checks/type/ReturnCheck.hx @@ -61,7 +61,6 @@ class ReturnCheck extends Check { }); } - @SuppressWarnings("checkstyle:CyclomaticComplexity") function walkExpr(e:Expr, noReturn:Bool, name:String, pos:Position) { if ((e == null) || (e.expr == null)) { return; From c2cba3e8e58916962b9054329c72024b00b65f70 Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 16:20:28 +0000 Subject: [PATCH 15/19] removed @SuppressWarnings --- src/checkstyle/checks/Check.hx | 1 - src/checkstyle/checks/block/LeftCurlyCheck.hx | 2 -- src/checkstyle/checks/block/RightCurlyCheck.hx | 1 - 3 files changed, 4 deletions(-) diff --git a/src/checkstyle/checks/Check.hx b/src/checkstyle/checks/Check.hx index 7239bcf4..7fa4c346 100644 --- a/src/checkstyle/checks/Check.hx +++ b/src/checkstyle/checks/Check.hx @@ -120,7 +120,6 @@ class Check { return isCharPosSuppressed(pos.min); } - @SuppressWarnings('checkstyle:CyclomaticComplexity') function isCharPosSuppressed(pos:Int):Bool { for (td in checker.ast.decls) { switch (td.decl){ diff --git a/src/checkstyle/checks/block/LeftCurlyCheck.hx b/src/checkstyle/checks/block/LeftCurlyCheck.hx index 273caf70..3baf1c2e 100644 --- a/src/checkstyle/checks/block/LeftCurlyCheck.hx +++ b/src/checkstyle/checks/block/LeftCurlyCheck.hx @@ -61,8 +61,6 @@ class LeftCurlyCheck extends Check { /** * find effective parent token and check against configured tokens */ - - @SuppressWarnings("checkstyle:CyclomaticComplexity") function findParentToken(token:TokenTree):ParentToken { if (token == null) return {token:token, hasToken: false}; switch (token.tok) { diff --git a/src/checkstyle/checks/block/RightCurlyCheck.hx b/src/checkstyle/checks/block/RightCurlyCheck.hx index fdf69420..653c70d1 100644 --- a/src/checkstyle/checks/block/RightCurlyCheck.hx +++ b/src/checkstyle/checks/block/RightCurlyCheck.hx @@ -50,7 +50,6 @@ class RightCurlyCheck extends Check { } } - @SuppressWarnings("checkstyle:CyclomaticComplexity") function filterParentToken(token:TokenTree):Bool { if (token == null) return false; switch (token.tok) { From ec9d698d93dfde868712a2a93eb40a59bf8f84ef Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 16:25:32 +0000 Subject: [PATCH 16/19] removed all @SuppressWarnings in the actual code --- .../checks/coding/MultipleVariableDeclarationsCheck.hx | 1 - src/checkstyle/checks/whitespace/OperatorWrapCheck.hx | 1 - src/checkstyle/checks/whitespace/WhitespaceAfterCheck.hx | 1 - src/checkstyle/checks/whitespace/WhitespaceAroundCheck.hx | 1 - 4 files changed, 4 deletions(-) diff --git a/src/checkstyle/checks/coding/MultipleVariableDeclarationsCheck.hx b/src/checkstyle/checks/coding/MultipleVariableDeclarationsCheck.hx index c783edc9..903b1f67 100644 --- a/src/checkstyle/checks/coding/MultipleVariableDeclarationsCheck.hx +++ b/src/checkstyle/checks/coding/MultipleVariableDeclarationsCheck.hx @@ -11,7 +11,6 @@ class MultipleVariableDeclarationsCheck extends Check { super(TOKEN); } - @SuppressWarnings('checkstyle:MultipleVariableDeclarations') override function actualRun() { var root:TokenTree = checker.getTokenTree(); var acceptableTokens:Array = root.filter([Kwd(KwdVar)], ALL); diff --git a/src/checkstyle/checks/whitespace/OperatorWrapCheck.hx b/src/checkstyle/checks/whitespace/OperatorWrapCheck.hx index 5771bcde..22edeb39 100644 --- a/src/checkstyle/checks/whitespace/OperatorWrapCheck.hx +++ b/src/checkstyle/checks/whitespace/OperatorWrapCheck.hx @@ -49,7 +49,6 @@ class OperatorWrapCheck extends WrapCheckBase { ]; } - @SuppressWarnings("checkstyle:CyclomaticComplexity") override function actualRun() { var tokenList:Array = []; diff --git a/src/checkstyle/checks/whitespace/WhitespaceAfterCheck.hx b/src/checkstyle/checks/whitespace/WhitespaceAfterCheck.hx index 9ef8f4c5..46636048 100644 --- a/src/checkstyle/checks/whitespace/WhitespaceAfterCheck.hx +++ b/src/checkstyle/checks/whitespace/WhitespaceAfterCheck.hx @@ -25,7 +25,6 @@ class WhitespaceAfterCheck extends Check { return (tokens.length == 0 || tokens.contains(token)); } - @SuppressWarnings(["checkstyle:CyclomaticComplexity", "checkstyle:MethodLength"]) override function actualRun() { var tokenList:Array = []; diff --git a/src/checkstyle/checks/whitespace/WhitespaceAroundCheck.hx b/src/checkstyle/checks/whitespace/WhitespaceAroundCheck.hx index 3329dc8a..fc01e614 100644 --- a/src/checkstyle/checks/whitespace/WhitespaceAroundCheck.hx +++ b/src/checkstyle/checks/whitespace/WhitespaceAroundCheck.hx @@ -56,7 +56,6 @@ class WhitespaceAroundCheck extends Check { return (tokens.length == 0 || tokens.contains(token)); } - @SuppressWarnings(["checkstyle:CyclomaticComplexity", "checkstyle:MethodLength"]) override function actualRun() { var tokenList:Array = []; From 56d937d59b93d47dedeed50b6257df858ef94d6e Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 16:25:55 +0000 Subject: [PATCH 17/19] added all the classes needed to exclude list --- resources/checkstyle-exclude.json | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/resources/checkstyle-exclude.json b/resources/checkstyle-exclude.json index 7b3c4999..9a364bc8 100644 --- a/resources/checkstyle-exclude.json +++ b/resources/checkstyle-exclude.json @@ -31,6 +31,34 @@ "checks.whitespace.IndentationCharacterCheckTest" ], "CyclomaticComplexity": [ - "checkstyle.utils.ExprUtils" + "checkstyle.checks.Check", + "checkstyle.utils.ExprUtils", + "checkstyle.utils.ComplexTypeUtils", + "checkstyle.checks.CyclomaticComplexityCheck", + "checkstyle.checks.block.LeftCurlyCheck", + "checkstyle.checks.block.RightCurlyCheck", + "checkstyle.checks.naming.MethodNameCheck", + "checkstyle.checks.type.ReturnCheck", + "checkstyle.checks.whitespace.OperatorWrapCheck", + "checkstyle.checks.whitespace.WhitespaceAfterCheck", + "checkstyle.checks.whitespace.WhitespaceAroundCheck", + "checkstyle.token.TokenTreeBuilder" + ], + "LeftCurly": [ + "checkstyle.checks.CyclomaticComplexityCheck" + ], + "RightCurly": [ + "checkstyle.checks.CyclomaticComplexityCheck" + ], + "MethodLength": [ + "checkstyle.checks.whitespace.WhitespaceAfterCheck", + "checkstyle.checks.whitespace.WhitespaceAroundCheck", + "checkstyle.token.TokenTreeBuilder" + ], + "MagicNumber": [ + "checkstyle.reporter.ProgressReporter" + ], + "MultipleVariableDeclarations": [ + "checkstyle.checks.coding.MultipleVariableDeclarationsCheck" ] } \ No newline at end of file From 55e044fc745885b1b81a616bd4db5eaec76a9c2f Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 16:31:54 +0000 Subject: [PATCH 18/19] removed duplicates --- resources/checkstyle-exclude.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/resources/checkstyle-exclude.json b/resources/checkstyle-exclude.json index 9a364bc8..225f7811 100644 --- a/resources/checkstyle-exclude.json +++ b/resources/checkstyle-exclude.json @@ -13,6 +13,7 @@ "token" ], "MultipleVariableDeclarations": [ + "checkstyle.checks.coding.MultipleVariableDeclarationsCheck", "checks.coding.MultipleVariableDeclarationsCheckTest" ], "TrailingWhitespace": [ @@ -57,8 +58,5 @@ ], "MagicNumber": [ "checkstyle.reporter.ProgressReporter" - ], - "MultipleVariableDeclarations": [ - "checkstyle.checks.coding.MultipleVariableDeclarationsCheck" ] } \ No newline at end of file From bc7a5416b791560d990b200df24a94f283b295eb Mon Sep 17 00:00:00 2001 From: Adi Date: Wed, 9 Mar 2016 16:32:02 +0000 Subject: [PATCH 19/19] included test --- build.hxml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.hxml b/build.hxml index 819ef2c2..0a861ba5 100644 --- a/build.hxml +++ b/build.hxml @@ -13,6 +13,6 @@ -x TestMain --next --cmd neko run -s src -p resources/static-analysis.txt -c resources/checkstyle.json -e resources/checkstyle-exclude.json +-cmd neko run -s src -s test -p resources/static-analysis.txt -c resources/checkstyle.json -e resources/checkstyle-exclude.json -cmd neko run --default-config resources/default-config.json -cmd neko run -c resources/default-config.json \ No newline at end of file