diff --git a/checkstyle.json b/checkstyle.json index a301cd38..a0f96d1a 100644 --- a/checkstyle.json +++ b/checkstyle.json @@ -517,6 +517,9 @@ "checkstyle.Main", "checkstyle.Checker", "checkstyle.ChecksInfo", + "checkstyle.checks.Check", + "checkstyle.checks.Directive", + "checkstyle.checks.whitespace.SpacingCheck", "checkstyle.checks.imports.UnusedImportCheck", "TestMain", "misc.ExtensionsTest", diff --git a/resources/default-config.json b/resources/default-config.json index 16f93b5d..1fd29050 100644 --- a/resources/default-config.json +++ b/resources/default-config.json @@ -442,13 +442,13 @@ }, { "props": { - "spaceIfCondition": "should", + "spaceIfCondition": 0, "spaceAroundBinop": true, - "spaceForLoop": "should", + "spaceForLoop": 0, "ignoreRangeOperator": true, - "spaceWhileLoop": "should", - "spaceCatch": "should", - "spaceSwitchCase": "should", + "spaceWhileLoop": 0, + "spaceCatch": 0, + "spaceSwitchCase": 0, "noSpaceAroundUnop": true }, "type": "Spacing" diff --git a/src/checkstyle/Main.hx b/src/checkstyle/Main.hx index 71333c16..e88ae0f3 100644 --- a/src/checkstyle/Main.hx +++ b/src/checkstyle/Main.hx @@ -188,7 +188,7 @@ class Main { catch (e:Dynamic) { var message = 'Failed to configure $prop setting for ${check.getModuleName()}: '; message += (Std.is(e, Error) ? (e:Error).message : Std.string(message)); - failWith(e.message); + failWith(message); } } if (defaultSeverity != null && !props.contains("severity")) check.severity = defaultSeverity; diff --git a/src/checkstyle/checks/Check.hx b/src/checkstyle/checks/Check.hx index b6fd3abf..0ec2bcfb 100644 --- a/src/checkstyle/checks/Check.hx +++ b/src/checkstyle/checks/Check.hx @@ -31,7 +31,7 @@ class Check { desc = haxe.rtti.Meta.getType(Type.getClass(this)).desc[0]; } - public function configureProperty(name:String, value:Any) { + public function configureProperty(name:String, value:Dynamic) { Reflect.setField(this, name, value); } diff --git a/src/checkstyle/checks/Directive.hx b/src/checkstyle/checks/Directive.hx index d61ce755..41abea6a 100644 --- a/src/checkstyle/checks/Directive.hx +++ b/src/checkstyle/checks/Directive.hx @@ -3,14 +3,20 @@ package checkstyle.checks; import Type.ValueType; import checkstyle.errors.InvalidDirectiveError; -@:enum -abstract Directive(String) to String { - var SHOULD = "should"; - var SHOULD_NOT = "shouldNot"; - var ANY = "any"; +enum Directive { + SHOULD; + SHOULD_NOT; + ANY; +} - @:from - public static function fromAny(value:Any):Directive { +class DirectiveTools { + static var MAPPING:Map = [ + "should" => SHOULD, + "shouldNot" => SHOULD_NOT, + "any" => ANY + ]; + + public static function fromDynamic(value:Dynamic):Directive { return switch (Type.typeof(value)) { case ValueType.TClass(String): getValidated(value); //support for legacy configs when such settings were boolean @@ -19,16 +25,9 @@ abstract Directive(String) to String { } } - @:from - static inline function fromString(value:String):Directive { - return getValidated(value); - } - static function getValidated(value:String):Directive { - switch (value:Directive) { - case SHOULD, SHOULD_NOT, ANY: - return value; - } + var directive = MAPPING.get(value); + if (directive != null) return directive; throw new InvalidDirectiveError('Invalid directive: $value'); } } \ No newline at end of file diff --git a/src/checkstyle/checks/whitespace/SpacingCheck.hx b/src/checkstyle/checks/whitespace/SpacingCheck.hx index 716b1df8..218bdeab 100644 --- a/src/checkstyle/checks/whitespace/SpacingCheck.hx +++ b/src/checkstyle/checks/whitespace/SpacingCheck.hx @@ -6,6 +6,7 @@ import haxe.macro.Expr; import haxe.macro.Printer; import haxe.macro.Expr.Binop; import haxe.macro.Expr.Unop; +import checkstyle.checks.Directive; @name("Spacing") @desc("Spacing check on if, for, while, switch, try statements and around operators.") @@ -33,12 +34,12 @@ class SpacingCheck extends Check { categories = [Category.STYLE, Category.CLARITY]; } - override public function configureProperty(name:String, value:Any) { + override public function configureProperty(name:String, value:Dynamic) { var currentValue = Reflect.field(this, name); switch (Type.typeof(currentValue)) { - case ValueType.TClass(String): - Reflect.setField(this, name, (value:Directive)); + case ValueType.TEnum(Directive): + Reflect.setField(this, name, DirectiveTools.fromDynamic(value)); case _: super.configureProperty(name, value); }