From f25940a0f651a469e907018374bea44f3fd8b8d4 Mon Sep 17 00:00:00 2001 From: AlexHaxe Date: Mon, 21 Oct 2019 23:12:32 +0200 Subject: [PATCH] new check AvoidIdentifier marks identifiers to avoid (#483) * new check AvoidIdentifier marks identifiers to avoid --- CHANGELOG.md | 1 + resources/checkstyle-excludes-schema.json | 150 +++++++------- resources/checkstyle-schema.json | 193 +++++++++++------- .../checks/type/AvoidIdentifierCheck.hx | 40 ++++ .../checks/type/AvoidIdentifierCheckTest.hx | 38 ++++ test/checkstyle/config/ConfigParserTest.hx | 8 +- 6 files changed, 280 insertions(+), 150 deletions(-) create mode 100644 src/checkstyle/checks/type/AvoidIdentifierCheck.hx create mode 100644 test/checkstyle/checks/type/AvoidIdentifierCheckTest.hx diff --git a/CHANGELOG.md b/CHANGELOG.md index bf91200d..744a64ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - New check `CodeSimilarity` to check for similar or identical code blocks ([#479](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/479) + [#480](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/480)) - New check `EnforceVarTypeHint` to enforce type hints for all variables and finals, fixes [#464](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/464) ([#481](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/481) + [#482](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/482)) +- New check `AvoidIdentifier` marks identifiers to avoid ([#483](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/483)) - Added coverage upload to codeclimate ([#478](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/478)) - Fixed allow excluding construtor (`new`) via range exclusion ([#479](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/479)) - Refactored build system to use lix ([#478](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/478)) diff --git a/resources/checkstyle-excludes-schema.json b/resources/checkstyle-excludes-schema.json index cb6ee939..9e299bdf 100644 --- a/resources/checkstyle-excludes-schema.json +++ b/resources/checkstyle-excludes-schema.json @@ -18,38 +18,38 @@ }, "UnusedImport": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 75 + "propertyOrder": 76 }, "Dynamic": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 17 + "propertyOrder": 18 }, "MultipleStringLiterals": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 43 + "propertyOrder": 44 }, "EnforceVarTypeHint": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 22 + "propertyOrder": 23 }, "NeedBraces": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 45 + "propertyOrder": 46 }, "SeparatorWhitespace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 61 + "propertyOrder": 62 }, "all": { "$ref": "#/definitions/ExcludeFilterList" }, "LocalVariableName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 36 + "propertyOrder": 37 }, "NestedForDepth": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 46 + "propertyOrder": 47 }, "Anonymous": { "$ref": "#/definitions/ExcludeFilterList", @@ -57,99 +57,103 @@ }, "MultipleVariableDeclarations": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 44 + "propertyOrder": 45 }, "NestedTryDepth": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 48 + "propertyOrder": 49 }, "BlockBreakingConditional": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 9 + "propertyOrder": 10 }, "CatchParameterName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 10 + "propertyOrder": 11 }, "EmptyBlock": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 19 + "propertyOrder": 20 }, "ExtendedEmptyLines": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 23 + "propertyOrder": 24 }, "ReturnCount": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 59 + "propertyOrder": 60 }, "DefaultComesLast": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 15 + "propertyOrder": 16 }, "HexadecimalLiteral": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 26 + "propertyOrder": 27 }, "WhitespaceAfter": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 78 + "propertyOrder": 79 }, "ConstantName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 13 + "propertyOrder": 14 }, "EmptyPackage": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 21 + "propertyOrder": 22 }, "Interface": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 32 + "propertyOrder": 33 }, "WhitespaceAround": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 79 + "propertyOrder": 80 }, "NestedIfDepth": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 47 + "propertyOrder": 48 }, "ParameterName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 52 + "propertyOrder": 53 }, "NullableParameter": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 49 + "propertyOrder": 50 }, "InlineFinal": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 30 + "propertyOrder": 31 }, "AvoidStarImport": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 7 + "propertyOrder": 8 }, "SeparatorWrap": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 62 + "propertyOrder": 63 + }, + "AvoidIdentifier": { + "$ref": "#/definitions/ExcludeFilterList", + "propertyOrder": 7 }, "RedundantAllowMeta": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 56 + "propertyOrder": 57 }, "HiddenField": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 27 + "propertyOrder": 28 }, "UnnecessaryConstructor": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 74 + "propertyOrder": 75 }, "SimplifyBooleanExpression": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 63 + "propertyOrder": 64 }, "path": { "description": "filters excludes relative to\n\t- RELATIVE_TO_PROJECT = use project root\n\t- RELATIVE_TO_SOURCE = use path(s) specified via \"-s \" command line switches", @@ -161,67 +165,67 @@ }, "MethodCount": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 39 + "propertyOrder": 40 }, "UnusedLocalVar": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 76 + "propertyOrder": 77 }, "TabForAligning": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 68 + "propertyOrder": 69 }, "MethodName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 41 + "propertyOrder": 42 }, "RightCurly": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 60 + "propertyOrder": 61 }, "AvoidTernaryOperator": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 8 + "propertyOrder": 9 }, "ParameterNumber": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 53 + "propertyOrder": 54 }, "MethodLength": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 40 + "propertyOrder": 41 }, "ConditionalCompilation": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 12 + "propertyOrder": 13 }, "EmptyLines": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 20 + "propertyOrder": 21 }, "MemberName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 38 + "propertyOrder": 39 }, "ERegLiteral": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 18 + "propertyOrder": 19 }, "RedundantModifier": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 57 + "propertyOrder": 58 }, "Type": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 71 + "propertyOrder": 72 }, "TypeName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 73 + "propertyOrder": 74 }, "Indentation": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 28 + "propertyOrder": 29 }, "version": { "maximum": 1, @@ -230,31 +234,31 @@ }, "Return": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 58 + "propertyOrder": 59 }, "SimplifyBooleanReturn": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 64 + "propertyOrder": 65 }, "TODOComment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 67 + "propertyOrder": 68 }, "OperatorWhitespace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 50 + "propertyOrder": 51 }, "Spacing": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 65 + "propertyOrder": 66 }, "IndentationCharacter": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 29 + "propertyOrder": 30 }, "MagicNumber": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 37 + "propertyOrder": 38 }, "ArrayLiteral": { "$ref": "#/definitions/ExcludeFilterList", @@ -262,35 +266,35 @@ }, "TrailingWhitespace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 70 + "propertyOrder": 71 }, "VariableInitialisation": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 77 + "propertyOrder": 78 }, "LineLength": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 34 + "propertyOrder": 35 }, "ListenerName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 35 + "propertyOrder": 36 }, "FileLength": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 25 + "propertyOrder": 26 }, "CyclomaticComplexity": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 14 + "propertyOrder": 15 }, "StringLiteral": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 66 + "propertyOrder": 67 }, "Trace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 69 + "propertyOrder": 70 }, "ArrayAccess": { "$ref": "#/definitions/ExcludeFilterList", @@ -298,43 +302,43 @@ }, "PublicAccessor": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 54 + "propertyOrder": 55 }, "DocCommentStyle": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 16 + "propertyOrder": 17 }, "InnerAssignment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 31 + "propertyOrder": 32 }, "RedundantAccessMeta": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 55 + "propertyOrder": 56 }, "CodeSimilarity": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 11 + "propertyOrder": 12 }, "OperatorWrap": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 51 + "propertyOrder": 52 }, "TypeDocComment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 72 + "propertyOrder": 73 }, "LeftCurly": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 33 + "propertyOrder": 34 }, "ModifierOrder": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 42 + "propertyOrder": 43 }, "FieldDocComment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 24 + "propertyOrder": 25 } }, "type": "object" diff --git a/resources/checkstyle-schema.json b/resources/checkstyle-schema.json index 51da9ea3..8b4b5b6e 100644 --- a/resources/checkstyle-schema.json +++ b/resources/checkstyle-schema.json @@ -2959,38 +2959,38 @@ }, "UnusedImport": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 75 + "propertyOrder": 76 }, "Dynamic": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 17 + "propertyOrder": 18 }, "MultipleStringLiterals": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 43 + "propertyOrder": 44 }, "EnforceVarTypeHint": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 22 + "propertyOrder": 23 }, "NeedBraces": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 45 + "propertyOrder": 46 }, "SeparatorWhitespace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 61 + "propertyOrder": 62 }, "all": { "$ref": "#/definitions/ExcludeFilterList" }, "LocalVariableName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 36 + "propertyOrder": 37 }, "NestedForDepth": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 46 + "propertyOrder": 47 }, "Anonymous": { "$ref": "#/definitions/ExcludeFilterList", @@ -2998,99 +2998,103 @@ }, "MultipleVariableDeclarations": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 44 + "propertyOrder": 45 }, "NestedTryDepth": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 48 + "propertyOrder": 49 }, "BlockBreakingConditional": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 9 + "propertyOrder": 10 }, "CatchParameterName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 10 + "propertyOrder": 11 }, "EmptyBlock": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 19 + "propertyOrder": 20 }, "ExtendedEmptyLines": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 23 + "propertyOrder": 24 }, "ReturnCount": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 59 + "propertyOrder": 60 }, "DefaultComesLast": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 15 + "propertyOrder": 16 }, "HexadecimalLiteral": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 26 + "propertyOrder": 27 }, "WhitespaceAfter": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 78 + "propertyOrder": 79 }, "ConstantName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 13 + "propertyOrder": 14 }, "EmptyPackage": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 21 + "propertyOrder": 22 }, "Interface": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 32 + "propertyOrder": 33 }, "WhitespaceAround": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 79 + "propertyOrder": 80 }, "NestedIfDepth": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 47 + "propertyOrder": 48 }, "ParameterName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 52 + "propertyOrder": 53 }, "NullableParameter": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 49 + "propertyOrder": 50 }, "InlineFinal": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 30 + "propertyOrder": 31 }, "AvoidStarImport": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 7 + "propertyOrder": 8 }, "SeparatorWrap": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 62 + "propertyOrder": 63 + }, + "AvoidIdentifier": { + "$ref": "#/definitions/ExcludeFilterList", + "propertyOrder": 7 }, "RedundantAllowMeta": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 56 + "propertyOrder": 57 }, "HiddenField": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 27 + "propertyOrder": 28 }, "UnnecessaryConstructor": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 74 + "propertyOrder": 75 }, "SimplifyBooleanExpression": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 63 + "propertyOrder": 64 }, "path": { "description": "filters excludes relative to\n\t- RELATIVE_TO_PROJECT = use project root\n\t- RELATIVE_TO_SOURCE = use path(s) specified via \"-s \" command line switches", @@ -3102,67 +3106,67 @@ }, "MethodCount": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 39 + "propertyOrder": 40 }, "UnusedLocalVar": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 76 + "propertyOrder": 77 }, "TabForAligning": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 68 + "propertyOrder": 69 }, "MethodName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 41 + "propertyOrder": 42 }, "RightCurly": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 60 + "propertyOrder": 61 }, "AvoidTernaryOperator": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 8 + "propertyOrder": 9 }, "ParameterNumber": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 53 + "propertyOrder": 54 }, "MethodLength": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 40 + "propertyOrder": 41 }, "ConditionalCompilation": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 12 + "propertyOrder": 13 }, "EmptyLines": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 20 + "propertyOrder": 21 }, "MemberName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 38 + "propertyOrder": 39 }, "ERegLiteral": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 18 + "propertyOrder": 19 }, "RedundantModifier": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 57 + "propertyOrder": 58 }, "Type": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 71 + "propertyOrder": 72 }, "TypeName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 73 + "propertyOrder": 74 }, "Indentation": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 28 + "propertyOrder": 29 }, "version": { "maximum": 1, @@ -3171,31 +3175,31 @@ }, "Return": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 58 + "propertyOrder": 59 }, "SimplifyBooleanReturn": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 64 + "propertyOrder": 65 }, "TODOComment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 67 + "propertyOrder": 68 }, "OperatorWhitespace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 50 + "propertyOrder": 51 }, "Spacing": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 65 + "propertyOrder": 66 }, "IndentationCharacter": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 29 + "propertyOrder": 30 }, "MagicNumber": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 37 + "propertyOrder": 38 }, "ArrayLiteral": { "$ref": "#/definitions/ExcludeFilterList", @@ -3203,35 +3207,35 @@ }, "TrailingWhitespace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 70 + "propertyOrder": 71 }, "VariableInitialisation": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 77 + "propertyOrder": 78 }, "LineLength": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 34 + "propertyOrder": 35 }, "ListenerName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 35 + "propertyOrder": 36 }, "FileLength": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 25 + "propertyOrder": 26 }, "CyclomaticComplexity": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 14 + "propertyOrder": 15 }, "StringLiteral": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 66 + "propertyOrder": 67 }, "Trace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 69 + "propertyOrder": 70 }, "ArrayAccess": { "$ref": "#/definitions/ExcludeFilterList", @@ -3239,43 +3243,43 @@ }, "PublicAccessor": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 54 + "propertyOrder": 55 }, "DocCommentStyle": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 16 + "propertyOrder": 17 }, "InnerAssignment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 31 + "propertyOrder": 32 }, "RedundantAccessMeta": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 55 + "propertyOrder": 56 }, "CodeSimilarity": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 11 + "propertyOrder": 12 }, "OperatorWrap": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 51 + "propertyOrder": 52 }, "TypeDocComment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 72 + "propertyOrder": 73 }, "LeftCurly": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 33 + "propertyOrder": 34 }, "ModifierOrder": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 42 + "propertyOrder": 43 }, "FieldDocComment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 24 + "propertyOrder": 25 } }, "type": "object" @@ -3853,6 +3857,46 @@ }, "type": "object" }, + "AvoidIdentifierCheck": { + "description": "Checks for identifiers to avoid.", + "additionalProperties": false, + "properties": { + "type": { + "description": "Checks for identifiers to avoid.", + "type": "string", + "enum": [ + "AvoidIdentifier" + ] + }, + "props": { + "description": "Checks for identifiers to avoid.", + "additionalProperties": false, + "properties": { + "severity": { + "description": "sets gravity of reported violations:\n\t- IGNORE = do not report violations, violations do not appear anywhere in output\n\t- INFO = all violations have info / lowest priority\n\t- WARNING = all violations have warning / medium priority\n\t- ERROR = all violations have error / highest priority", + "type": "string", + "enum": [ + "INFO", + "WARNING", + "ERROR", + "IGNORE" + ], + "propertyOrder": 1 + }, + "avoidIdentifiers": { + "description": "list of identifiers to avoid", + "items": { + "type": "string" + }, + "type": "array", + "propertyOrder": 0 + } + }, + "type": "object" + } + }, + "type": "object" + }, "NeedBracesCheck": { "description": "Checks for braces on function, if, for and while statements. It has an option to allow single line statements without braces using property `allowSingleLineStatement` like `if (b) return 10;`.", "additionalProperties": false, @@ -4090,6 +4134,9 @@ { "$ref": "#/definitions/ArrayLiteralCheck" }, + { + "$ref": "#/definitions/AvoidIdentifierCheck" + }, { "$ref": "#/definitions/AvoidStarImportCheck" }, diff --git a/src/checkstyle/checks/type/AvoidIdentifierCheck.hx b/src/checkstyle/checks/type/AvoidIdentifierCheck.hx new file mode 100644 index 00000000..00608b40 --- /dev/null +++ b/src/checkstyle/checks/type/AvoidIdentifierCheck.hx @@ -0,0 +1,40 @@ +package checkstyle.checks.type; + +/** + Checks for identifiers to avoid. +**/ +@name("AvoidIdentifier") +@desc("Checks for identifiers to avoid.") +class AvoidIdentifierCheck extends Check { + /** + list of identifiers to avoid + **/ + public var avoidIdentifiers:Array; + + public function new() { + super(TOKEN); + avoidIdentifiers = []; + } + + override function actualRun() { + var root:TokenTree = checker.getTokenTree(); + root.filterCallback(function(token:TokenTree, index:Int):FilterResult { + switch (token.tok) { + case Const(CIdent(ident)): + checkIdent(ident, token); + default: + } + return GO_DEEPER; + }); + } + + function checkIdent(ident:String, token:TokenTree) { + if (isPosSuppressed(token.pos)) return; + if (avoidIdentifiers.indexOf(ident) < 0) return; + error(ident, token.pos); + } + + function error(name:String, pos:Position) { + logPos('Identifier "${name}" should be avoided', pos); + } +} \ No newline at end of file diff --git a/test/checkstyle/checks/type/AvoidIdentifierCheckTest.hx b/test/checkstyle/checks/type/AvoidIdentifierCheckTest.hx new file mode 100644 index 00000000..2bdd679d --- /dev/null +++ b/test/checkstyle/checks/type/AvoidIdentifierCheckTest.hx @@ -0,0 +1,38 @@ +package checkstyle.checks.type; + +class AvoidIdentifierCheckTest extends CheckTestCase { + @Test + public function testCorrectTypeHints() { + var check = new AvoidIdentifierCheck(); + assertNoMsg(check, TEST); + + check.avoidIdentifiers = ["TokenTree"]; + assertMsg(check, TEST, 'Identifier "TokenTree" should be avoided'); + check.avoidIdentifiers = ["a"]; + assertMsg(check, TEST, 'Identifier "a" should be avoided'); + + check.avoidIdentifiers = ["TokenTree2"]; + assertNoMsg(check, TEST); + } +} + +@:enum +abstract AvoidIdentifierCheckTests(String) to String { + var TEST = " + abstractAndClass Test { + var a:Int; + + function checkIdent(ident:String, token:TokenTree) { + if (isPosSuppressed(token.pos)) return; + if (avoidIdentifiers.indexOf(ident) < 0) return; + error(ident, token.pos); + } + + @SuppressWarnings('checkstyle:AvoidIdentifier') + function checkIdent2(ident:String, token:TokenTree2) { + if (isPosSuppressed(token.pos)) return; + if (avoidIdentifiers.indexOf(ident) < 0) return; + error2(ident, token.pos); + } + }"; +} \ No newline at end of file diff --git a/test/checkstyle/config/ConfigParserTest.hx b/test/checkstyle/config/ConfigParserTest.hx index f64b548d..d7f43040 100644 --- a/test/checkstyle/config/ConfigParserTest.hx +++ b/test/checkstyle/config/ConfigParserTest.hx @@ -58,9 +58,9 @@ class ConfigParserTest { var configParser:ConfigParser = new ConfigParser(reportConfigParserFailure); #if haxe4 - Assert.areEqual(76, configParser.getCheckCount()); + Assert.areEqual(77, configParser.getCheckCount()); #else - Assert.areEqual(75, configParser.getCheckCount()); + Assert.areEqual(76, configParser.getCheckCount()); #end } @@ -71,9 +71,9 @@ class ConfigParserTest { Assert.areEqual(0, configParser.getUsedCheckCount()); configParser.addAllChecks(); #if haxe4 - Assert.areEqual(76, configParser.getUsedCheckCount()); + Assert.areEqual(77, configParser.getUsedCheckCount()); #else - Assert.areEqual(75, configParser.getUsedCheckCount()); + Assert.areEqual(76, configParser.getUsedCheckCount()); #end }