diff --git a/.github/workflows/checkstyle-linux.yml b/.github/workflows/checkstyle-linux.yml index 81f42c45..d28f9f12 100644 --- a/.github/workflows/checkstyle-linux.yml +++ b/.github/workflows/checkstyle-linux.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - haxe-version: ['3.4.7', '4.0.5', '4.1.1', 'nightly'] + haxe-version: ['3.4.7', '4.0.5', '4.1.2', 'nightly'] env: CC_TEST_REPORTER_ID: 1dff6f89d7179dff5db635c6b4fe64acdd5694c9ed44d7da5f12f0f7d3d163b7 CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} @@ -26,7 +26,7 @@ jobs: with: node-version: 10 - name: Installing codeclimate client - if: matrix.haxe-version == '4.1.1' + if: matrix.haxe-version == '4.1.2' run: | curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter chmod +x ./cc-test-reporter @@ -72,7 +72,7 @@ jobs: if: matrix.haxe-version != '3.4.7' run: npx haxe testJvm.hxml - name: Format and upload codeclimate coverage - if: success() && matrix.haxe-version == '4.1.1' + if: success() && matrix.haxe-version == '4.1.2' run: | ( \ cd src; \ @@ -80,5 +80,5 @@ jobs: ../cc-test-reporter upload-coverage; \ ) - name: Upload results to codecov - if: success() && (matrix.haxe-version == '3.4.7' || matrix.haxe-version == '4.1.1') + if: success() && (matrix.haxe-version == '3.4.7' || matrix.haxe-version == '4.1.2') run: bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" diff --git a/.haxerc b/.haxerc index e89f5794..372dbd4f 100644 --- a/.haxerc +++ b/.haxerc @@ -1,4 +1,4 @@ { - "version": "4.1.1", + "version": "4.1.2", "resolveLibs": "scoped" } \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a40c7234..714d2a5b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ install: - if [[ "$HAXE_VERSION" == "haxe347" ]]; then mv haxe_libraries haxe4_libraries; mv haxe3_libraries haxe_libraries; fi - if [[ "$HAXE_VERSION" == "haxe347" ]]; then npx lix download haxe 3.4.7; npx lix use haxe 3.4.7; fi - if [[ "$HAXE_VERSION" == "haxe4" ]]; then npx lix download haxe 4.0.5; npx lix use haxe 4.0.5; fi - - if [[ "$HAXE_VERSION" == "haxe41" ]]; then npx lix download haxe 4.1.1; npx lix use haxe 4.1.1; fi + - if [[ "$HAXE_VERSION" == "haxe41" ]]; then npx lix download haxe 4.1.2; npx lix use haxe 4.1.2; fi - if [[ "$HAXE_VERSION" == "nightly" ]]; then npx lix download haxe nightly; npx lix use haxe nightly; fi - npx lix download - npx haxe -version diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fb4433c..41a5d2a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,11 @@ ## dev branch / next version (2.x.x) +- **Breaking Change** replaced `EnforceVarTypeHint` with `VarTypeHint` check ([#500](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/500)) - Added support for final in `MagicNumber`, fixes [#494](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/494) ([#495](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/495)) - Fixed handling `OBJECT_DECL` token in `RightCurly`, fixes [#496](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/496) ([#497](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/497)) - Reorganised build files ([#498](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/498)) +- Refactored for tokentree API change ([#500](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/500)) ## version 2.6.1 (2019-12-17) diff --git a/checkstyle.json b/checkstyle.json index 35251b57..dbebee8f 100644 --- a/checkstyle.json +++ b/checkstyle.json @@ -153,15 +153,6 @@ }, "type": "HiddenField" }, - { - "type": "Indentation" - }, - { - "props": { - "character": "tab" - }, - "type": "IndentationCharacter" - }, { "type": "InnerAssignment" }, diff --git a/haxe3_libraries/tokentree.hxml b/haxe3_libraries/tokentree.hxml index 7940cc95..b3546cb6 100644 --- a/haxe3_libraries/tokentree.hxml +++ b/haxe3_libraries/tokentree.hxml @@ -1,3 +1,3 @@ -# @install: lix --silent download "gh://github.com/HaxeCheckstyle/tokentree#119c4cefa927018472cd57f5de1063d43f00da95" into tokentree/1.0.24/github/119c4cefa927018472cd57f5de1063d43f00da95 --cp ${HAXE_LIBCACHE}/tokentree/1.0.24/github/119c4cefa927018472cd57f5de1063d43f00da95/src --D tokentree=1.0.24 +# @install: lix --silent download "gh://github.com/HaxeCheckstyle/tokentree#7bada801831488a3bed105838c263ec819c69dfb" into tokentree/1.0.28/github/7bada801831488a3bed105838c263ec819c69dfb +-cp ${HAXE_LIBCACHE}/tokentree/1.0.28/github/7bada801831488a3bed105838c263ec819c69dfb/src +-D tokentree=1.0.28 \ No newline at end of file diff --git a/haxe_libraries/haxeparser.hxml b/haxe_libraries/haxeparser.hxml index 4756bf0d..1c0cd87e 100644 --- a/haxe_libraries/haxeparser.hxml +++ b/haxe_libraries/haxeparser.hxml @@ -1,4 +1,4 @@ --D haxeparser=3.3.0 -# @install: lix --silent download "gh://github.com/Simn/haxeparser#e5746bfc55c09a3694db42738ff575b91441971a" into haxeparser/3.3.0/github/e5746bfc55c09a3694db42738ff575b91441971a +# @install: lix --silent download "gh://github.com/simn/haxeparser#00b509e8690300ca6366aa8d0d4d97bd29fbcf2b" into haxeparser/3.3.0/github/00b509e8690300ca6366aa8d0d4d97bd29fbcf2b -lib hxparse --cp ${HAXE_LIBCACHE}/haxeparser/3.3.0/github/e5746bfc55c09a3694db42738ff575b91441971a/src +-cp ${HAXE_LIBCACHE}/haxeparser/3.3.0/github/00b509e8690300ca6366aa8d0d4d97bd29fbcf2b/src +-D haxeparser=3.3.0 \ No newline at end of file diff --git a/haxe_libraries/tokentree.hxml b/haxe_libraries/tokentree.hxml index 7940cc95..b3546cb6 100644 --- a/haxe_libraries/tokentree.hxml +++ b/haxe_libraries/tokentree.hxml @@ -1,3 +1,3 @@ -# @install: lix --silent download "gh://github.com/HaxeCheckstyle/tokentree#119c4cefa927018472cd57f5de1063d43f00da95" into tokentree/1.0.24/github/119c4cefa927018472cd57f5de1063d43f00da95 --cp ${HAXE_LIBCACHE}/tokentree/1.0.24/github/119c4cefa927018472cd57f5de1063d43f00da95/src --D tokentree=1.0.24 +# @install: lix --silent download "gh://github.com/HaxeCheckstyle/tokentree#7bada801831488a3bed105838c263ec819c69dfb" into tokentree/1.0.28/github/7bada801831488a3bed105838c263ec819c69dfb +-cp ${HAXE_LIBCACHE}/tokentree/1.0.28/github/7bada801831488a3bed105838c263ec819c69dfb/src +-D tokentree=1.0.28 \ No newline at end of file diff --git a/resources/checkstyle-excludes-schema.json b/resources/checkstyle-excludes-schema.json index 6f212a10..f16f5a34 100644 --- a/resources/checkstyle-excludes-schema.json +++ b/resources/checkstyle-excludes-schema.json @@ -18,7 +18,7 @@ }, "UnusedImport": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 78 + "propertyOrder": 77 }, "Dynamic": { "$ref": "#/definitions/ExcludeFilterList", @@ -26,34 +26,30 @@ }, "Final": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 28 + "propertyOrder": 27 }, "MultipleStringLiterals": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 45 - }, - "EnforceVarTypeHint": { - "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 24 + "propertyOrder": 44 }, "NeedBraces": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 47 + "propertyOrder": 46 }, "SeparatorWhitespace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 64 + "propertyOrder": 63 }, "all": { "$ref": "#/definitions/ExcludeFilterList" }, "LocalVariableName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 38 + "propertyOrder": 37 }, "NestedForDepth": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 49 + "propertyOrder": 48 }, "Anonymous": { "$ref": "#/definitions/ExcludeFilterList", @@ -61,11 +57,11 @@ }, "MultipleVariableDeclarations": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 46 + "propertyOrder": 45 }, "NestedTryDepth": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 51 + "propertyOrder": 50 }, "BlockBreakingConditional": { "$ref": "#/definitions/ExcludeFilterList", @@ -81,11 +77,11 @@ }, "ExtendedEmptyLines": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 25 + "propertyOrder": 24 }, "ReturnCount": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 62 + "propertyOrder": 61 }, "DefaultComesLast": { "$ref": "#/definitions/ExcludeFilterList", @@ -93,7 +89,7 @@ }, "HexadecimalLiteral": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 29 + "propertyOrder": 28 }, "WhitespaceAfter": { "$ref": "#/definitions/ExcludeFilterList", @@ -109,7 +105,7 @@ }, "Interface": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 34 + "propertyOrder": 33 }, "WhitespaceAround": { "$ref": "#/definitions/ExcludeFilterList", @@ -117,15 +113,15 @@ }, "NestedIfDepth": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 50 + "propertyOrder": 49 }, "ParameterName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 55 + "propertyOrder": 54 }, "NullableParameter": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 52 + "propertyOrder": 51 }, "AvoidStarImport": { "$ref": "#/definitions/ExcludeFilterList", @@ -133,7 +129,7 @@ }, "SeparatorWrap": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 65 + "propertyOrder": 64 }, "AvoidIdentifier": { "$ref": "#/definitions/ExcludeFilterList", @@ -141,19 +137,19 @@ }, "RedundantAllowMeta": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 59 + "propertyOrder": 58 }, "HiddenField": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 30 + "propertyOrder": 29 }, "UnnecessaryConstructor": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 77 + "propertyOrder": 76 }, "SimplifyBooleanExpression": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 66 + "propertyOrder": 65 }, "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", @@ -165,23 +161,23 @@ }, "MethodCount": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 41 + "propertyOrder": 40 }, "UnusedLocalVar": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 79 + "propertyOrder": 78 }, "TabForAligning": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 71 + "propertyOrder": 70 }, "MethodName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 43 + "propertyOrder": 42 }, "RightCurly": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 63 + "propertyOrder": 62 }, "AvoidTernaryOperator": { "$ref": "#/definitions/ExcludeFilterList", @@ -189,7 +185,7 @@ }, "ParameterNumber": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 56 + "propertyOrder": 55 }, "ArrowFunction": { "$ref": "#/definitions/ExcludeFilterList", @@ -197,7 +193,7 @@ }, "MethodLength": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 42 + "propertyOrder": 41 }, "ConditionalCompilation": { "$ref": "#/definitions/ExcludeFilterList", @@ -209,7 +205,7 @@ }, "MemberName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 40 + "propertyOrder": 39 }, "ERegLiteral": { "$ref": "#/definitions/ExcludeFilterList", @@ -217,19 +213,19 @@ }, "RedundantModifier": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 60 + "propertyOrder": 59 }, "Type": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 74 + "propertyOrder": 73 }, "TypeName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 76 + "propertyOrder": 75 }, "Indentation": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 31 + "propertyOrder": 30 }, "version": { "maximum": 1, @@ -238,35 +234,39 @@ }, "Return": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 61 + "propertyOrder": 60 }, "SimplifyBooleanReturn": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 67 + "propertyOrder": 66 }, "TODOComment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 70 + "propertyOrder": 69 + }, + "VarTypeHint": { + "$ref": "#/definitions/ExcludeFilterList", + "propertyOrder": 79 }, "NestedControlFlow": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 48 + "propertyOrder": 47 }, "OperatorWhitespace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 53 + "propertyOrder": 52 }, "Spacing": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 68 + "propertyOrder": 67 }, "IndentationCharacter": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 32 + "propertyOrder": 31 }, "MagicNumber": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 39 + "propertyOrder": 38 }, "ArrayLiteral": { "$ref": "#/definitions/ExcludeFilterList", @@ -274,7 +274,7 @@ }, "TrailingWhitespace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 73 + "propertyOrder": 72 }, "VariableInitialisation": { "$ref": "#/definitions/ExcludeFilterList", @@ -282,15 +282,15 @@ }, "LineLength": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 36 + "propertyOrder": 35 }, "ListenerName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 37 + "propertyOrder": 36 }, "FileLength": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 27 + "propertyOrder": 26 }, "CyclomaticComplexity": { "$ref": "#/definitions/ExcludeFilterList", @@ -298,11 +298,11 @@ }, "StringLiteral": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 69 + "propertyOrder": 68 }, "Trace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 72 + "propertyOrder": 71 }, "ArrayAccess": { "$ref": "#/definitions/ExcludeFilterList", @@ -310,7 +310,7 @@ }, "PublicAccessor": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 57 + "propertyOrder": 56 }, "DocCommentStyle": { "$ref": "#/definitions/ExcludeFilterList", @@ -318,11 +318,11 @@ }, "InnerAssignment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 33 + "propertyOrder": 32 }, "RedundantAccessMeta": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 58 + "propertyOrder": 57 }, "CodeSimilarity": { "$ref": "#/definitions/ExcludeFilterList", @@ -330,23 +330,23 @@ }, "OperatorWrap": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 54 + "propertyOrder": 53 }, "TypeDocComment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 75 + "propertyOrder": 74 }, "LeftCurly": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 35 + "propertyOrder": 34 }, "ModifierOrder": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 44 + "propertyOrder": 43 }, "FieldDocComment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 26 + "propertyOrder": 25 } }, "type": "object" diff --git a/resources/checkstyle-schema.json b/resources/checkstyle-schema.json index 77b6bb00..e1734577 100644 --- a/resources/checkstyle-schema.json +++ b/resources/checkstyle-schema.json @@ -1746,43 +1746,6 @@ }, "type": "object" }, - "EnforceVarTypeHintCheck": { - "description": "Checks if all variables have type hint.", - "additionalProperties": false, - "properties": { - "type": { - "description": "Checks if all variables have type hint.", - "type": "string", - "enum": [ - "EnforceVarTypeHint" - ] - }, - "props": { - "description": "Checks if all variables have type hint.", - "additionalProperties": false, - "properties": { - "ignoreEnumAbstractValues": { - "description": "ignores fields inside abstract enums", - "type": "boolean", - "propertyOrder": 0 - }, - "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 - } - }, - "type": "object" - } - }, - "type": "object" - }, "SimplifyBooleanReturnCheck": { "description": "Checks for over-complicated boolean return statements.", "additionalProperties": false, @@ -3021,7 +2984,7 @@ }, "UnusedImport": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 78 + "propertyOrder": 77 }, "Dynamic": { "$ref": "#/definitions/ExcludeFilterList", @@ -3029,34 +2992,30 @@ }, "Final": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 28 + "propertyOrder": 27 }, "MultipleStringLiterals": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 45 - }, - "EnforceVarTypeHint": { - "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 24 + "propertyOrder": 44 }, "NeedBraces": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 47 + "propertyOrder": 46 }, "SeparatorWhitespace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 64 + "propertyOrder": 63 }, "all": { "$ref": "#/definitions/ExcludeFilterList" }, "LocalVariableName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 38 + "propertyOrder": 37 }, "NestedForDepth": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 49 + "propertyOrder": 48 }, "Anonymous": { "$ref": "#/definitions/ExcludeFilterList", @@ -3064,11 +3023,11 @@ }, "MultipleVariableDeclarations": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 46 + "propertyOrder": 45 }, "NestedTryDepth": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 51 + "propertyOrder": 50 }, "BlockBreakingConditional": { "$ref": "#/definitions/ExcludeFilterList", @@ -3084,11 +3043,11 @@ }, "ExtendedEmptyLines": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 25 + "propertyOrder": 24 }, "ReturnCount": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 62 + "propertyOrder": 61 }, "DefaultComesLast": { "$ref": "#/definitions/ExcludeFilterList", @@ -3096,7 +3055,7 @@ }, "HexadecimalLiteral": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 29 + "propertyOrder": 28 }, "WhitespaceAfter": { "$ref": "#/definitions/ExcludeFilterList", @@ -3112,7 +3071,7 @@ }, "Interface": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 34 + "propertyOrder": 33 }, "WhitespaceAround": { "$ref": "#/definitions/ExcludeFilterList", @@ -3120,15 +3079,15 @@ }, "NestedIfDepth": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 50 + "propertyOrder": 49 }, "ParameterName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 55 + "propertyOrder": 54 }, "NullableParameter": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 52 + "propertyOrder": 51 }, "AvoidStarImport": { "$ref": "#/definitions/ExcludeFilterList", @@ -3136,7 +3095,7 @@ }, "SeparatorWrap": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 65 + "propertyOrder": 64 }, "AvoidIdentifier": { "$ref": "#/definitions/ExcludeFilterList", @@ -3144,19 +3103,19 @@ }, "RedundantAllowMeta": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 59 + "propertyOrder": 58 }, "HiddenField": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 30 + "propertyOrder": 29 }, "UnnecessaryConstructor": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 77 + "propertyOrder": 76 }, "SimplifyBooleanExpression": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 66 + "propertyOrder": 65 }, "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", @@ -3168,23 +3127,23 @@ }, "MethodCount": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 41 + "propertyOrder": 40 }, "UnusedLocalVar": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 79 + "propertyOrder": 78 }, "TabForAligning": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 71 + "propertyOrder": 70 }, "MethodName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 43 + "propertyOrder": 42 }, "RightCurly": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 63 + "propertyOrder": 62 }, "AvoidTernaryOperator": { "$ref": "#/definitions/ExcludeFilterList", @@ -3192,7 +3151,7 @@ }, "ParameterNumber": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 56 + "propertyOrder": 55 }, "ArrowFunction": { "$ref": "#/definitions/ExcludeFilterList", @@ -3200,7 +3159,7 @@ }, "MethodLength": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 42 + "propertyOrder": 41 }, "ConditionalCompilation": { "$ref": "#/definitions/ExcludeFilterList", @@ -3212,7 +3171,7 @@ }, "MemberName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 40 + "propertyOrder": 39 }, "ERegLiteral": { "$ref": "#/definitions/ExcludeFilterList", @@ -3220,19 +3179,19 @@ }, "RedundantModifier": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 60 + "propertyOrder": 59 }, "Type": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 74 + "propertyOrder": 73 }, "TypeName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 76 + "propertyOrder": 75 }, "Indentation": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 31 + "propertyOrder": 30 }, "version": { "maximum": 1, @@ -3241,35 +3200,39 @@ }, "Return": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 61 + "propertyOrder": 60 }, "SimplifyBooleanReturn": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 67 + "propertyOrder": 66 }, "TODOComment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 70 + "propertyOrder": 69 + }, + "VarTypeHint": { + "$ref": "#/definitions/ExcludeFilterList", + "propertyOrder": 79 }, "NestedControlFlow": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 48 + "propertyOrder": 47 }, "OperatorWhitespace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 53 + "propertyOrder": 52 }, "Spacing": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 68 + "propertyOrder": 67 }, "IndentationCharacter": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 32 + "propertyOrder": 31 }, "MagicNumber": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 39 + "propertyOrder": 38 }, "ArrayLiteral": { "$ref": "#/definitions/ExcludeFilterList", @@ -3277,7 +3240,7 @@ }, "TrailingWhitespace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 73 + "propertyOrder": 72 }, "VariableInitialisation": { "$ref": "#/definitions/ExcludeFilterList", @@ -3285,15 +3248,15 @@ }, "LineLength": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 36 + "propertyOrder": 35 }, "ListenerName": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 37 + "propertyOrder": 36 }, "FileLength": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 27 + "propertyOrder": 26 }, "CyclomaticComplexity": { "$ref": "#/definitions/ExcludeFilterList", @@ -3301,11 +3264,11 @@ }, "StringLiteral": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 69 + "propertyOrder": 68 }, "Trace": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 72 + "propertyOrder": 71 }, "ArrayAccess": { "$ref": "#/definitions/ExcludeFilterList", @@ -3313,7 +3276,7 @@ }, "PublicAccessor": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 57 + "propertyOrder": 56 }, "DocCommentStyle": { "$ref": "#/definitions/ExcludeFilterList", @@ -3321,11 +3284,11 @@ }, "InnerAssignment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 33 + "propertyOrder": 32 }, "RedundantAccessMeta": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 58 + "propertyOrder": 57 }, "CodeSimilarity": { "$ref": "#/definitions/ExcludeFilterList", @@ -3333,23 +3296,23 @@ }, "OperatorWrap": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 54 + "propertyOrder": 53 }, "TypeDocComment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 75 + "propertyOrder": 74 }, "LeftCurly": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 35 + "propertyOrder": 34 }, "ModifierOrder": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 44 + "propertyOrder": 43 }, "FieldDocComment": { "$ref": "#/definitions/ExcludeFilterList", - "propertyOrder": 26 + "propertyOrder": 25 } }, "type": "object" @@ -3470,6 +3433,53 @@ }, "type": "object" }, + "VarTypeHintCheck": { + "description": "Checks type hints of variables.", + "additionalProperties": false, + "properties": { + "type": { + "description": "Checks type hints of variables.", + "type": "string", + "enum": [ + "VarTypeHint" + ] + }, + "props": { + "description": "Checks type hints of variables.", + "additionalProperties": false, + "properties": { + "ignoreEnumAbstractValues": { + "description": "ignores fields inside abstract enums", + "type": "boolean", + "propertyOrder": 1 + }, + "typeHintPolicy": { + "description": "policy for type hints on var and final", + "type": "string", + "enum": [ + "enforce_all", + "infer_new_or_const", + "infer_all" + ], + "propertyOrder": 0 + }, + "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": 2 + } + }, + "type": "object" + } + }, + "type": "object" + }, "CodeSimilarityCheck": { "description": "Checks for identical or similar code.", "additionalProperties": false, @@ -4292,9 +4302,6 @@ { "$ref": "#/definitions/EmptyPackageCheck" }, - { - "$ref": "#/definitions/EnforceVarTypeHintCheck" - }, { "$ref": "#/definitions/ExtendedEmptyLinesCheck" }, @@ -4460,6 +4467,9 @@ { "$ref": "#/definitions/UnusedLocalVarCheck" }, + { + "$ref": "#/definitions/VarTypeHintCheck" + }, { "$ref": "#/definitions/VariableInitialisationCheck" }, diff --git a/resources/default-config.json b/resources/default-config.json index fc105995..da14a7e7 100644 --- a/resources/default-config.json +++ b/resources/default-config.json @@ -149,12 +149,6 @@ "enforceEmptyPackage": false } }, - { - "type": "EnforceVarTypeHint", - "props": { - "ignoreEnumAbstractValues": true - } - }, { "type": "ExtendedEmptyLines", "props": { @@ -646,6 +640,13 @@ "type": "UnusedLocalVar", "props": {} }, + { + "type": "VarTypeHint", + "props": { + "typeHintPolicy": "infer_new_or_const", + "ignoreEnumAbstractValues": true + } + }, { "type": "VariableInitialisation", "props": { diff --git a/src/checkstyle/checks/block/BlockBreakingConditionalCheck.hx b/src/checkstyle/checks/block/BlockBreakingConditionalCheck.hx index c24a0979..11aee1d1 100644 --- a/src/checkstyle/checks/block/BlockBreakingConditionalCheck.hx +++ b/src/checkstyle/checks/block/BlockBreakingConditionalCheck.hx @@ -12,7 +12,7 @@ class BlockBreakingConditionalCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var allBrs:Array = root.filter([BrOpen, BrClose], ALL); + var allBrs:Array = root.filter([BrOpen, BrClose], All); for (br in allBrs) { if (isPosSuppressed(br.pos)) continue; diff --git a/src/checkstyle/checks/block/ConditionalCompilationCheck.hx b/src/checkstyle/checks/block/ConditionalCompilationCheck.hx index 44769880..46dcfdc8 100644 --- a/src/checkstyle/checks/block/ConditionalCompilationCheck.hx +++ b/src/checkstyle/checks/block/ConditionalCompilationCheck.hx @@ -29,7 +29,7 @@ class ConditionalCompilationCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - checkSharpIf(root.filter([Sharp("if")], ALL)); + checkSharpIf(root.filter([Sharp("if")], All)); } function checkSharpIf(tokens:Array) { diff --git a/src/checkstyle/checks/block/EmptyBlockCheck.hx b/src/checkstyle/checks/block/EmptyBlockCheck.hx index f1b823af..f2b5a01f 100644 --- a/src/checkstyle/checks/block/EmptyBlockCheck.hx +++ b/src/checkstyle/checks/block/EmptyBlockCheck.hx @@ -59,7 +59,7 @@ class EmptyBlockCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var allBrOpen:Array = root.filter([BrOpen], ALL); + var allBrOpen:Array = root.filter([BrOpen], All); for (brOpen in allBrOpen) { if (isPosSuppressed(brOpen.pos)) continue; @@ -78,7 +78,7 @@ class EmptyBlockCheck extends Check { } function filterParentToken(token:TokenTree):Bool { - if ((token == null) || (token.tok == null)) return false; + if ((token == null) || (token.tok == Root)) return false; switch (token.tok) { case Kwd(KwdClass): return !hasToken(CLASS_DEF); diff --git a/src/checkstyle/checks/block/LeftCurlyCheck.hx b/src/checkstyle/checks/block/LeftCurlyCheck.hx index 0318fb2a..b61cf8e1 100644 --- a/src/checkstyle/checks/block/LeftCurlyCheck.hx +++ b/src/checkstyle/checks/block/LeftCurlyCheck.hx @@ -72,21 +72,21 @@ class LeftCurlyCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var allBrOpen:Array = root.filter([BrOpen], ALL); + var allBrOpen:Array = root.filter([BrOpen], All); for (brOpen in allBrOpen) { if (isPosSuppressed(brOpen.pos)) continue; if (skipSingleLine(brOpen)) continue; var type:BrOpenType = TokenTreeCheckUtils.getBrOpenType(brOpen); switch (type) { - case BLOCK: - case TYPEDEFDECL: + case Block: + case TypedefDecl: if (!hasToken(TYPEDEF_DEF)) continue; - case OBJECTDECL: + case ObjectDecl: if (!hasToken(OBJECT_DECL)) continue; - case ANONTYPE: + case AnonType: if (!hasToken(ANON_TYPE)) continue; - case UNKNOWN: + case Unknown: } var parent:ParentToken = findParentToken(brOpen.parent); if (!parent.hasToken) continue; @@ -108,7 +108,7 @@ class LeftCurlyCheck extends Check { find effective parent token and check against configured tokens **/ function findParentToken(token:TokenTree):ParentToken { - if ((token == null) || (token.tok == null)) return {token: token, hasToken: false}; + if ((token == null) || (token.tok == Root)) return {token: token, hasToken: false}; switch (token.tok) { case Kwd(KwdClass): return {token: token, hasToken: hasToken(CLASS_DEF)}; @@ -159,22 +159,22 @@ class LeftCurlyCheck extends Check { } function findParentTokenDblDot(token:TokenTree):ParentToken { - if ((token == null) || (token.tok == null)) return {token: token, hasToken: false}; + if ((token == null) || (token.tok == Root)) return {token: token, hasToken: false}; var type:ColonType = TokenTreeCheckUtils.getColonType(token); switch (type) { - case SWITCH_CASE: + case SwitchCase: return {token: token, hasToken: hasToken(SWITCH)}; - case TYPE_HINT: + case TypeHint: return {token: token, hasToken: hasToken(TYPEDEF_DEF)}; - case TYPE_CHECK: + case TypeCheck: return {token: token, hasToken: hasToken(TYPEDEF_DEF)}; - case TERNARY: + case Ternary: return {token: token, hasToken: false}; - case OBJECT_LITERAL: + case ObjectLiteral: return {token: token, hasToken: hasToken(OBJECT_DECL)}; - case AT: + case At: return {token: token, hasToken: false}; - case UNKNOWN: + case Unknown: return {token: token, hasToken: false}; } } diff --git a/src/checkstyle/checks/block/NeedBracesCheck.hx b/src/checkstyle/checks/block/NeedBracesCheck.hx index 4300eadd..e121a8c8 100644 --- a/src/checkstyle/checks/block/NeedBracesCheck.hx +++ b/src/checkstyle/checks/block/NeedBracesCheck.hx @@ -36,7 +36,7 @@ class NeedBracesCheck extends Check { } override function actualRun() { - var tokenList:Array = []; + var tokenList:Array = []; if (hasToken(FUNCTION)) tokenList.push(Kwd(KwdFunction)); if (hasToken(FOR)) tokenList.push(Kwd(KwdFor)); @@ -51,7 +51,7 @@ class NeedBracesCheck extends Check { if (tokenList.length <= 0) return; var root:TokenTree = checker.getTokenTree(); - var allTokens:Array = root.filter(tokenList, ALL); + var allTokens:Array = root.filter(tokenList, All); for (tok in allTokens) { if (isPosSuppressed(tok.pos)) continue; diff --git a/src/checkstyle/checks/block/RightCurlyCheck.hx b/src/checkstyle/checks/block/RightCurlyCheck.hx index 73b5cdb6..c309c91b 100644 --- a/src/checkstyle/checks/block/RightCurlyCheck.hx +++ b/src/checkstyle/checks/block/RightCurlyCheck.hx @@ -60,7 +60,7 @@ class RightCurlyCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var allBrClose:Array = root.filter([BrClose], ALL); + var allBrClose:Array = root.filter([BrClose], All); for (brClose in allBrClose) { if (isPosSuppressed(brClose.pos)) continue; @@ -68,13 +68,13 @@ class RightCurlyCheck extends Check { if ((brOpen == null) || (brOpen.pos == null)) continue; var type:BrOpenType = TokenTreeCheckUtils.getBrOpenType(brOpen); switch (type) { - case BLOCK: - case TYPEDEFDECL: + case Block: + case TypedefDecl: if (!hasToken(TYPEDEF_DEF)) continue; - case OBJECTDECL: + case ObjectDecl: if (!hasToken(OBJECT_DECL)) continue; - case ANONTYPE: - case UNKNOWN: + case AnonType: + case Unknown: } if (filterParentToken(brOpen.parent)) continue; check(brClose, type, isSingleLine(brOpen.pos.min, brClose.pos.max)); @@ -82,7 +82,7 @@ class RightCurlyCheck extends Check { } function filterParentToken(token:TokenTree):Bool { - if ((token == null) || (token.tok == null)) return false; + if ((token == null) || (token.tok == Root)) return false; switch (token.tok) { case Kwd(KwdClass): return !hasToken(CLASS_DEF); @@ -176,9 +176,9 @@ class RightCurlyCheck extends Check { var curlyAlone:Bool = false; switch (type) { - case BLOCK, TYPEDEFDECL, UNKNOWN: + case Block | TypedefDecl | Unknown: curlyAlone = ~/^\s*\}(|\..*|\).*|\].*|,\s*|;\s*)(|\/\/.*)$/.match(line); - case OBJECTDECL, ANONTYPE: + case ObjectDecl | AnonType: curlyAlone = ~/^\s*\}(|\..*|\).*|\].*|,.*|;\s*)(|\/\/.*)$/.match(line); } logErrorIf(!curlyAlone diff --git a/src/checkstyle/checks/coding/ArrowFunctionCheck.hx b/src/checkstyle/checks/coding/ArrowFunctionCheck.hx index 8c328990..108d2d4f 100644 --- a/src/checkstyle/checks/coding/ArrowFunctionCheck.hx +++ b/src/checkstyle/checks/coding/ArrowFunctionCheck.hx @@ -40,19 +40,19 @@ class ArrowFunctionCheck extends Check { var arrowTokens:Array = root.filterCallback(function(token:TokenTree, index:Int):FilterResult { return switch (token.tok) { case Arrow: - if (isPosSuppressed(token.pos)) SKIP_SUBTREE; - FOUND_GO_DEEPER; + if (isPosSuppressed(token.pos)) SkipSubtree; + FoundGoDeeper; default: - GO_DEEPER; + GoDeeper; } }); for (token in arrowTokens) { var type:ArrowType = TokenTreeCheckUtils.determineArrowType(token); switch (type) { - case ARROW_FUNCTION: + case ArrowFunction: checkArrowFunction(token); - case FUNCTION_TYPE_HAXE3, FUNCTION_TYPE_HAXE4: + case OldFunctionType | NewFunctionType: continue; } } @@ -66,8 +66,8 @@ class ArrowFunctionCheck extends Check { case BrOpen: var type:BrOpenType = TokenTreeCheckUtils.getBrOpenType(body); switch (type) { - case OBJECTDECL: - case BLOCK, TYPEDEFDECL, ANONTYPE, UNKNOWN: + case ObjectDecl: + case Block | TypedefDecl | AnonType | Unknown: logPos("Arrow function should not have curlies", body.getPos()); } default: @@ -76,23 +76,23 @@ class ArrowFunctionCheck extends Check { arrow.filterCallback(function(token:TokenTree, index:Int):FilterResult { switch (token.tok) { case Arrow: - if (token.index == arrow.index) return GO_DEEPER; - return SKIP_SUBTREE; + if (token.index == arrow.index) return GoDeeper; + return SkipSubtree; case Kwd(KwdFunction): - if (allowFunction) return SKIP_SUBTREE; + if (allowFunction) return SkipSubtree; logPos("Arrow function should not include nested functions", token.pos); - return SKIP_SUBTREE; + return SkipSubtree; case Kwd(KwdReturn): - if (allowReturn) return GO_DEEPER; + if (allowReturn) return GoDeeper; logPos("Arrow function should not have explicit returns", token.pos); - return SKIP_SUBTREE; + return SkipSubtree; default: - return GO_DEEPER; + return GoDeeper; } }); if (allowSingleArgParens) return; var parent:Null = arrow.parent; - if ((parent == null) || (parent.tok == null)) return; + if ((parent == null) || (parent.tok == Root)) return; if (!parent.is(POpen)) return; var count:Int = 0; for (child in parent.children) { diff --git a/src/checkstyle/checks/coding/CodeSimilarityCheck.hx b/src/checkstyle/checks/coding/CodeSimilarityCheck.hx index b2faff24..3d0b36c2 100644 --- a/src/checkstyle/checks/coding/CodeSimilarityCheck.hx +++ b/src/checkstyle/checks/coding/CodeSimilarityCheck.hx @@ -53,7 +53,7 @@ class CodeSimilarityCheck extends Check { case Kwd(KwdDo): skipSubTree = checkFunctionSimilarity(token); case Kwd(KwdWhile): - if ((token.parent != null) && (token.parent.is(Kwd(KwdDo)))) return SKIP_SUBTREE; + if ((token.parent != null) && (token.parent.is(Kwd(KwdDo)))) return SkipSubtree; skipSubTree = checkFunctionSimilarity(token); case Kwd(KwdTry): skipSubTree = checkFunctionSimilarity(token); @@ -64,9 +64,9 @@ class CodeSimilarityCheck extends Check { default: } if (skipSubTree) { - return SKIP_SUBTREE; + return SkipSubtree; } - return GO_DEEPER; + return GoDeeper; }); } diff --git a/src/checkstyle/checks/coding/DefaultComesLastCheck.hx b/src/checkstyle/checks/coding/DefaultComesLastCheck.hx index 0608d805..89c4bc46 100644 --- a/src/checkstyle/checks/coding/DefaultComesLastCheck.hx +++ b/src/checkstyle/checks/coding/DefaultComesLastCheck.hx @@ -15,10 +15,10 @@ class DefaultComesLastCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var acceptableTokens:Array = root.filter([Kwd(KwdSwitch)], ALL); + var acceptableTokens:Array = root.filter([Kwd(KwdSwitch)], All); for (token in acceptableTokens) { - var tokens:Array = token.filter([Kwd(KwdCase), Kwd(KwdDefault)], FIRST); + var tokens:Array = token.filter([Kwd(KwdCase), Kwd(KwdDefault)], First); if (tokens.length <= 0) continue; if (tokens[tokens.length - 1].is(Kwd(KwdDefault))) continue; diff --git a/src/checkstyle/checks/coding/HiddenFieldCheck.hx b/src/checkstyle/checks/coding/HiddenFieldCheck.hx index d660670d..65dd9ab3 100644 --- a/src/checkstyle/checks/coding/HiddenFieldCheck.hx +++ b/src/checkstyle/checks/coding/HiddenFieldCheck.hx @@ -35,14 +35,14 @@ class HiddenFieldCheck extends Check { override function actualRun() { var ignoreFormatRE:EReg = new EReg(ignoreFormat, ""); var root:TokenTree = checker.getTokenTree(); - checkClasses(root.filter([Kwd(KwdClass)], ALL), ignoreFormatRE); + checkClasses(root.filter([Kwd(KwdClass)], All), ignoreFormatRE); } function checkClasses(classes:Array, ignoreFormatRE:EReg) { for (clazz in classes) { if (isPosSuppressed(clazz.pos)) continue; var memberNames:Array = collectMemberNames(clazz); - var methods:Array = clazz.filter([Kwd(KwdFunction)], FIRST); + var methods:Array = clazz.filter([Kwd(KwdFunction)], First); for (method in methods) { if (isPosSuppressed(method.pos)) continue; checkMethod(method, memberNames, ignoreFormatRE); @@ -90,7 +90,7 @@ class HiddenFieldCheck extends Check { // |- POpen // |- parameters // |- PClose - var paramDef:Array = method.filter([POpen], FIRST, 2); + var paramDef:Array = method.filter([POpen], First, 2); if ((paramDef == null) || (paramDef.length != 1)) { throw "function parameters have invalid structure!"; } @@ -99,7 +99,7 @@ class HiddenFieldCheck extends Check { } function checkVars(method:TokenTree, memberNames:Array) { - var vars:Array = method.filter([Kwd(KwdVar)], ALL); + var vars:Array = method.filter([Kwd(KwdVar)], All); for (v in vars) { if (!v.hasChildren()) throw "var has invalid structure!"; checkName(v.children[0], memberNames, "Variable definition"); @@ -107,9 +107,9 @@ class HiddenFieldCheck extends Check { } function checkForLoops(method:TokenTree, memberNames:Array) { - var fors:Array = method.filter([Kwd(KwdFor)], ALL); + var fors:Array = method.filter([Kwd(KwdFor)], All); for (f in fors) { - var popens:Array = f.filter([POpen], FIRST, 2); + var popens:Array = f.filter([POpen], First, 2); if (popens.length <= 0) continue; var pOpen:TokenTree = popens[0]; if (!pOpen.hasChildren()) continue; @@ -135,7 +135,7 @@ class HiddenFieldCheck extends Check { // |- Kwd(KwdVar) // |- Kwd(KwdVar) // |- Kwd(KwdFunction) - var varFields:Array = clazz.filter([Kwd(KwdVar)], FIRST, MAX_FIELD_LEVEL); + var varFields:Array = clazz.filter([Kwd(KwdVar)], First, MAX_FIELD_LEVEL); for (member in varFields) { if (!member.hasChildren()) continue; switch (member.children[0].tok) { diff --git a/src/checkstyle/checks/coding/InnerAssignmentCheck.hx b/src/checkstyle/checks/coding/InnerAssignmentCheck.hx index 8dba6b23..38c0b489 100644 --- a/src/checkstyle/checks/coding/InnerAssignmentCheck.hx +++ b/src/checkstyle/checks/coding/InnerAssignmentCheck.hx @@ -32,7 +32,7 @@ class InnerAssignmentCheck extends Check { Binop(OpAssignOp(OpAnd)), Binop(OpAssignOp(OpOr)), Binop(OpAssignOp(OpXor)) - ], ALL); + ], All); for (assignToken in allAssignments) { if (isPosSuppressed(assignToken.pos) || !filterAssignment(assignToken)) continue; logPos("Inner assignment detected", assignToken.pos); @@ -40,7 +40,7 @@ class InnerAssignmentCheck extends Check { } function filterAssignment(token:TokenTree):Bool { - if ((token == null) || (token.tok == null)) return false; + if ((token == null) || (token.tok == Root)) return false; if (token.previousSibling != null) { // tokenizer does not treat >= as OpGte // creates OpGt and OpAssign instead @@ -58,7 +58,7 @@ class InnerAssignmentCheck extends Check { } function filterPOpen(token:TokenTree):Bool { - if ((token == null) || (token.tok == null)) return false; + if ((token == null) || (token.tok == Root)) return false; return switch (token.tok) { case Kwd(KwdFunction): false; case Kwd(KwdVar): false; @@ -78,12 +78,11 @@ class InnerAssignmentCheck extends Check { // - return is only statement inside block // - it is inside of setter function var allBinops:Array = token.filterCallback(function(token:TokenTree, depth:Int):FilterResult { - if (token.tok == null) return GO_DEEPER; return switch (token.tok) { - case Binop(_): FOUND_GO_DEEPER; - case Unop(_): FOUND_GO_DEEPER; - case POpen, BkOpen, BrOpen: FOUND_GO_DEEPER; - default: GO_DEEPER; + case Binop(_): FoundGoDeeper; + case Unop(_): FoundGoDeeper; + case POpen, BkOpen, BrOpen: FoundGoDeeper; + default: GoDeeper; } }); diff --git a/src/checkstyle/checks/coding/MagicNumberCheck.hx b/src/checkstyle/checks/coding/MagicNumberCheck.hx index ee8d2a6f..af52f771 100644 --- a/src/checkstyle/checks/coding/MagicNumberCheck.hx +++ b/src/checkstyle/checks/coding/MagicNumberCheck.hx @@ -26,7 +26,7 @@ class MagicNumberCheck extends Check { Kwd(KwdEnum), Kwd(KwdInterface), Kwd(KwdTypedef) - ], FIRST); + ], First); for (type in allTypes) { if (TokenTreeCheckUtils.isTypeEnumAbstract(type)) continue; checkForNumbers(type); @@ -35,11 +35,10 @@ class MagicNumberCheck extends Check { function checkForNumbers(parent:TokenTree) { var allNumbers:Array = parent.filterCallback(function(token:TokenTree, depth:Int):FilterResult { - if (token.tok == null) return GO_DEEPER; return switch (token.tok) { - case Const(CInt(_)): FOUND_GO_DEEPER; - case Const(CFloat(_)): FOUND_GO_DEEPER; - default: GO_DEEPER; + case Const(CInt(_)): FoundGoDeeper; + case Const(CFloat(_)): FoundGoDeeper; + default: GoDeeper; } }); @@ -61,7 +60,7 @@ class MagicNumberCheck extends Check { } function filterNumber(token:TokenTree):Bool { - if ((token == null) || (token.tok == null)) return false; + if ((token == null) || (token.tok == Root)) return false; return switch (token.tok) { case At: true; #if haxe4 @@ -70,7 +69,7 @@ class MagicNumberCheck extends Check { case Const(CIdent("final")): true; #end case BrOpen: false; - case Kwd(KwdVar): if (token.filter([Kwd(KwdStatic)], FIRST).length > 0) true; else false; + case Kwd(KwdVar): if (token.filter([Kwd(KwdStatic)], First).length > 0) true; else false; default: filterNumber(token.parent); } } diff --git a/src/checkstyle/checks/coding/MultipleVariableDeclarationsCheck.hx b/src/checkstyle/checks/coding/MultipleVariableDeclarationsCheck.hx index 73b3f956..b071e25a 100644 --- a/src/checkstyle/checks/coding/MultipleVariableDeclarationsCheck.hx +++ b/src/checkstyle/checks/coding/MultipleVariableDeclarationsCheck.hx @@ -14,7 +14,7 @@ class MultipleVariableDeclarationsCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var acceptableTokens:Array = root.filter([Kwd(KwdVar)], ALL); + var acceptableTokens:Array = root.filter([Kwd(KwdVar)], All); var lastVarLineNo = -1; for (v in acceptableTokens) { diff --git a/src/checkstyle/checks/coding/NestedControlFlowCheck.hx b/src/checkstyle/checks/coding/NestedControlFlowCheck.hx index f33e154f..a65aa427 100644 --- a/src/checkstyle/checks/coding/NestedControlFlowCheck.hx +++ b/src/checkstyle/checks/coding/NestedControlFlowCheck.hx @@ -23,19 +23,19 @@ class NestedControlFlowCheck extends Check { var controlFlowTokens:Array = root.filterCallback(function(token:TokenTree, index:Int):FilterResult { return switch (token.tok) { case Kwd(KwdFor): - FOUND_GO_DEEPER; + FoundGoDeeper; case Kwd(KwdIf): - FOUND_GO_DEEPER; + FoundGoDeeper; case Kwd(KwdSwitch): - FOUND_GO_DEEPER; + FoundGoDeeper; case Kwd(KwdDo): - FOUND_GO_DEEPER; + FoundGoDeeper; case Kwd(KwdWhile): - if ((token.parent != null) && (token.parent.is(Kwd(KwdDo)))) GO_DEEPER; else FOUND_GO_DEEPER; + if ((token.parent != null) && (token.parent.is(Kwd(KwdDo)))) GoDeeper; else FoundGoDeeper; case Kwd(KwdTry): - FOUND_GO_DEEPER; + FoundGoDeeper; default: - GO_DEEPER; + GoDeeper; } }); for (token in controlFlowTokens) { @@ -52,7 +52,7 @@ class NestedControlFlowCheck extends Check { function calcDepth(token:TokenTree):Int { var parent:TokenTree = token.parent; var count:Int = 1; - while ((parent != null) && (parent.tok != null)) { + while ((parent != null) && (parent.tok != Root)) { switch (parent.tok) { case Kwd(KwdFor): count++; diff --git a/src/checkstyle/checks/coding/ReturnCountCheck.hx b/src/checkstyle/checks/coding/ReturnCountCheck.hx index ba3588d1..68223491 100644 --- a/src/checkstyle/checks/coding/ReturnCountCheck.hx +++ b/src/checkstyle/checks/coding/ReturnCountCheck.hx @@ -29,7 +29,7 @@ class ReturnCountCheck extends Check { override function actualRun() { var ignoreFormatRE:EReg = new EReg(ignoreFormat, ""); var root:TokenTree = checker.getTokenTree(); - var functions = root.filter([Kwd(KwdFunction)], ALL); + var functions = root.filter([Kwd(KwdFunction)], All); for (fn in functions) { if (fn.children == null) continue; switch (fn.getFirstChild().tok) { @@ -50,9 +50,9 @@ class ReturnCountCheck extends Check { return switch (token.tok) { case Kwd(KwdFunction): // top node is always a function node - if (depth == 0) GO_DEEPER; else SKIP_SUBTREE; - case Kwd(KwdReturn): FOUND_SKIP_SUBTREE; - default: GO_DEEPER; + if (depth == 0) GoDeeper; else SkipSubtree; + case Kwd(KwdReturn): FoundSkipSubtree; + default: GoDeeper; } } diff --git a/src/checkstyle/checks/coding/SimplifyBooleanExpressionCheck.hx b/src/checkstyle/checks/coding/SimplifyBooleanExpressionCheck.hx index b8e30912..1e13a4d1 100644 --- a/src/checkstyle/checks/coding/SimplifyBooleanExpressionCheck.hx +++ b/src/checkstyle/checks/coding/SimplifyBooleanExpressionCheck.hx @@ -24,7 +24,7 @@ class SimplifyBooleanExpressionCheck extends Check { Binop(OpAnd), Binop(OpBoolOr), Binop(OpBoolAnd) - ], ALL); + ], All); for (token in acceptableTokens) { if (isPosSuppressed(token.pos)) continue; diff --git a/src/checkstyle/checks/coding/SimplifyBooleanReturnCheck.hx b/src/checkstyle/checks/coding/SimplifyBooleanReturnCheck.hx index 90d258bd..0af19b33 100644 --- a/src/checkstyle/checks/coding/SimplifyBooleanReturnCheck.hx +++ b/src/checkstyle/checks/coding/SimplifyBooleanReturnCheck.hx @@ -14,10 +14,10 @@ class SimplifyBooleanReturnCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var acceptableTokens:Array = root.filter([Kwd(KwdIf)], ALL); + var acceptableTokens:Array = root.filter([Kwd(KwdIf)], All); for (token in acceptableTokens) { - var elseLiteral = token.filter([Kwd(KwdElse)], FIRST)[0]; + var elseLiteral = token.filter([Kwd(KwdElse)], First)[0]; if (elseLiteral == null) continue; var elseStatement = elseLiteral.getFirstChild(); diff --git a/src/checkstyle/checks/coding/TraceCheck.hx b/src/checkstyle/checks/coding/TraceCheck.hx index 00aeacee..e49a685b 100644 --- a/src/checkstyle/checks/coding/TraceCheck.hx +++ b/src/checkstyle/checks/coding/TraceCheck.hx @@ -13,7 +13,7 @@ class TraceCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var traces = root.filter([Const(CIdent("trace"))], ALL); + var traces = root.filter([Const(CIdent("trace"))], All); for (tr in traces) { if (!tr.getFirstChild().tok.match(POpen)) continue; if (filterTrace(tr.parent)) continue; diff --git a/src/checkstyle/checks/coding/UnusedLocalVarCheck.hx b/src/checkstyle/checks/coding/UnusedLocalVarCheck.hx index 42e7e9b1..419f8b8c 100644 --- a/src/checkstyle/checks/coding/UnusedLocalVarCheck.hx +++ b/src/checkstyle/checks/coding/UnusedLocalVarCheck.hx @@ -14,21 +14,21 @@ class UnusedLocalVarCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var functions:Array = root.filter([Kwd(KwdFunction)], ALL); + var functions:Array = root.filter([Kwd(KwdFunction)], All); for (f in functions) { if (isPosSuppressed(f.pos)) continue; var skipFirstFunction:Bool = true; var localVars:Array = f.filterCallback(function(tok:TokenTree, depth:Int):FilterResult { return switch (tok.tok) { - case Kwd(KwdVar): FOUND_SKIP_SUBTREE; + case Kwd(KwdVar): FoundSkipSubtree; case Kwd(KwdFunction): if (skipFirstFunction) { skipFirstFunction = false; - GO_DEEPER; + GoDeeper; } - else SKIP_SUBTREE; - default: GO_DEEPER; + else SkipSubtree; + default: GoDeeper; } }); checkLocalVars(f, localVars); @@ -53,26 +53,26 @@ class UnusedLocalVarCheck extends Check { if (ignoreFunctionSignature) { switch (tok.tok) { case Kwd(KwdPublic), Kwd(KwdPrivate): - return SKIP_SUBTREE; + return SkipSubtree; case At: - return SKIP_SUBTREE; + return SkipSubtree; case Comment(_), CommentLine(_): - return SKIP_SUBTREE; + return SkipSubtree; case POpen: ignoreFunctionSignature = false; - return SKIP_SUBTREE; + return SkipSubtree; default: - return GO_DEEPER; + return GoDeeper; } } return switch (tok.tok) { case Dollar(n): - if (n == name) FOUND_GO_DEEPER; else GO_DEEPER; + if (n == name) FoundGoDeeper; else GoDeeper; case Const(CIdent(n)): - if (n == name) FOUND_GO_DEEPER; else GO_DEEPER; + if (n == name) FoundGoDeeper; else GoDeeper; case Const(CString(s)): checkStringInterpolation(tok, name, s); - default: GO_DEEPER; + default: GoDeeper; } }); if (nameList.length > 1) return; @@ -82,23 +82,23 @@ class UnusedLocalVarCheck extends Check { function checkStringInterpolation(tok:TokenTree, name:String, s:String):FilterResult { if (!StringUtils.isStringInterpolation(s, checker.file.content, tok.pos)) { - return GO_DEEPER; + return GoDeeper; } // $name var format:String = "\\$" + name + "([^_0-9a-zA-Z]|$)"; var r:EReg = new EReg(format, ""); if (r.match(s)) { - return FOUND_GO_DEEPER; + return FoundGoDeeper; } // '${name.doSomething()} or ${doSomething(name)} or ${name} format = "\\$\\{(|.*[^_0-9a-zA-Z])" + name + "([^_0-9a-zA-Z].*|)\\}"; r = new EReg(format, ""); if (r.match(s)) { - return FOUND_GO_DEEPER; + return FoundGoDeeper; } - return GO_DEEPER; + return GoDeeper; } override public function detectableInstances():DetectableInstances { diff --git a/src/checkstyle/checks/comments/DocCommentStyleCheck.hx b/src/checkstyle/checks/comments/DocCommentStyleCheck.hx index 0decd553..40bbb248 100644 --- a/src/checkstyle/checks/comments/DocCommentStyleCheck.hx +++ b/src/checkstyle/checks/comments/DocCommentStyleCheck.hx @@ -40,7 +40,7 @@ class DocCommentStyleCheck extends Check { Kwd(KwdVar), #if haxe4 Kwd(KwdFinal) #else Const(CIdent("final")) #end, Kwd(KwdFunction) - ], ALL); + ], All); for (token in docTokens) { if (isPosSuppressed(token.pos)) continue; diff --git a/src/checkstyle/checks/comments/FieldDocCommentCheck.hx b/src/checkstyle/checks/comments/FieldDocCommentCheck.hx index 018960e8..f30dfa9b 100644 --- a/src/checkstyle/checks/comments/FieldDocCommentCheck.hx +++ b/src/checkstyle/checks/comments/FieldDocCommentCheck.hx @@ -72,15 +72,15 @@ class FieldDocCommentCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var typeTokenDefs:Array = []; + var typeTokenDefs:Array = []; if (hasToken(ABSTRACT_DEF)) typeTokenDefs.push(Kwd(KwdAbstract)); if (hasToken(CLASS_DEF)) typeTokenDefs.push(Kwd(KwdClass)); if (hasToken(ENUM_DEF)) typeTokenDefs.push(Kwd(KwdEnum)); if (hasToken(INTERFACE_DEF)) typeTokenDefs.push(Kwd(KwdInterface)); if (hasToken(TYPEDEF_DEF)) typeTokenDefs.push(Kwd(KwdTypedef)); - var typeTokens = root.filter(typeTokenDefs, ALL); + var typeTokens = root.filter(typeTokenDefs, All); - var fieldTokenDefs:Array = []; + var fieldTokenDefs:Array = []; if ((fieldType == VARS) || (fieldType == BOTH)) { fieldTokenDefs.push(Kwd(KwdVar)); #if haxe4 @@ -93,7 +93,7 @@ class FieldDocCommentCheck extends Check { for (typeToken in typeTokens) { if (isPosSuppressed(typeToken.pos)) continue; - var fieldTokens:Array = typeToken.filter(fieldTokenDefs, FIRST); + var fieldTokens:Array = typeToken.filter(fieldTokenDefs, First); for (token in fieldTokens) { checkField(token, isDefaultPublic(typeToken)); } @@ -134,14 +134,14 @@ class FieldDocCommentCheck extends Check { function checkIgnoreOverride(token:TokenTree):Bool { if (!ignoreOverride) return false; - var ignoreTokens:Array = token.filter([Kwd(KwdOverride)], FIRST); + var ignoreTokens:Array = token.filter([Kwd(KwdOverride)], First); return (ignoreTokens.length > 0); } function matchesModifier(token:TokenTree, defaultPublic:Bool):Bool { if (modifier == BOTH) return true; - var modifierList:Array = token.filter([Kwd(KwdPublic), Kwd(KwdPrivate)], FIRST); + var modifierList:Array = token.filter([Kwd(KwdPublic), Kwd(KwdPrivate)], First); var isPublic:Bool = defaultPublic; for (modToken in modifierList) { switch (modToken.tok) { diff --git a/src/checkstyle/checks/comments/TypeDocCommentCheck.hx b/src/checkstyle/checks/comments/TypeDocCommentCheck.hx index 8afb09d1..f6778b3d 100644 --- a/src/checkstyle/checks/comments/TypeDocCommentCheck.hx +++ b/src/checkstyle/checks/comments/TypeDocCommentCheck.hx @@ -27,13 +27,13 @@ class TypeDocCommentCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var tokenList:Array = []; + var tokenList:Array = []; if (hasToken(ABSTRACT_DEF)) tokenList.push(Kwd(KwdAbstract)); if (hasToken(CLASS_DEF)) tokenList.push(Kwd(KwdClass)); if (hasToken(ENUM_DEF)) tokenList.push(Kwd(KwdEnum)); if (hasToken(INTERFACE_DEF)) tokenList.push(Kwd(KwdInterface)); if (hasToken(TYPEDEF_DEF)) tokenList.push(Kwd(KwdTypedef)); - var docTokens = root.filter(tokenList, ALL); + var docTokens = root.filter(tokenList, All); for (token in docTokens) { if (isPosSuppressed(token.pos)) continue; var name:String = getTypeName(token); @@ -77,7 +77,7 @@ class TypeDocCommentCheck extends Check { Kwd(KwdTypedef), Kwd(KwdImport), Kwd(KwdUsing) - ], FIRST); + ], First); if (notAllowed.length > 0) { return null; } diff --git a/src/checkstyle/checks/design/EmptyPackageCheck.hx b/src/checkstyle/checks/design/EmptyPackageCheck.hx index d63e1b97..b4556ff8 100644 --- a/src/checkstyle/checks/design/EmptyPackageCheck.hx +++ b/src/checkstyle/checks/design/EmptyPackageCheck.hx @@ -18,7 +18,7 @@ class EmptyPackageCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var packageTokens = root.filter([Kwd(KwdPackage)], ALL); + var packageTokens = root.filter([Kwd(KwdPackage)], All); if (enforceEmptyPackage) { if (packageTokens.length == 0) log("Missing package declaration", 1, 0, 1, 0, MISSING_PACKAGE); } diff --git a/src/checkstyle/checks/design/InterfaceCheck.hx b/src/checkstyle/checks/design/InterfaceCheck.hx index 1513f3d7..3f2b4a9a 100644 --- a/src/checkstyle/checks/design/InterfaceCheck.hx +++ b/src/checkstyle/checks/design/InterfaceCheck.hx @@ -26,10 +26,10 @@ class InterfaceCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var interfaces:Array = root.filter([Kwd(KwdInterface)], ALL); + var interfaces:Array = root.filter([Kwd(KwdInterface)], All); for (intr in interfaces) { - var functions:Array = intr.filter([Kwd(KwdFunction)], ALL); - var vars:Array = intr.filter([Kwd(KwdVar)], ALL); + var functions:Array = intr.filter([Kwd(KwdFunction)], All); + var vars:Array = intr.filter([Kwd(KwdVar)], All); if (functions.length == 0 && vars.length == 0) { if (allowMarkerInterfaces) continue; diff --git a/src/checkstyle/checks/design/UnnecessaryConstructorCheck.hx b/src/checkstyle/checks/design/UnnecessaryConstructorCheck.hx index f3a9dae7..100cf075 100644 --- a/src/checkstyle/checks/design/UnnecessaryConstructorCheck.hx +++ b/src/checkstyle/checks/design/UnnecessaryConstructorCheck.hx @@ -14,26 +14,26 @@ class UnnecessaryConstructorCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var classes:Array = root.filter([Kwd(KwdClass)], ALL); + var classes:Array = root.filter([Kwd(KwdClass)], All); for (cls in classes) { if (extendsBaseClass(cls)) { continue; } if (isPosSuppressed(cls.pos)) continue; - var acceptableTokens:Array = cls.filter([Kwd(KwdFunction), Kwd(KwdVar)], FIRST); + var acceptableTokens:Array = cls.filter([Kwd(KwdFunction), Kwd(KwdVar)], First); var haveConstructor:Bool = false; var staticTokens:Int = 0; var constructorPos = null; for (token in acceptableTokens) { - if (token.filter([Kwd(KwdNew)], FIRST, 2).length > 0) { + if (token.filter([Kwd(KwdNew)], First, 2).length > 0) { haveConstructor = true; constructorPos = token.getPos(); continue; } - if (token.filter([Kwd(KwdStatic)], FIRST, 2).length > 0) { + if (token.filter([Kwd(KwdStatic)], First, 2).length > 0) { staticTokens++; continue; } diff --git a/src/checkstyle/checks/imports/AvoidStarImportCheck.hx b/src/checkstyle/checks/imports/AvoidStarImportCheck.hx index 1b31c493..7f8cc67d 100644 --- a/src/checkstyle/checks/imports/AvoidStarImportCheck.hx +++ b/src/checkstyle/checks/imports/AvoidStarImportCheck.hx @@ -14,12 +14,12 @@ class AvoidStarImportCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - checkImports(root.filter([Kwd(KwdImport)], ALL)); + checkImports(root.filter([Kwd(KwdImport)], All)); } function checkImports(importEntries:Array) { for (entry in importEntries) { - var stars:Array = entry.filter([Binop(OpMult)], ALL); + var stars:Array = entry.filter([Binop(OpMult)], All); if (stars.length <= 0) continue; logPos('Using the ".*" form of import should be avoided', entry.getPos()); } diff --git a/src/checkstyle/checks/imports/UnusedImportCheck.hx b/src/checkstyle/checks/imports/UnusedImportCheck.hx index 7cac6f0f..1af192c5 100644 --- a/src/checkstyle/checks/imports/UnusedImportCheck.hx +++ b/src/checkstyle/checks/imports/UnusedImportCheck.hx @@ -1,7 +1,7 @@ package checkstyle.checks.imports; -import tokentree.utils.TokenTreeCheckUtils; import haxe.io.Path; +import tokentree.utils.TokenTreeCheckUtils; /** Checks for unused or duplicate imports. @@ -33,24 +33,24 @@ class UnusedImportCheck extends Check { if (isImportHx()) return; var root:TokenTree = checker.getTokenTree(); var packageName:String = detectPackageName(root); - var imports:Array = root.filter([Kwd(KwdImport)], ALL); + var imports:Array = root.filter([Kwd(KwdImport)], All); var idents:Array = root.filterCallback(function(token:TokenTree, depth:Int):FilterResult { switch (token.tok) { case Const(CIdent(_)): - if (TokenTreeCheckUtils.isImport(token)) return GO_DEEPER; - return FOUND_GO_DEEPER; + if (TokenTreeCheckUtils.isImport(token)) return GoDeeper; + return FoundGoDeeper; default: } - return GO_DEEPER; + return GoDeeper; }); var stringLiterals:Array = root.filterCallback(function(token:TokenTree, depth:Int):FilterResult { switch (token.tok) { case Const(CString(text)): - if (checker.getString(token.pos.min, token.pos.min + 1) != "'") return GO_DEEPER; - if (~/\$\{[^\}]+\.[^\}]+\}/.match(text)) return FOUND_GO_DEEPER; + if (checker.getString(token.pos.min, token.pos.min + 1) != "'") return GoDeeper; + if (~/\$\{[^\}]+\.[^\}]+\}/.match(text)) return FoundGoDeeper; default: } - return GO_DEEPER; + return GoDeeper; }); for (imp in imports) { var typeName:String = detectTypeName(imp); @@ -83,7 +83,7 @@ class UnusedImportCheck extends Check { } function detectPackageName(root:TokenTree):String { - var packageToken:Array = root.filter([Kwd(KwdPackage)], ALL); + var packageToken:Array = root.filter([Kwd(KwdPackage)], All); if ((packageToken == null) || (packageToken.length <= 0)) return null; var packageName:String = detectModuleName(packageToken[0]); diff --git a/src/checkstyle/checks/literal/MultipleStringLiteralsCheck.hx b/src/checkstyle/checks/literal/MultipleStringLiteralsCheck.hx index 2748e8ff..302702d4 100644 --- a/src/checkstyle/checks/literal/MultipleStringLiteralsCheck.hx +++ b/src/checkstyle/checks/literal/MultipleStringLiteralsCheck.hx @@ -41,10 +41,9 @@ class MultipleStringLiteralsCheck extends Check { var allLiterals:Map = new Map(); var allStringLiterals:Array = root.filterCallback(function(token:TokenTree, depth:Int):FilterResult { - if (token.tok == null) return GO_DEEPER; return switch (token.tok) { - case Const(CString(_)): FOUND_GO_DEEPER; - default: GO_DEEPER; + case Const(CString(_)): FoundGoDeeper; + default: GoDeeper; } }); @@ -74,10 +73,10 @@ class MultipleStringLiteralsCheck extends Check { } function filterLiteral(token:TokenTree):Bool { - if ((token == null) || (token.tok == null)) return true; + if ((token == null) || (token.tok == Root)) return true; return switch (token.tok) { case At: false; - case Kwd(KwdVar): !(token.filter([Kwd(KwdStatic)], FIRST).length > 0); + case Kwd(KwdVar): !(token.filter([Kwd(KwdStatic)], First).length > 0); default: filterLiteral(token.parent); } } diff --git a/src/checkstyle/checks/literal/StringLiteralCheck.hx b/src/checkstyle/checks/literal/StringLiteralCheck.hx index c0b0065f..d88cdb52 100644 --- a/src/checkstyle/checks/literal/StringLiteralCheck.hx +++ b/src/checkstyle/checks/literal/StringLiteralCheck.hx @@ -33,10 +33,9 @@ class StringLiteralCheck extends Check { var root:TokenTree = checker.getTokenTree(); var allStringLiterals:Array = root.filterCallback(function(token:TokenTree, depth:Int):FilterResult { - if (token.tok == null) return GO_DEEPER; return switch (token.tok) { - case Const(CString(_)): FOUND_GO_DEEPER; - default: GO_DEEPER; + case Const(CString(_)): FoundGoDeeper; + default: GoDeeper; } }); diff --git a/src/checkstyle/checks/meta/RedundantAccessMetaBase.hx b/src/checkstyle/checks/meta/RedundantAccessMetaBase.hx index fdbeb503..4f7b3c0f 100644 --- a/src/checkstyle/checks/meta/RedundantAccessMetaBase.hx +++ b/src/checkstyle/checks/meta/RedundantAccessMetaBase.hx @@ -22,7 +22,7 @@ class RedundantAccessMetaBase extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var docTokens = root.filter([At], ALL); + var docTokens = root.filter([At], All); var infos:Array = []; diff --git a/src/checkstyle/checks/naming/CatchParameterNameCheck.hx b/src/checkstyle/checks/naming/CatchParameterNameCheck.hx index 3f2b3b85..d7d4caa0 100644 --- a/src/checkstyle/checks/naming/CatchParameterNameCheck.hx +++ b/src/checkstyle/checks/naming/CatchParameterNameCheck.hx @@ -19,7 +19,7 @@ class CatchParameterNameCheck extends Check { override function actualRun() { var formatRE = new EReg(format, ""); var root:TokenTree = checker.getTokenTree(); - var catchTokens = root.filter([Kwd(KwdCatch)], ALL); + var catchTokens = root.filter([Kwd(KwdCatch)], All); for (tkn in catchTokens) { for (item in tkn.children) { diff --git a/src/checkstyle/checks/size/MethodCountCheck.hx b/src/checkstyle/checks/size/MethodCountCheck.hx index 5b4033af..26086ed8 100644 --- a/src/checkstyle/checks/size/MethodCountCheck.hx +++ b/src/checkstyle/checks/size/MethodCountCheck.hx @@ -34,7 +34,7 @@ class MethodCountCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var acceptableTokens:Array = root.filter([Kwd(KwdFunction)], FIRST); + var acceptableTokens:Array = root.filter([Kwd(KwdFunction)], First); if (acceptableTokens.length > maxTotal) { logPos('Total number of methods is ${acceptableTokens.length} (max allowed is $maxTotal)', acceptableTokens[maxTotal].pos); @@ -44,7 +44,7 @@ class MethodCountCheck extends Check { var privateTokens = []; var publicTokens = []; for (token in acceptableTokens) { - if (token.filter([Kwd(KwdPublic)], FIRST).length > 0) publicTokens.push(token); + if (token.filter([Kwd(KwdPublic)], First).length > 0) publicTokens.push(token); else privateTokens.push(token); } diff --git a/src/checkstyle/checks/size/MethodLengthCheck.hx b/src/checkstyle/checks/size/MethodLengthCheck.hx index e22d4566..c7e451c1 100755 --- a/src/checkstyle/checks/size/MethodLengthCheck.hx +++ b/src/checkstyle/checks/size/MethodLengthCheck.hx @@ -32,7 +32,7 @@ class MethodLengthCheck extends Check { override public function actualRun() { var root:TokenTree = checker.getTokenTree(); - var functions:Array = root.filter([Kwd(KwdFunction)], FIRST); + var functions:Array = root.filter([Kwd(KwdFunction)], First); var emptyLines:ListOfEmptyLines = ListOfEmptyLines.detectEmptyLines(checker); for (func in functions) { diff --git a/src/checkstyle/checks/type/AvoidIdentifierCheck.hx b/src/checkstyle/checks/type/AvoidIdentifierCheck.hx index 00608b40..bf8e5872 100644 --- a/src/checkstyle/checks/type/AvoidIdentifierCheck.hx +++ b/src/checkstyle/checks/type/AvoidIdentifierCheck.hx @@ -24,7 +24,7 @@ class AvoidIdentifierCheck extends Check { checkIdent(ident, token); default: } - return GO_DEEPER; + return GoDeeper; }); } diff --git a/src/checkstyle/checks/type/DynamicCheck.hx b/src/checkstyle/checks/type/DynamicCheck.hx index 02ff2603..4f295bc1 100644 --- a/src/checkstyle/checks/type/DynamicCheck.hx +++ b/src/checkstyle/checks/type/DynamicCheck.hx @@ -17,11 +17,11 @@ class DynamicCheck extends Check { root.filterCallback(function(token:TokenTree, index:Int):FilterResult { switch token.tok { case Const(CIdent("Dynamic")): - if (isPosSuppressed(token.pos)) return SKIP_SUBTREE; + if (isPosSuppressed(token.pos)) return SkipSubtree; logPos('Avoid using "Dynamic" as type', token.pos); - return SKIP_SUBTREE; + return SkipSubtree; default: - return GO_DEEPER; + return GoDeeper; } }); } diff --git a/src/checkstyle/checks/type/EnforceVarTypeHintCheck.hx b/src/checkstyle/checks/type/EnforceVarTypeHintCheck.hx deleted file mode 100644 index 93b7dfd0..00000000 --- a/src/checkstyle/checks/type/EnforceVarTypeHintCheck.hx +++ /dev/null @@ -1,76 +0,0 @@ -package checkstyle.checks.type; - -/** - Checks if type is specified or not for member variables. -**/ -@name("EnforceVarTypeHint") -@desc("Checks if all variables have type hint.") -class EnforceVarTypeHintCheck extends Check { - /** - ignores fields inside abstract enums - **/ - public var ignoreEnumAbstractValues:Bool; - - public function new() { - super(TOKEN); - ignoreEnumAbstractValues = true; - categories = [CLARITY, BUG_RISK]; - } - - override function actualRun() { - var root:TokenTree = checker.getTokenTree(); - root.filterCallback(function(token:TokenTree, index:Int):FilterResult { - switch (token.tok) { - #if haxe4 - case Kwd(KwdFinal): - checkVar(token); - return SKIP_SUBTREE; - #else - case Const(CIdent("final")): - checkVar(token); - return SKIP_SUBTREE; - #end - case Kwd(KwdVar): - checkVar(token); - return SKIP_SUBTREE; - default: - return GO_DEEPER; - } - }); - } - - function checkVar(token:TokenTree) { - if (isPosSuppressed(token.pos)) return; - var name:Null = token.access().firstChild().token; - if (name == null) return; - var colon:Null = name.access().firstOf(DblDot).token; - if (colon != null) return; - if (ignoreEnumAbstractValues && isEnumAbstractValue(token)) return; - error(name.toString(), name.pos); - } - - function isEnumAbstractValue(token:TokenTree):Bool { - var parent:Null = token.parent; - while ((parent != null) && (parent.tok != null)) { - switch (parent.tok) { - case Kwd(KwdAbstract): - return TokenTreeCheckUtils.isTypeEnumAbstract(parent); - case Kwd(KwdInterface): - return false; - case Kwd(KwdClass): - return false; - case Kwd(KwdEnum): - return false; - case Kwd(KwdTypedef): - return false; - default: - } - parent = parent.parent; - } - return false; - } - - function error(name:String, pos:Position) { - logPos('Variable "${name}" has no type hint', pos); - } -} \ No newline at end of file diff --git a/src/checkstyle/checks/type/VarTypeHintCheck.hx b/src/checkstyle/checks/type/VarTypeHintCheck.hx new file mode 100644 index 00000000..30e510b5 --- /dev/null +++ b/src/checkstyle/checks/type/VarTypeHintCheck.hx @@ -0,0 +1,150 @@ +package checkstyle.checks.type; + +/** + Checks if type is specified or not for member variables. +**/ +@name("VarTypeHint", "EnforceVarTypeHint") +@desc("Checks type hints of variables.") +class VarTypeHintCheck extends Check { + /** + policy for type hints on var and final + **/ + public var typeHintPolicy:VarTypeHintPolicy; + + /** + ignores fields inside abstract enums + **/ + public var ignoreEnumAbstractValues:Bool; + + public function new() { + super(TOKEN); + typeHintPolicy = INFER_NEW_OR_CONST; + ignoreEnumAbstractValues = true; + categories = [CLARITY, BUG_RISK]; + } + + override function actualRun() { + var root:TokenTree = checker.getTokenTree(); + var varList:Array = root.filterCallback(function(token:TokenTree, index:Int):FilterResult { + return switch (token.tok) { + #if haxe4 + case Kwd(KwdFinal): + FoundSkipSubtree; + #else + case Const(CIdent("final")): + FoundSkipSubtree; + #end + case Kwd(KwdVar): + FoundSkipSubtree; + default: + return GoDeeper; + } + }); + for (v in varList) { + checkVar(v); + } + } + + function checkVar(token:TokenTree) { + if (isPosSuppressed(token.pos)) return; + if (!token.hasChildren()) return; + + for (child in token.children) { + checkVarName(child); + } + } + + function checkVarName(name:TokenTree) { + if (ignoreEnumAbstractValues && isEnumAbstractValue(name)) return; + switch (name.tok) { + case Root: + return; + case Question: + checkVarName(name.getFirstChild()); + return; + default: + } + var colon:Null = name.access().firstOf(DblDot).token; + var opAssign:Null = name.access().firstOf(Binop(OpAssign)).token; + var hasNewOrConst:Bool = detectNewOrConst(opAssign); + switch (typeHintPolicy) { + case ENFORCE_ALL: + if (colon == null) needsTypeHint(name.toString(), name.pos); + + case INFER_NEW_OR_CONST if (opAssign == null): + if (colon != null) return; + needsTypeHint(name.toString(), name.pos); + case INFER_NEW_OR_CONST if (colon == null): + if (hasNewOrConst) return; + needsTypeHint(name.toString(), name.pos); + case INFER_NEW_OR_CONST: + if (!hasNewOrConst) return; + noTypeHintNeeded(name.toString(), name.pos); + + case INFER_ALL if (opAssign == null): + if (colon != null) return; + needsTypeHint(name.toString(), name.pos); + case INFER_ALL: + if (colon != null) noTypeHintNeeded(name.toString(), name.pos); + } + } + + function detectNewOrConst(token:TokenTree):Bool { + if (token == null) return false; + for (child in token.children) { + switch (child.tok) { + case Const(CString(_)) | Const(CInt(_)) | Const(CFloat(_)) | Const(CRegexp(_)): + return true; + case Kwd(KwdTrue) | Kwd(KwdFalse): + return true; + case Kwd(KwdNew): + return true; + case Semicolon: + return false; + default: + } + } + return false; + } + + function isEnumAbstractValue(token:TokenTree):Bool { + var parent:Null = token.parent; + while ((parent != null) && (parent.tok != Root)) { + switch (parent.tok) { + case Kwd(KwdAbstract): + return TokenTreeCheckUtils.isTypeEnumAbstract(parent); + case Kwd(KwdInterface): + return false; + case Kwd(KwdClass): + return false; + case Kwd(KwdEnum): + return false; + case Kwd(KwdTypedef): + return false; + default: + } + parent = parent.parent; + } + return false; + } + + function needsTypeHint(name:String, pos:Position) { + logPos('"${name}" should have a type hint', pos); + } + + function noTypeHintNeeded(name:String, pos:Position) { + logPos('"${name}" type hint not needed', pos); + } +} + +/** + enforce_all = var / final require a type hint + infer_new_or_const = var / final require a type hint unless you assign a number, a string or new + infer_all = var / final only require a type hint if you do not assign anything +**/ +@:enum +abstract VarTypeHintPolicy(String) { + var ENFORCE_ALL = "enforce_all"; + var INFER_NEW_OR_CONST = "infer_new_or_const"; + var INFER_ALL = "infer_all"; +} \ No newline at end of file diff --git a/src/checkstyle/checks/whitespace/ExtendedEmptyLinesCheck.hx b/src/checkstyle/checks/whitespace/ExtendedEmptyLinesCheck.hx index b3386e8a..f84df11c 100644 --- a/src/checkstyle/checks/whitespace/ExtendedEmptyLinesCheck.hx +++ b/src/checkstyle/checks/whitespace/ExtendedEmptyLinesCheck.hx @@ -4,8 +4,7 @@ import checkstyle.checks.whitespace.ListOfEmptyLines.EmptyLineRange; /** Checks for consecutive empty lines. -**/ -@name("ExtendedEmptyLines") +**/ @name("ExtendedEmptyLines") @desc("Checks for consecutive empty lines.") class ExtendedEmptyLinesCheck extends Check { /** @@ -103,7 +102,7 @@ class ExtendedEmptyLinesCheck extends Check { if (isIgnored([BEFORE_PACKAGE, AFTER_PACKAGE])) return; var root:TokenTree = checker.getTokenTree(); - var packages:Array = root.filter([Kwd(KwdPackage)], ALL); + var packages:Array = root.filter([Kwd(KwdPackage)], All); for (pack in packages) { checkBetweenToken(emptyLines, null, pack, getPolicy(BEFORE_PACKAGE), "before package"); @@ -115,7 +114,7 @@ class ExtendedEmptyLinesCheck extends Check { if (isIgnored([AFTER_IMPORTS, BEFORE_USING, BETWEEN_IMPORTS])) return; var root:TokenTree = checker.getTokenTree(); - var imports:Array = root.filter([Kwd(KwdImport), Kwd(KwdUsing)], ALL); + var imports:Array = root.filter([Kwd(KwdImport), Kwd(KwdUsing)], All); if (imports.length <= 0) return; @@ -160,7 +159,7 @@ class ExtendedEmptyLinesCheck extends Check { Kwd(KwdEnum), Kwd(KwdInterface), Kwd(KwdTypedef) - ], FIRST); + ], First); if (types.length <= 0) return; @@ -295,8 +294,8 @@ class ExtendedEmptyLinesCheck extends Check { if (isVarChild && (type == FUNCTION)) return makePolicyAndWhat(getPolicy(AFTER_CLASS_VARS), "after class vars"); if (isFuncChild && (type == VAR)) return makePolicyAndWhat(getPolicy(AFTER_CLASS_VARS), "after class vars"); - var isStaticChild:Bool = (child.filter([Kwd(KwdStatic)], FIRST).length > 0); - var isStaticNext:Bool = (next.filter([Kwd(KwdStatic)], FIRST).length > 0); + var isStaticChild:Bool = (child.filter([Kwd(KwdStatic)], First).length > 0); + var isStaticNext:Bool = (next.filter([Kwd(KwdStatic)], First).length > 0); if (isStaticChild && isStaticNext) return makePolicyAndWhat(getPolicy(BETWEEN_CLASS_STATIC_VARS), "between class static vars"); if (!isStaticChild && !isStaticNext) return makePolicyAndWhat(getPolicy(BETWEEN_CLASS_VARS), "between class vars"); @@ -362,8 +361,8 @@ class ExtendedEmptyLinesCheck extends Check { if (parent == null) return null; var brOpens:Array = parent.filterCallback(function(tok:TokenTree, depth:Int):FilterResult { return switch (tok.tok) { - case BrOpen: FOUND_SKIP_SUBTREE; - default: GO_DEEPER; + case BrOpen: FoundSkipSubtree; + default: GoDeeper; } }); if (brOpens.length <= 0) return null; @@ -406,7 +405,7 @@ class ExtendedEmptyLinesCheck extends Check { if (isIgnored([IN_FUNCTION, AFTER_LEFT_CURLY, BEFORE_RIGHT_CURLY])) return; var root:TokenTree = checker.getTokenTree(); - var funcs:Array = root.filter([Kwd(KwdFunction)], ALL); + var funcs:Array = root.filter([Kwd(KwdFunction)], All); if (funcs.length <= 0) return; @@ -416,7 +415,7 @@ class ExtendedEmptyLinesCheck extends Check { var end:Int = checker.getLinePos(pos.max).line; checkLines(emptyLines, getPolicy(IN_FUNCTION), start, end, "inside functions", true); - var brOpen:Array = func.filter([BrOpen], ALL); + var brOpen:Array = func.filter([BrOpen], All); for (open in brOpen) { var close:TokenTree = open.getLastChild(); if (close == null) continue; @@ -442,9 +441,9 @@ class ExtendedEmptyLinesCheck extends Check { var root:TokenTree = checker.getTokenTree(); var comments:Array = root.filterCallback(function(tok:TokenTree, depth:Int):FilterResult { return switch (tok.tok) { - case Comment(_): FOUND_SKIP_SUBTREE; - case CommentLine(_): FOUND_SKIP_SUBTREE; - default: GO_DEEPER; + case Comment(_): FoundSkipSubtree; + case CommentLine(_): FoundSkipSubtree; + default: GoDeeper; } }); for (comment in comments) { @@ -474,7 +473,7 @@ class ExtendedEmptyLinesCheck extends Check { } function checkPreviousSiblingComment(token:TokenTree):Bool { - if ((token == null) || (token.tok == null)) { + if ((token == null) || (token.tok == Root)) { return false; } switch (token.tok) { @@ -484,7 +483,7 @@ class ExtendedEmptyLinesCheck extends Check { return false; case POpen, Const(CIdent(_)): var parent:Null = token.parent; - if ((parent != null) && (parent.tok != null)) { + if (parent != null) { switch (parent.tok) { case Sharp(_): return false; diff --git a/src/checkstyle/checks/whitespace/IndentationCheck.hx b/src/checkstyle/checks/whitespace/IndentationCheck.hx index bdbf580f..d124071d 100644 --- a/src/checkstyle/checks/whitespace/IndentationCheck.hx +++ b/src/checkstyle/checks/whitespace/IndentationCheck.hx @@ -127,7 +127,7 @@ class IndentationCheck extends Check { function calcLineIndentation():Array { var lineIndentation:Array = [for (i in 0...checker.lines.length) 0]; - var searchFor:Array = [ + var searchFor:Array = [ BrOpen, BkOpen, Sharp("if"), @@ -144,7 +144,7 @@ class IndentationCheck extends Check { Kwd(KwdCase), Kwd(KwdDefault) ]; - var tokenList:Array = checker.getTokenTree().filter(searchFor, ALL); + var tokenList:Array = checker.getTokenTree().filter(searchFor, All); for (token in tokenList) { switch (token.tok) { case BkOpen: @@ -289,7 +289,7 @@ class IndentationCheck extends Check { function calcWrapStatements():Array { var wrapped:Array = [for (i in 0...checker.lines.length) false]; - var searchFor:Array = [ + var searchFor:Array = [ POpen, Dot, Kwd(KwdReturn), @@ -309,7 +309,7 @@ class IndentationCheck extends Check { Binop(OpAssignOp(OpAnd)), Binop(OpAssignOp(OpXor)) ]; - var tokenList:Array = checker.getTokenTree().filter(searchFor, ALL); + var tokenList:Array = checker.getTokenTree().filter(searchFor, All); for (token in tokenList) { var pos = token.getPos(); var child:TokenTree = token.getFirstChild(); @@ -351,12 +351,11 @@ class IndentationCheck extends Check { var ignoreIndentation:Array = [for (i in 0...checker.lines.length) false]; var tokenList:Array = checker.getTokenTree().filterCallback(function(token:TokenTree, depth:Int):FilterResult { - if (token.tok == null) return GO_DEEPER; return switch (token.tok) { - case Comment(_): FOUND_SKIP_SUBTREE; - case CommentLine(_): FOUND_SKIP_SUBTREE; - case Const(CString(_)): FOUND_SKIP_SUBTREE; - default: GO_DEEPER; + case Comment(_): FoundSkipSubtree; + case CommentLine(_): FoundSkipSubtree; + case Const(CString(_)): FoundSkipSubtree; + default: GoDeeper; } }); for (token in tokenList) { diff --git a/src/checkstyle/checks/whitespace/OperatorWhitespaceCheck.hx b/src/checkstyle/checks/whitespace/OperatorWhitespaceCheck.hx index 824fb978..4e5032b2 100644 --- a/src/checkstyle/checks/whitespace/OperatorWhitespaceCheck.hx +++ b/src/checkstyle/checks/whitespace/OperatorWhitespaceCheck.hx @@ -1,8 +1,8 @@ package checkstyle.checks.whitespace; -import tokentree.utils.TokenTreeCheckUtils; import checkstyle.checks.whitespace.WhitespaceCheckBase.WhitespacePolicy; import checkstyle.checks.whitespace.WhitespaceCheckBase.WhitespaceUnaryPolicy; +import tokentree.utils.TokenTreeCheckUtils; /** Checks that whitespace is present or absent around a operators. @@ -178,7 +178,7 @@ class OperatorWhitespaceCheck extends WhitespaceCheckBase { function checkUnaryOps(root:TokenTree) { if ((unaryOpPolicy == null) || (unaryOpPolicy == IGNORE)) return; - var tokens:Array = root.filter([Unop(OpNegBits), Unop(OpNot), Unop(OpIncrement), Unop(OpDecrement)], ALL); + var tokens:Array = root.filter([Unop(OpNegBits), Unop(OpNot), Unop(OpIncrement), Unop(OpDecrement)], All); for (token in tokens) { if (isPosSuppressed(token.pos)) continue; @@ -188,7 +188,7 @@ class OperatorWhitespaceCheck extends WhitespaceCheckBase { function checkTernaryOps(root:TokenTree) { if ((ternaryOpPolicy == null) || (ternaryOpPolicy == IGNORE)) return; - var tokens:Array = root.filter([Question], ALL); + var tokens:Array = root.filter([Question], All); for (token in tokens) { if (isPosSuppressed(token.pos)) continue; @@ -233,11 +233,10 @@ class OperatorWhitespaceCheck extends WhitespaceCheckBase { function checkIntervalOps(root:TokenTree) { if ((intervalOpPolicy == null) || (intervalOpPolicy == IGNORE)) return; var tokens:Array = root.filterCallback(function(token:TokenTree, depth:Int):FilterResult { - if (token.tok == null) return GO_DEEPER; return switch (token.tok) { - case Binop(OpInterval): FOUND_SKIP_SUBTREE; - case IntInterval(_): FOUND_SKIP_SUBTREE; - default: GO_DEEPER; + case Binop(OpInterval): FoundSkipSubtree; + case IntInterval(_): FoundSkipSubtree; + default: GoDeeper; } }); checkTokenList(tokens, intervalOpPolicy); @@ -245,7 +244,7 @@ class OperatorWhitespaceCheck extends WhitespaceCheckBase { function checkArrowOps(root:TokenTree) { if ((arrowPolicy == null) || (arrowPolicy == IGNORE)) return; - var tokens:Array = root.filter([Binop(OpArrow)], ALL); + var tokens:Array = root.filter([Binop(OpArrow)], All); checkTokenList(tokens, arrowPolicy); } @@ -255,16 +254,16 @@ class OperatorWhitespaceCheck extends WhitespaceCheckBase { && ((newFunctionTypePolicy == null) || (newFunctionTypePolicy == IGNORE))) { return; } - var tokens:Array = root.filter([Arrow], ALL); + var tokens:Array = root.filter([Arrow], All); for (token in tokens) { if (isPosSuppressed(token.pos)) continue; var type:ArrowType = TokenTreeCheckUtils.getArrowType(token); switch (type) { - case ARROW_FUNCTION: + case ArrowFunction: checkWhitespace(token, arrowFunctionPolicy); - case FUNCTION_TYPE_HAXE3: + case OldFunctionType: checkWhitespace(token, oldFunctionTypePolicy); - case FUNCTION_TYPE_HAXE4: + case NewFunctionType: checkWhitespace(token, newFunctionTypePolicy); } } diff --git a/src/checkstyle/checks/whitespace/OperatorWrapCheck.hx b/src/checkstyle/checks/whitespace/OperatorWrapCheck.hx index d460d98f..2f09f517 100644 --- a/src/checkstyle/checks/whitespace/OperatorWrapCheck.hx +++ b/src/checkstyle/checks/whitespace/OperatorWrapCheck.hx @@ -50,7 +50,7 @@ class OperatorWrapCheck extends WrapCheckBase { } override function actualRun() { - var tokenList:Array = []; + var tokenList:Array = []; if (hasToken("=")) tokenList.push(Binop(OpAssign)); if (hasToken("+")) tokenList.push(Binop(OpAdd)); diff --git a/src/checkstyle/checks/whitespace/SeparatorWrapCheck.hx b/src/checkstyle/checks/whitespace/SeparatorWrapCheck.hx index de7bee7f..9dc76280 100644 --- a/src/checkstyle/checks/whitespace/SeparatorWrapCheck.hx +++ b/src/checkstyle/checks/whitespace/SeparatorWrapCheck.hx @@ -14,7 +14,7 @@ class SeparatorWrapCheck extends WrapCheckBase { } override function actualRun() { - var tokenList:Array = []; + var tokenList:Array = []; if (hasToken(",")) tokenList.push(Comma); if (hasToken(".")) tokenList.push(Dot); diff --git a/src/checkstyle/checks/whitespace/SpacingCheck.hx b/src/checkstyle/checks/whitespace/SpacingCheck.hx index 43540fbf..9043671d 100644 --- a/src/checkstyle/checks/whitespace/SpacingCheck.hx +++ b/src/checkstyle/checks/whitespace/SpacingCheck.hx @@ -78,7 +78,7 @@ class SpacingCheck extends Check { override function actualRun() { var root:TokenTree = checker.getTokenTree(); - var acceptableTokens:Array = root.filter([Kwd(KwdIf), Kwd(KwdFor), Kwd(KwdWhile), Kwd(KwdSwitch), Kwd(KwdCatch)], ALL); + var acceptableTokens:Array = root.filter([Kwd(KwdIf), Kwd(KwdFor), Kwd(KwdWhile), Kwd(KwdSwitch), Kwd(KwdCatch)], All); for (token in acceptableTokens) { var firstChild:TokenTree = token.getFirstChild(); diff --git a/src/checkstyle/checks/whitespace/WhitespaceAfterCheck.hx b/src/checkstyle/checks/whitespace/WhitespaceAfterCheck.hx index 501849c7..65740e4a 100644 --- a/src/checkstyle/checks/whitespace/WhitespaceAfterCheck.hx +++ b/src/checkstyle/checks/whitespace/WhitespaceAfterCheck.hx @@ -32,7 +32,7 @@ class WhitespaceAfterCheck extends Check { } override function actualRun() { - var tokenList:Array = []; + var tokenList:Array = []; if (hasToken(",")) tokenList.push(Comma); if (hasToken(";")) tokenList.push(Semicolon); @@ -90,9 +90,9 @@ class WhitespaceAfterCheck extends Check { checkTokens(tokenList); } - function checkTokens(tokenList:Array) { + function checkTokens(tokenList:Array) { var root:TokenTree = checker.getTokenTree(); - var allTokens:Array = root.filter(tokenList, ALL); + var allTokens:Array = root.filter(tokenList, All); for (tok in allTokens) { if (isPosSuppressed(tok.pos)) continue; diff --git a/src/checkstyle/checks/whitespace/WhitespaceAroundCheck.hx b/src/checkstyle/checks/whitespace/WhitespaceAroundCheck.hx index bb2050cf..039ba1b5 100644 --- a/src/checkstyle/checks/whitespace/WhitespaceAroundCheck.hx +++ b/src/checkstyle/checks/whitespace/WhitespaceAroundCheck.hx @@ -61,7 +61,7 @@ class WhitespaceAroundCheck extends Check { } override function actualRun() { - var tokenList:Array = []; + var tokenList:Array = []; if (hasToken(",")) tokenList.push(Comma); if (hasToken(";")) tokenList.push(Semicolon); @@ -122,9 +122,9 @@ class WhitespaceAroundCheck extends Check { checkTokens(tokenList); } - function checkTokens(tokenList:Array) { + function checkTokens(tokenList:Array) { var root:TokenTree = checker.getTokenTree(); - var allTokens:Array = root.filter(tokenList, ALL); + var allTokens:Array = root.filter(tokenList, All); for (tok in allTokens) { if (isPosSuppressed(tok.pos)) continue; diff --git a/src/checkstyle/checks/whitespace/WhitespaceCheckBase.hx b/src/checkstyle/checks/whitespace/WhitespaceCheckBase.hx index 6e3c9c24..35a52218 100644 --- a/src/checkstyle/checks/whitespace/WhitespaceCheckBase.hx +++ b/src/checkstyle/checks/whitespace/WhitespaceCheckBase.hx @@ -13,9 +13,9 @@ class WhitespaceCheckBase extends Check { categories = [Category.STYLE, Category.CLARITY]; } - function checkTokens(root:TokenTree, tokens:Array, policy:WhitespacePolicy) { + function checkTokens(root:TokenTree, tokens:Array, policy:WhitespacePolicy) { if ((policy == null) || (policy == IGNORE)) return; - var tokenList:Array = root.filter(tokens, ALL); + var tokenList:Array = root.filter(tokens, All); checkTokenList(tokenList, policy); } diff --git a/src/checkstyle/checks/whitespace/WrapCheckBase.hx b/src/checkstyle/checks/whitespace/WrapCheckBase.hx index 704e2f7f..44fbf901 100644 --- a/src/checkstyle/checks/whitespace/WrapCheckBase.hx +++ b/src/checkstyle/checks/whitespace/WrapCheckBase.hx @@ -29,9 +29,9 @@ class WrapCheckBase extends Check { return (tokens.length == 0 || tokens.contains(token)); } - function checkTokens(tokenList:Array) { + function checkTokens(tokenList:Array) { var root:TokenTree = checker.getTokenTree(); - var allTokens:Array = root.filter(tokenList, ALL); + var allTokens:Array = root.filter(tokenList, All); for (tok in allTokens) { if (isPosSuppressed(tok.pos)) continue; diff --git a/src/checkstyle/config/ExcludeManager.hx b/src/checkstyle/config/ExcludeManager.hx index 11a94726..abce8a21 100644 --- a/src/checkstyle/config/ExcludeManager.hx +++ b/src/checkstyle/config/ExcludeManager.hx @@ -27,13 +27,13 @@ class ExcludeManager { } static function createExcludeDefinition(filter:String, range:String):ExcludeDefinition { - if ((range == null) || (range == "")) return FULL(filter); - if (~/^[1-9][0-9]*$/.match(range)) return LINE(filter, Std.parseInt(range)); + if ((range == null) || (range == "")) return ExcludeDefinition.FULL(filter); + if (~/^[1-9][0-9]*$/.match(range)) return ExcludeDefinition.LINE(filter, Std.parseInt(range)); if (~/^[1-9][0-9]*-[1-9][0-9]*$/.match(range)) { var parts = range.split("-"); - return RANGE(filter, Std.parseInt(parts[0]), Std.parseInt(parts[1])); + return ExcludeDefinition.RANGE(filter, Std.parseInt(parts[0]), Std.parseInt(parts[1])); } - return IDENTIFIER(filter, range); + return ExcludeDefinition.IDENTIFIER(filter, range); } public static function isExcludedFromAll(fileName:String):Bool { @@ -133,7 +133,7 @@ class ExcludeManager { function getInlineExcludes(checker:Checker):Array { var inlineExcludes:Array = []; var root:TokenTree = checker.getTokenTree(); - var allAtTokens:Array = root.filter([At], ALL); + var allAtTokens:Array = root.filter([At], All); for (atToken in allAtTokens) { var child:TokenTree = atToken.getFirstChild(); if (child == null) continue; @@ -146,11 +146,11 @@ class ExcludeManager { pOpen.filterCallback(function(token:TokenTree, depth:Int):FilterResult { switch (token.tok) { case Const(CString(name)): - if (!StringTools.startsWith(name, "checkstyle:")) return SKIP_SUBTREE; + if (!StringTools.startsWith(name, "checkstyle:")) return SkipSubtree; checkNames.push(name.substr(11)); - return SKIP_SUBTREE; + return SkipSubtree; default: - return GO_DEEPER; + return GoDeeper; } }); for (name in checkNames) { @@ -176,11 +176,11 @@ class ExcludeManager { function makeIdentifierRange(checker:Checker, checkName:String, name:String):Array { var identifierExcludes:Array = []; var root:TokenTree = checker.getTokenTree(); - var filterTokens:Array = [Const(CIdent(name))]; + var filterTokens:Array = [Const(CIdent(name))]; if (name == "new") { filterTokens.push(Kwd(KwdNew)); } - var allTokens:Array = root.filter(filterTokens, ALL); + var allTokens:Array = root.filter(filterTokens, All); for (token in allTokens) { identifierExcludes.push(makeTokenExcludeRange(checker, checkName, token)); } diff --git a/src/checkstyle/detect/DetectCodingStyle.hx b/src/checkstyle/detect/DetectCodingStyle.hx index fc14ad45..96ec79c3 100644 --- a/src/checkstyle/detect/DetectCodingStyle.hx +++ b/src/checkstyle/detect/DetectCodingStyle.hx @@ -1,10 +1,10 @@ package checkstyle.detect; -import checkstyle.config.CheckConfig; import checkstyle.Checker; import checkstyle.checks.Check; -import checkstyle.utils.ConfigUtils; +import checkstyle.config.CheckConfig; import checkstyle.reporter.ReporterManager; +import checkstyle.utils.ConfigUtils; import haxe.ds.ArraySort; class DetectCodingStyle { @@ -70,16 +70,16 @@ class DetectCodingStyle { static function iterateProperty(check:Check, property:DetectablePropertyList, file:CheckFile):DetectionResult { if (property.values.length <= 0) { - return NO_CHANGE; + return DetectionResult.NO_CHANGE; } if (property.values.length == 1) { - return CHANGE_DETECTED(property.values[0]); + return DetectionResult.CHANGE_DETECTED(property.values[0]); } var checker:Checker = new Checker(); checker.addCheck(check); checker.loadFileContent(file); - if (!checker.createContext(file)) return NO_CHANGE; + if (!checker.createContext(file)) return DetectionResult.NO_CHANGE; var lastCount:Int = -1; var lowestCountValue:Any = null; @@ -102,14 +102,14 @@ class DetectCodingStyle { } if (changed) { var index:Int = property.values.indexOf(lowestCountValue); - if (index <= 0) return CHANGE_DETECTED(lowestCountValue); + if (index <= 0) return DetectionResult.CHANGE_DETECTED(lowestCountValue); property.values = property.values.slice(index); if (property.values.length > 2) { - return REDUCED_VALUE_LIST(lowestCountValue); + return DetectionResult.REDUCED_VALUE_LIST(lowestCountValue); } - return CHANGE_DETECTED(lowestCountValue); + return DetectionResult.CHANGE_DETECTED(lowestCountValue); } - return NO_CHANGE; + return DetectionResult.NO_CHANGE; } static function runCheck(checker:Checker, fileList:Array):Int { diff --git a/src/checkstyle/import.hx b/src/checkstyle/import.hx index 8b94a048..5cbdcd3b 100644 --- a/src/checkstyle/import.hx +++ b/src/checkstyle/import.hx @@ -9,6 +9,7 @@ import haxe.macro.Expr; import haxeparser.Data; import tokentree.TokenTree; import tokentree.TokenTreeAccessHelper; +import tokentree.TokenTreeDef; import tokentree.utils.TokenTreeCheckUtils; using StringTools; diff --git a/src/checkstyle/utils/ComplexTypeUtils.hx b/src/checkstyle/utils/ComplexTypeUtils.hx index ebb6cd51..2200658f 100644 --- a/src/checkstyle/utils/ComplexTypeUtils.hx +++ b/src/checkstyle/utils/ComplexTypeUtils.hx @@ -19,6 +19,10 @@ class ComplexTypeUtils { walkTypedef(d, td.pos, cb); case EUsing(path): walkTypePath(path, path.name, td.pos, cb); + #if haxe4 + case EStatic(s): + walkStatic(s, td.pos, cb); + #end } } @@ -85,6 +89,12 @@ class ComplexTypeUtils { } } + #if haxe4 + public static function walkStatic(s:Definition, pos:Position, cb:ComplexTypeCallback) { + walkField(cast s, cb); + } + #end + public static function walkVar(v:Var, pos:Position, cb:ComplexTypeCallback) { if (v.type != null) walkComplexType(v.type, v.name, pos, cb); if (v.expr != null) walkExpr(v.expr, cb); diff --git a/src/checkstyle/utils/ExprUtils.hx b/src/checkstyle/utils/ExprUtils.hx index c818af17..6e844629 100644 --- a/src/checkstyle/utils/ExprUtils.hx +++ b/src/checkstyle/utils/ExprUtils.hx @@ -19,6 +19,10 @@ class ExprUtils { walkTypedef(d, cb); case EUsing(path): walkTypePath(path, cb); + #if haxe4 + case EStatic(s): + walkStatic(s, td.pos, cb); + #end } } @@ -85,6 +89,12 @@ class ExprUtils { } } + #if haxe4 + public static function walkStatic(s:Definition, pos:Position, cb:Expr -> Void) { + walkField(cast s, cb); + } + #end + public static function walkVar(v:Var, cb:Expr -> Void) { if (v.type != null) walkComplexType(v.type, cb); if (v.expr != null) walkExpr(v.expr, cb); diff --git a/src/checkstyle/utils/FieldUtils.hx b/src/checkstyle/utils/FieldUtils.hx index bf255c8b..a322a6c0 100644 --- a/src/checkstyle/utils/FieldUtils.hx +++ b/src/checkstyle/utils/FieldUtils.hx @@ -54,7 +54,7 @@ class FieldUtils { var kind = a.meta.hasMeta(metaName) ? ENUM_ABSTRACT : ABSTRACT; return {decl: decl, kind: kind}; case ETypedef(d): - return return {decl: decl, kind: TYPEDEF}; + return {decl: decl, kind: TYPEDEF}; default: return null; } @@ -70,6 +70,6 @@ enum FieldParentKind { } typedef ParentType = { - var decl:TypeDef; + var decl:haxeparser.Data.TypeDef; var kind:FieldParentKind; } \ No newline at end of file diff --git a/test/checkstyle/checks/CheckTestCase.hx b/test/checkstyle/checks/CheckTestCase.hx index 262499ce..d907a0e8 100644 --- a/test/checkstyle/checks/CheckTestCase.hx +++ b/test/checkstyle/checks/CheckTestCase.hx @@ -18,6 +18,11 @@ class CheckTestCase { function assertMsg(check:Check, testCase:T, expected:String, ?defines:Array>, ?fileName:String, allowFailingAST:Bool = false, ?pos:PosInfos) { + assertMessages(check, testCase, [expected], defines, fileName, allowFailingAST, pos); + } + + function assertMessages(check:Check, testCase:T, expected:Array, ?defines:Array>, ?fileName:String, allowFailingAST:Bool = false, + ?pos:PosInfos) { var re = ~/abstractAndClass ([a-zA-Z0-9]*)/g; if (re.match(testCase)) { actualAssertMsg(check, re.replace(testCase, "class $1"), expected, fileName, allowFailingAST, pos); @@ -27,17 +32,26 @@ class CheckTestCase { } function assertNoMsg(check:Check, testCase:T, ?fileName:String, allowFailingAST:Bool = false, ?pos:PosInfos) { - assertMsg(check, testCase, "", null, fileName, allowFailingAST, pos); + assertMessages(check, testCase, [], null, fileName, allowFailingAST, pos); } - function actualAssertMsg(check:Check, testCase:String, expected:String, ?defines:Array>, ?fileName:String, allowFailingAST:Bool = false, - ?pos:PosInfos) { - var msg = checkMessage(testCase, check, defines, fileName, allowFailingAST, pos); - Assert.areEqual(expected, msg, pos); + function actualAssertMsg(check:Check, testCase:String, expected:Array, ?defines:Array>, ?fileName:String, + allowFailingAST:Bool = false, ?pos:PosInfos) { + var messages:Array = checkMessages(testCase, check, defines, fileName, allowFailingAST, pos); + if ((expected.length == 1) && (expected.length != messages.length)) { + for (i in 0...messages.length) { + Assert.areEqual(expected[0], messages[i].message, pos); + } + } + // trace(messages.map(m -> m.message)); + Assert.areEqual(expected.length, messages.length, pos); + for (i in 0...expected.length) { + Assert.areEqual(expected[i], messages[i].message, pos); + } } - function checkMessage(src:String, check:Check, defines:Array>, fileName:String = FILE_NAME, allowFailingAST:Bool = false, - ?pos:PosInfos):String { + function checkMessages(src:String, check:Check, defines:Array>, fileName:String = FILE_NAME, allowFailingAST:Bool = false, + ?pos:PosInfos):Array { // a fresh Checker and Reporter for every checkMessage // to allow multiple independent checkMessage calls in a single test checker = new Checker(allowFailingAST); @@ -49,7 +63,7 @@ class CheckTestCase { ReporterManager.INSTANCE.clear(); ReporterManager.INSTANCE.addReporter(reporter); checker.process([{name: fileName, content: ByteData.ofString(src), index: 0}]); - return reporter.message; + return reporter.messages; } @After @@ -60,10 +74,10 @@ class CheckTestCase { } class TestReporter implements IReporter { - public var message:String; + public var messages:Array; public function new() { - message = ""; + messages = []; } public function start() {} @@ -75,6 +89,6 @@ class TestReporter implements IReporter { public function fileFinish(f:CheckFile) {} public function addMessage(m:CheckMessage) { - message = m.message; + messages.push(m); } } \ No newline at end of file diff --git a/test/checkstyle/checks/block/BlockBreakingConditionalCheckTest.hx b/test/checkstyle/checks/block/BlockBreakingConditionalCheckTest.hx index bf823051..bb73683a 100644 --- a/test/checkstyle/checks/block/BlockBreakingConditionalCheckTest.hx +++ b/test/checkstyle/checks/block/BlockBreakingConditionalCheckTest.hx @@ -1,6 +1,7 @@ package checkstyle.checks.block; class BlockBreakingConditionalCheckTest extends CheckTestCase { + static inline var MSG_LEFT_CURLY:String = "Left curly has no matching right curly"; static inline var MSG_RIGHT_CURLY:String = "Right curly has no matching left curly"; @Test @@ -14,11 +15,21 @@ class BlockBreakingConditionalCheckTest extends CheckTestCase { assertMsg(check, TEST5, MSG_EOL); assertMsg(check, TEST7, MSG_EOL); assertMsg(check, TEST10, MSG_EOL); - assertMsg(check, NL_CASEBLOCK, MSG_EOL); + assertMessages(check, NL_CASEBLOCK, [MSG_EOL, MSG_EOL, MSG_EOL]); assertMsg(check, NLOW_CASEBLOCK, MSG_EOL); } @@ -44,16 +44,16 @@ class LeftCurlyCheckTest extends CheckTestCase { var check = new LeftCurlyCheck(); check.option = NL; - assertMsg(check, TEST, MSG_NL); + assertMessages(check, TEST, [MSG_NL, MSG_NL, MSG_NL, MSG_NL, MSG_NL, MSG_NL, MSG_NL, MSG_NL]); assertNoMsg(check, TEST13); check.tokens = [OBJECT_DECL]; assertMsg(check, TEST4, MSG_NL); assertNoMsg(check, TEST14); - assertMsg(check, NESTED_OBJECT_LITERAL, MSG_NL); + assertMessages(check, NESTED_OBJECT_LITERAL, [MSG_NL, MSG_NL]); check.tokens = [TYPEDEF_DEF]; - assertMsg(check, TEST14, MSG_NL); + assertMessages(check, TEST14, [MSG_NL, MSG_NL]); check.tokens = [IF]; assertNoMsg(check, TEST1); @@ -73,8 +73,8 @@ class LeftCurlyCheckTest extends CheckTestCase { check.option = NL; assertNoMsg(check, TEST15); assertNoMsg(check, NL_CASEBLOCK); - assertMsg(check, EOL_CASEBLOCK, MSG_NL); - assertMsg(check, NLOW_CASEBLOCK, MSG_NL); + assertMessages(check, EOL_CASEBLOCK, [MSG_NL, MSG_NL, MSG_NL]); + assertMessages(check, NLOW_CASEBLOCK, [MSG_NL, MSG_NL]); } @Test @@ -85,7 +85,7 @@ class LeftCurlyCheckTest extends CheckTestCase { assertNoMsg(check, TEST12); assertNoMsg(check, TEST16); assertNoMsg(check, NLOW_CASEBLOCK); - assertMsg(check, TEST17, MSG_NLOW); + assertMessages(check, TEST17, [MSG_NLOW, MSG_NLOW]); assertMsg(check, TEST18, MSG_NL_SPLIT); assertMsg(check, TEST19, MSG_NL_SPLIT); assertMsg(check, WRAPPED_FUNCTION, MSG_NL_SPLIT); @@ -95,7 +95,7 @@ class LeftCurlyCheckTest extends CheckTestCase { public function testReification() { var check = new LeftCurlyCheck(); check.tokens = [REIFICATION]; - assertMsg(check, MACRO_REIFICATION, MSG_EOL); + assertMessages(check, MACRO_REIFICATION, [MSG_EOL, MSG_EOL]); } @Test @@ -116,16 +116,16 @@ class LeftCurlyCheckTest extends CheckTestCase { var check = new LeftCurlyCheck(); check.tokens = [ARRAY_COMPREHENSION, OBJECT_DECL]; assertNoMsg(check, ARRAY_COMPREHENSION_2_ISSUE_114); - assertMsg(check, ARRAY_COMPREHENSION_ISSUE_114, MSG_EOL); + assertMessages(check, ARRAY_COMPREHENSION_ISSUE_114, [MSG_EOL, MSG_EOL]); check.option = NLOW; assertNoMsg(check, ARRAY_COMPREHENSION_2_ISSUE_114); assertNoMsg(check, ARRAY_COMPREHENSION_NLOW_ISSUE_114); - assertMsg(check, ARRAY_COMPREHENSION_ISSUE_114, MSG_NL); + assertMessages(check, ARRAY_COMPREHENSION_ISSUE_114, [MSG_NL, MSG_NL]); check.option = NL; - assertMsg(check, ARRAY_COMPREHENSION_2_ISSUE_114, MSG_NL); - assertMsg(check, ARRAY_COMPREHENSION_ISSUE_114, MSG_NL); + assertMessages(check, ARRAY_COMPREHENSION_2_ISSUE_114, [MSG_NL, MSG_NL]); + assertMessages(check, ARRAY_COMPREHENSION_ISSUE_114, [MSG_NL, MSG_NL]); } } diff --git a/test/checkstyle/checks/block/NeedBracesCheckTest.hx b/test/checkstyle/checks/block/NeedBracesCheckTest.hx index 90ae8b49..5b2dfa3a 100644 --- a/test/checkstyle/checks/block/NeedBracesCheckTest.hx +++ b/test/checkstyle/checks/block/NeedBracesCheckTest.hx @@ -46,9 +46,17 @@ class NeedBracesCheckTest extends CheckTestCase { var check = new NeedBracesCheck(); check.allowSingleLineStatement = false; - assertMsg(check, TEST, MSG_SAME_LINE_WHILE); + assertMessages(check, TEST, [ + MSG_SAME_LINE_IF, + MSG_SAME_LINE_IF, + MSG_SAME_LINE_ELSE, + MSG_SAME_LINE_IF, + MSG_SAME_LINE_IF, + MSG_SAME_LINE_FOR, + MSG_SAME_LINE_WHILE + ]); assertMsg(check, TEST1, MSG_IF); - assertMsg(check, TEST2, MSG_ELSE); + assertMessages(check, TEST2, [MSG_SAME_LINE_IF, MSG_ELSE]); assertNoMsg(check, TEST3); assertMsg(check, TEST4, MSG_IF); assertNoMsg(check, TEST5); @@ -57,7 +65,7 @@ class NeedBracesCheckTest extends CheckTestCase { assertNoMsg(check, TEST8); assertMsg(check, TEST9, MSG_SAME_LINE_FOR); assertMsg(check, TEST10, MSG_SAME_LINE_IF); - assertMsg(check, TEST11, MSG_SAME_LINE_ELSE); + assertMessages(check, TEST11, [MSG_IF, MSG_SAME_LINE_ELSE]); assertMsg(check, TEST12, MSG_SAME_LINE_IF); assertMsg(check, TEST13, MSG_SAME_LINE_IF); assertNoMsg(check, TEST14); @@ -113,9 +121,15 @@ class NeedBracesCheckTest extends CheckTestCase { assertNoMsg(check, TEST14); check.allowSingleLineStatement = false; - assertMsg(check, TEST, MSG_SAME_LINE_IF); + assertMessages(check, TEST, [ + MSG_SAME_LINE_IF, + MSG_SAME_LINE_IF, + MSG_SAME_LINE_ELSE, + MSG_SAME_LINE_IF, + MSG_SAME_LINE_IF + ]); assertMsg(check, TEST10, MSG_SAME_LINE_IF); - assertMsg(check, TEST11, MSG_SAME_LINE_ELSE); + assertMessages(check, TEST11, [MSG_IF, MSG_SAME_LINE_ELSE]); assertMsg(check, TEST13, MSG_SAME_LINE_IF); assertNoMsg(check, TEST14); assertMsg(check, TEST16, MSG_SAME_LINE_ELSE); @@ -143,9 +157,15 @@ class NeedBracesCheckTest extends CheckTestCase { assertNoMsg(check, TEST14); check.allowSingleLineStatement = false; - assertMsg(check, TEST, MSG_SAME_LINE_IF); + assertMessages(check, TEST, [ + MSG_SAME_LINE_IF, + MSG_SAME_LINE_IF, + MSG_SAME_LINE_ELSE, + MSG_SAME_LINE_IF, + MSG_SAME_LINE_IF + ]); assertMsg(check, TEST10, MSG_SAME_LINE_IF); - assertMsg(check, TEST11, MSG_SAME_LINE_ELSE); + assertMessages(check, TEST11, [MSG_IF, MSG_SAME_LINE_ELSE]); assertMsg(check, TEST12, MSG_SAME_LINE_IF); assertMsg(check, TEST13, MSG_SAME_LINE_IF); assertNoMsg(check, TEST14); diff --git a/test/checkstyle/checks/block/RightCurlyCheckTest.hx b/test/checkstyle/checks/block/RightCurlyCheckTest.hx index d94f29c4..d10efd68 100644 --- a/test/checkstyle/checks/block/RightCurlyCheckTest.hx +++ b/test/checkstyle/checks/block/RightCurlyCheckTest.hx @@ -53,7 +53,7 @@ class RightCurlyCheckTest extends CheckTestCase { var check = new RightCurlyCheck(); assertMsg(check, SAMELINE_IF, MSG_ALONE); assertMsg(check, SAMELINE_TRY_CATCH, MSG_ALONE); - assertMsg(check, SAMELINE_NESTED_OBJECT, MSG_ALONE); + assertMessages(check, SAMELINE_NESTED_OBJECT, [MSG_ALONE, MSG_ALONE]); } @Test @@ -84,19 +84,19 @@ class RightCurlyCheckTest extends CheckTestCase { public function testIncorrectSame() { var check = new RightCurlyCheck(); check.option = SAME; - assertMsg(check, SINGLELINE_IF, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_IF, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertMsg(check, SINGLELINE_FOR, MSG_NOT_SAME_LINE); assertMsg(check, SINGLELINE_WHILE, MSG_NOT_SAME_LINE); - assertMsg(check, SINGLELINE_TRY_CATCH, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_TRY_CATCH, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertMsg(check, SINGLELINE_INTERFACE, MSG_NOT_SAME_LINE); - assertMsg(check, SINGLELINE_CLASS, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_CLASS, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertMsg(check, SINGLELINE_TYPEDEF, MSG_NOT_SAME_LINE); assertMsg(check, SINGLELINE_SWITCH, MSG_NOT_SAME_LINE); - assertMsg(check, SINGLELINE_CASE, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_CASE, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertMsg(check, SINGLELINE_OBJECT, MSG_NOT_SAME_LINE); - assertMsg(check, SINGLELINE_ABSTRACT, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_ABSTRACT, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertMsg(check, SINGLELINE_ENUM, MSG_NOT_SAME_LINE); - assertMsg(check, SINGLELINE_NESTED_OBJECT, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_NESTED_OBJECT, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertMsg(check, ALONE_IF, MSG_SAME_LINE); assertMsg(check, ALONE_TRY_CATCH, MSG_SAME_LINE); @@ -127,24 +127,24 @@ class RightCurlyCheckTest extends CheckTestCase { public function testIncorrectAlone() { var check = new RightCurlyCheck(); check.option = ALONE; - assertMsg(check, SINGLELINE_IF, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_IF, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertMsg(check, SINGLELINE_FUNCTION, MSG_NOT_SAME_LINE); assertMsg(check, SINGLELINE_FOR, MSG_NOT_SAME_LINE); assertMsg(check, SINGLELINE_WHILE, MSG_NOT_SAME_LINE); - assertMsg(check, SINGLELINE_TRY_CATCH, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_TRY_CATCH, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertMsg(check, SINGLELINE_INTERFACE, MSG_NOT_SAME_LINE); - assertMsg(check, SINGLELINE_CLASS, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_CLASS, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertMsg(check, SINGLELINE_TYPEDEF, MSG_NOT_SAME_LINE); assertMsg(check, SINGLELINE_SWITCH, MSG_NOT_SAME_LINE); - assertMsg(check, SINGLELINE_CASE, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_CASE, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertMsg(check, SINGLELINE_OBJECT, MSG_NOT_SAME_LINE); - assertMsg(check, SINGLELINE_ABSTRACT, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_ABSTRACT, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertMsg(check, SINGLELINE_ENUM, MSG_NOT_SAME_LINE); - assertMsg(check, SINGLELINE_NESTED_OBJECT, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_NESTED_OBJECT, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertMsg(check, SAMELINE_IF, MSG_ALONE); assertMsg(check, SAMELINE_TRY_CATCH, MSG_ALONE); - assertMsg(check, SAMELINE_NESTED_OBJECT, MSG_ALONE); + assertMessages(check, SAMELINE_NESTED_OBJECT, [MSG_ALONE, MSG_ALONE]); } @Test @@ -159,7 +159,7 @@ class RightCurlyCheckTest extends CheckTestCase { assertNoMsg(check, ALONE_FOR); check.option = SAME; - assertMsg(check, SINGLELINE_IF, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_IF, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertNoMsg(check, SINGLELINE_FOR); assertNoMsg(check, SAMELINE_IF); assertNoMsg(check, SAMELINE_TRY_CATCH); @@ -167,7 +167,7 @@ class RightCurlyCheckTest extends CheckTestCase { assertNoMsg(check, ALONE_FOR); check.option = ALONE; - assertMsg(check, SINGLELINE_IF, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_IF, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertNoMsg(check, SINGLELINE_FOR); assertMsg(check, SAMELINE_IF, MSG_ALONE); assertNoMsg(check, SAMELINE_TRY_CATCH); @@ -182,10 +182,10 @@ class RightCurlyCheckTest extends CheckTestCase { assertNoMsg(check, MACRO_REIFICATION); check.option = SAME; - assertMsg(check, MACRO_REIFICATION, MSG_NOT_SAME_LINE); + assertMessages(check, MACRO_REIFICATION, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); check.option = ALONE; - assertMsg(check, MACRO_REIFICATION, MSG_NOT_SAME_LINE); + assertMessages(check, MACRO_REIFICATION, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); } @Test @@ -196,11 +196,11 @@ class RightCurlyCheckTest extends CheckTestCase { assertNoMsg(check, ARRAY_COMPREHENSION_2_ISSUE_114); check.option = SAME; - assertMsg(check, ARRAY_COMPREHENSION_ISSUE_114, MSG_NOT_SAME_LINE); + assertMessages(check, ARRAY_COMPREHENSION_ISSUE_114, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertNoMsg(check, ARRAY_COMPREHENSION_2_ISSUE_114); check.option = ALONE; - assertMsg(check, ARRAY_COMPREHENSION_ISSUE_114, MSG_NOT_SAME_LINE); + assertMessages(check, ARRAY_COMPREHENSION_ISSUE_114, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertNoMsg(check, ARRAY_COMPREHENSION_2_ISSUE_114); check.tokens = [ARRAY_COMPREHENSION]; @@ -223,7 +223,7 @@ class RightCurlyCheckTest extends CheckTestCase { check.tokens = [IF]; check.option = ALONE; - assertMsg(check, SINGLELINE_IF, MSG_NOT_SAME_LINE); + assertMessages(check, SINGLELINE_IF, [MSG_NOT_SAME_LINE, MSG_NOT_SAME_LINE]); assertNoMsg(check, SINGLELINE_FUNCTION); assertNoMsg(check, SINGLELINE_FOR); diff --git a/test/checkstyle/checks/coding/HiddenFieldCheckTest.hx b/test/checkstyle/checks/coding/HiddenFieldCheckTest.hx index 818bb547..1d5a674f 100644 --- a/test/checkstyle/checks/coding/HiddenFieldCheckTest.hx +++ b/test/checkstyle/checks/coding/HiddenFieldCheckTest.hx @@ -31,7 +31,10 @@ class HiddenFieldCheckTest extends CheckTestCase { assertMsg(check, HIDDEN_FIELDS_CONSTRUCTOR_VAR, 'Variable definition of "field2" masks member of same name'); assertMsg(check, HIDDEN_FIELDS_FUNC, 'Parameter definition of "field1" masks member of same name'); assertMsg(check, HIDDEN_FIELDS_FUNC_WITH_COMMENT, 'Parameter definition of "field1" masks member of same name'); - assertMsg(check, HIDDEN_FIELDS_CONSTRUCTOR_VAR_WITH_COMMENT, 'Variable definition of "field2" masks member of same name'); + assertMessages(check, HIDDEN_FIELDS_CONSTRUCTOR_VAR_WITH_COMMENT, [ + 'Variable definition of "field2" masks member of same name', + 'Variable definition of "field2" masks member of same name' + ]); } @Test @@ -43,7 +46,10 @@ class HiddenFieldCheckTest extends CheckTestCase { assertNoMsg(check, HIDDEN_FIELDS_CONSTRUCTOR); assertNoMsg(check, HIDDEN_FIELDS_CONSTRUCTOR_VAR); assertNoMsg(check, HIDDEN_FIELDS_CONSTRUCTOR_VAR_WITH_COMMENT); - assertMsg(check, HIDDEN_FIELDS_SETTER, 'Parameter definition of "field2" masks member of same name'); + assertMessages(check, HIDDEN_FIELDS_SETTER, [ + 'Parameter definition of "field1" masks member of same name', + 'Parameter definition of "field2" masks member of same name' + ]); assertMsg(check, HIDDEN_FIELDS_FUNC, 'Parameter definition of "field1" masks member of same name'); assertMsg(check, HIDDEN_FIELDS_FUNC_WITH_COMMENT, 'Parameter definition of "field1" masks member of same name'); } diff --git a/test/checkstyle/checks/coding/InnerAssignmentCheckTest.hx b/test/checkstyle/checks/coding/InnerAssignmentCheckTest.hx index 688e8325..b9afb751 100644 --- a/test/checkstyle/checks/coding/InnerAssignmentCheckTest.hx +++ b/test/checkstyle/checks/coding/InnerAssignmentCheckTest.hx @@ -20,7 +20,7 @@ class InnerAssignmentCheckTest extends CheckTestCase assertMsg(check, IF_RETURN_EXPR, MSG_INNER_ASSIGNMENT); assertMsg(check, WHILE_COND_RETURN, MSG_INNER_ASSIGNMENT); assertMsg(check, SWITCH, MSG_INNER_ASSIGNMENT); - assertMsg(check, SETTER_GETTER_ISSUE_259, MSG_INNER_ASSIGNMENT); + assertMessages(check, SETTER_GETTER_ISSUE_259, [MSG_INNER_ASSIGNMENT, MSG_INNER_ASSIGNMENT]); } @Test diff --git a/test/checkstyle/checks/coding/MultipleVariableDeclarationsCheckTest.hx b/test/checkstyle/checks/coding/MultipleVariableDeclarationsCheckTest.hx index b12aa30a..2965db71 100644 --- a/test/checkstyle/checks/coding/MultipleVariableDeclarationsCheckTest.hx +++ b/test/checkstyle/checks/coding/MultipleVariableDeclarationsCheckTest.hx @@ -12,7 +12,7 @@ class MultipleVariableDeclarationsCheckTest extends CheckTestCase { + static inline var NESTED_TRY_DEPTH_IS_2_MAX_ALLOWED_IS_1:String = "Nested try depth is 2 (max allowed is 1)"; + static inline var NESTED_TRY_DEPTH_IS_1_MAX_ALLOWED_IS_0:String = "Nested try depth is 1 (max allowed is 0)"; + @Test public function testDefault() { var check = new NestedTryDepthCheck(); @@ -10,7 +13,7 @@ class NestedTryDepthCheckTest extends CheckTestCase { @Test public function testDefaultTooMany() { var check = new NestedTryDepthCheck(); - assertMsg(check, TEST2, "Nested try depth is 2 (max allowed is 1)"); + assertMessages(check, TEST2, [NESTED_TRY_DEPTH_IS_2_MAX_ALLOWED_IS_1, NESTED_TRY_DEPTH_IS_2_MAX_ALLOWED_IS_1]); } @Test @@ -23,7 +26,14 @@ class NestedTryDepthCheckTest extends CheckTestCase { check.max = 0; assertNoMsg(check, TEST1); - assertMsg(check, TEST2, "Nested try depth is 1 (max allowed is 0)"); + assertMessages(check, TEST2, [ + NESTED_TRY_DEPTH_IS_1_MAX_ALLOWED_IS_0, + NESTED_TRY_DEPTH_IS_1_MAX_ALLOWED_IS_0, + NESTED_TRY_DEPTH_IS_1_MAX_ALLOWED_IS_0, + NESTED_TRY_DEPTH_IS_1_MAX_ALLOWED_IS_0, + NESTED_TRY_DEPTH_IS_1_MAX_ALLOWED_IS_0, + NESTED_TRY_DEPTH_IS_1_MAX_ALLOWED_IS_0 + ]); } } diff --git a/test/checkstyle/checks/coding/ReturnCountCheckTest.hx b/test/checkstyle/checks/coding/ReturnCountCheckTest.hx index 44d245a1..8031ec0f 100644 --- a/test/checkstyle/checks/coding/ReturnCountCheckTest.hx +++ b/test/checkstyle/checks/coding/ReturnCountCheckTest.hx @@ -27,7 +27,7 @@ class ReturnCountCheckTest extends CheckTestCase { public function testIgnoreRE() { var check = new ReturnCountCheck(); check.ignoreFormat = "^equals$"; - assertMsg(check, TEST5, ""); + assertNoMsg(check, TEST5); } @Test diff --git a/test/checkstyle/checks/comments/DocCommentStyleCheckTest.hx b/test/checkstyle/checks/comments/DocCommentStyleCheckTest.hx index 20e0b4b5..2d9b46cc 100644 --- a/test/checkstyle/checks/comments/DocCommentStyleCheckTest.hx +++ b/test/checkstyle/checks/comments/DocCommentStyleCheckTest.hx @@ -12,7 +12,7 @@ class DocCommentStyleCheckTest extends CheckTestCase assertNoMsg(check, TWO_STAR_NO_STAR_TWO_STAR); assertNoMsg(check, MANY_STARS_NO_STAR_MANY_STARS); assertMsg(check, ONE_STAR_NO_STAR_ONE_STAR, MSG_SHOULD_USE_TWO_STARS); - assertMsg(check, ONE_STAR_ONE_STAR_ONE_STAR, MSG_SHOULD_NOT_START_WITH_STAR); + assertMessages(check, ONE_STAR_ONE_STAR_ONE_STAR, [MSG_SHOULD_USE_TWO_STARS, MSG_SHOULD_NOT_START_WITH_STAR]); assertMsg(check, TWO_STAR_ONE_STAR_TWO_STAR, MSG_SHOULD_NOT_START_WITH_STAR); assertMsg(check, TWO_STAR_TWO_STARS_TWO_STAR, MSG_SHOULD_NOT_START_WITH_STAR); } diff --git a/test/checkstyle/checks/comments/FieldDocCommentCheckTest.hx b/test/checkstyle/checks/comments/FieldDocCommentCheckTest.hx index f52e29a1..ca0ea7bc 100644 --- a/test/checkstyle/checks/comments/FieldDocCommentCheckTest.hx +++ b/test/checkstyle/checks/comments/FieldDocCommentCheckTest.hx @@ -1,8 +1,14 @@ package checkstyle.checks.comments; class FieldDocCommentCheckTest extends CheckTestCase { - static inline var MSG_DOC_FUNC8:String = 'Field "func8" should have documentation'; + static inline var MSG_DOC_FIELD1:String = 'Field "field1" should have documentation'; + static inline var MSG_DOC_FIELD2:String = 'Field "field2" should have documentation'; static inline var MSG_DOC_FUNC4:String = 'Field "func4" should have documentation'; + static inline var MSG_DOC_FUNC5:String = 'Field "func5" should have documentation'; + static inline var MSG_DOC_FUNC5A:String = 'Field "func5a" should have documentation'; + static inline var MSG_DOC_FUNC6:String = 'Field "func6" should have documentation'; + static inline var MSG_DOC_FUNC7:String = 'Field "func7" should have documentation'; + static inline var MSG_DOC_FUNC8:String = 'Field "func8" should have documentation'; static inline var MSG_DOC_PARAM1_FUNC8:String = 'Documentation for parameter "param1" of field "func8" missing'; static inline var MSG_DOC_RETURN_FUNC8:String = 'Documentation for return value of field "func8" missing'; @@ -16,8 +22,15 @@ class FieldDocCommentCheckTest extends CheckTestCase assertNoMsg(check, INTERFACE); assertNoMsg(check, TYPEDEF); - assertMsg(check, ONLY_PRIVATE_CLASS_FIELDS_COMMENTED, MSG_DOC_FUNC8); - assertMsg(check, NO_CLASS_FIELDS_COMMENTED, MSG_DOC_FUNC8); + assertMessages(check, ONLY_PRIVATE_CLASS_FIELDS_COMMENTED, [MSG_DOC_FIELD2, MSG_DOC_FUNC8]); + assertMessages(check, NO_CLASS_FIELDS_COMMENTED, [ + MSG_DOC_FIELD2, + MSG_DOC_FUNC5, + MSG_DOC_FUNC5A, + MSG_DOC_FUNC6, + MSG_DOC_FUNC7, + MSG_DOC_FUNC8 + ]); assertMsg(check, MISSING_PARAM, MSG_DOC_PARAM1_FUNC8); assertMsg(check, MISSING_RETURN, MSG_DOC_RETURN_FUNC8); @@ -38,8 +51,15 @@ class FieldDocCommentCheckTest extends CheckTestCase assertNoMsg(check, INTERFACE); assertNoMsg(check, TYPEDEF); - assertMsg(check, ONLY_PRIVATE_CLASS_FIELDS_COMMENTED, MSG_DOC_FUNC8); - assertMsg(check, NO_CLASS_FIELDS_COMMENTED, MSG_DOC_FUNC8); + assertMessages(check, ONLY_PRIVATE_CLASS_FIELDS_COMMENTED, [MSG_DOC_FIELD2, MSG_DOC_FUNC8]); + assertMessages(check, NO_CLASS_FIELDS_COMMENTED, [ + MSG_DOC_FIELD2, + MSG_DOC_FUNC5, + MSG_DOC_FUNC5A, + MSG_DOC_FUNC6, + MSG_DOC_FUNC7, + MSG_DOC_FUNC8 + ]); assertMsg(check, MISSING_PARAM, MSG_DOC_PARAM1_FUNC8); assertMsg(check, MISSING_RETURN, MSG_DOC_RETURN_FUNC8); @@ -63,21 +83,21 @@ class FieldDocCommentCheckTest extends CheckTestCase check.modifier = PUBLIC; assertNoMsg(check, ALL_CLASS_FIELDS_COMMENTED); assertNoMsg(check, ONLY_PUBLIC_CLASS_FIELDS_COMMENTED); - assertMsg(check, ONLY_PRIVATE_CLASS_FIELDS_COMMENTED, MSG_DOC_FUNC8); + assertMessages(check, ONLY_PRIVATE_CLASS_FIELDS_COMMENTED, [MSG_DOC_FIELD2, MSG_DOC_FUNC8]); assertMsg(check, MISSING_PARAM, MSG_DOC_PARAM1_FUNC8); assertMsg(check, MISSING_RETURN, MSG_DOC_RETURN_FUNC8); check.modifier = PRIVATE; assertNoMsg(check, ALL_CLASS_FIELDS_COMMENTED); - assertMsg(check, ONLY_PUBLIC_CLASS_FIELDS_COMMENTED, MSG_DOC_FUNC4); + assertMessages(check, ONLY_PUBLIC_CLASS_FIELDS_COMMENTED, [MSG_DOC_FIELD1, MSG_DOC_FUNC4]); assertNoMsg(check, ONLY_PRIVATE_CLASS_FIELDS_COMMENTED); assertNoMsg(check, MISSING_PARAM); assertNoMsg(check, MISSING_RETURN); check.modifier = BOTH; assertNoMsg(check, ALL_CLASS_FIELDS_COMMENTED); - assertMsg(check, ONLY_PUBLIC_CLASS_FIELDS_COMMENTED, MSG_DOC_FUNC4); - assertMsg(check, ONLY_PRIVATE_CLASS_FIELDS_COMMENTED, MSG_DOC_FUNC8); + assertMessages(check, ONLY_PUBLIC_CLASS_FIELDS_COMMENTED, [MSG_DOC_FIELD1, MSG_DOC_FUNC4]); + assertMessages(check, ONLY_PRIVATE_CLASS_FIELDS_COMMENTED, [MSG_DOC_FIELD2, MSG_DOC_FUNC8]); assertMsg(check, MISSING_PARAM, MSG_DOC_PARAM1_FUNC8); assertMsg(check, MISSING_RETURN, MSG_DOC_RETURN_FUNC8); } @@ -88,7 +108,7 @@ class FieldDocCommentCheckTest extends CheckTestCase check.fieldType = VARS; assertNoMsg(check, ALL_CLASS_FIELDS_COMMENTED); assertNoMsg(check, ONLY_PUBLIC_CLASS_FIELDS_COMMENTED); - assertMsg(check, ONLY_PRIVATE_CLASS_FIELDS_COMMENTED, 'Field "field2" should have documentation'); + assertMsg(check, ONLY_PRIVATE_CLASS_FIELDS_COMMENTED, MSG_DOC_FIELD2); assertNoMsg(check, MISSING_PARAM); assertNoMsg(check, MISSING_RETURN); @@ -102,7 +122,7 @@ class FieldDocCommentCheckTest extends CheckTestCase check.fieldType = BOTH; assertNoMsg(check, ALL_CLASS_FIELDS_COMMENTED); assertNoMsg(check, ONLY_PUBLIC_CLASS_FIELDS_COMMENTED); - assertMsg(check, ONLY_PRIVATE_CLASS_FIELDS_COMMENTED, MSG_DOC_FUNC8); + assertMessages(check, ONLY_PRIVATE_CLASS_FIELDS_COMMENTED, [MSG_DOC_FIELD2, MSG_DOC_FUNC8]); assertMsg(check, MISSING_PARAM, MSG_DOC_PARAM1_FUNC8); assertMsg(check, MISSING_RETURN, MSG_DOC_RETURN_FUNC8); } diff --git a/test/checkstyle/checks/comments/TypeDocCommentCheckTest.hx b/test/checkstyle/checks/comments/TypeDocCommentCheckTest.hx index 7eca7737..9338d7c3 100644 --- a/test/checkstyle/checks/comments/TypeDocCommentCheckTest.hx +++ b/test/checkstyle/checks/comments/TypeDocCommentCheckTest.hx @@ -4,7 +4,22 @@ class TypeDocCommentCheckTest extends CheckTestCase { @Test public function testDefault() { var check = new TypeDocCommentCheck(); - checkComments(check, "TTest"); + + var shouldHaveExtra:Array = [ + for (t in ["ATest", "CTest", "ETest", "ITest", "TTest"]) 'Documentation for type "$t" should have at least one extra line of text' + ]; + var shouldContain:Array = [ + for (t in ["ATest", "CTest", "ETest", "ITest", "TTest"]) 'Documentation for type "$t" should contain text' + ]; + var shouldHave:Array = [ + for (t in ["ATest", "CTest", "ETest", "ITest", "TTest"]) 'Type "$t" should have documentation' + ]; + + assertNoMsg(check, ALL_TYPES_COMMENTED); + assertMessages(check, EMPTY_COMMENTS, shouldHaveExtra); + assertMessages(check, EMPTY_COMMENTS_2, shouldHaveExtra); + assertMessages(check, EMPTY_COMMENTS_3, shouldContain); + assertMessages(check, NO_COMMENTS, shouldHave); } @Test diff --git a/test/checkstyle/checks/imports/AvoidStarImportCheckTest.hx b/test/checkstyle/checks/imports/AvoidStarImportCheckTest.hx index fbe5f59e..c659e0a3 100644 --- a/test/checkstyle/checks/imports/AvoidStarImportCheckTest.hx +++ b/test/checkstyle/checks/imports/AvoidStarImportCheckTest.hx @@ -15,7 +15,7 @@ class AvoidStarImportCheckTest extends CheckTestCase assertMsg(check, STAR_IMPORT, MSG_STAR_IMPORT); assertMsg(check, CONDITIONAL_STAR_IMPORT_ISSUE_160, MSG_STAR_IMPORT); assertMsg(check, CONDITIONAL_ELSE_STAR_IMPORT, MSG_STAR_IMPORT); - assertMsg(check, CONDITIONAL_ELSEIF_STAR_IMPORT, MSG_STAR_IMPORT); + assertMessages(check, CONDITIONAL_ELSEIF_STAR_IMPORT, [MSG_STAR_IMPORT, MSG_STAR_IMPORT, MSG_STAR_IMPORT]); } } diff --git a/test/checkstyle/checks/literal/MultipleStringLiteralsCheckTest.hx b/test/checkstyle/checks/literal/MultipleStringLiteralsCheckTest.hx index e421d666..464aec07 100644 --- a/test/checkstyle/checks/literal/MultipleStringLiteralsCheckTest.hx +++ b/test/checkstyle/checks/literal/MultipleStringLiteralsCheckTest.hx @@ -17,7 +17,10 @@ class MultipleStringLiteralsCheckTest extends CheckTestCase { assertNoMsg(check, SINGLE_QUOTE); assertNoMsg(check, INTERPOLATION); assertNoMsg(check, NO_INTERPOLATION); - assertMsg(check, DOUBLE_QUOTE, 'String "test" uses double quotes instead of single quotes'); + assertMessages(check, DOUBLE_QUOTE, [ + 'String "check" uses double quotes instead of single quotes', + 'String "test" uses double quotes instead of single quotes', + 'String "xml" uses double quotes instead of single quotes', + 'String "test" uses double quotes instead of single quotes' + ]); assertMsg(check, SINGLE_QUOTE_WITH_EXCEPTION, "String \"test 'xml' \" uses double quotes instead of single quotes"); } @@ -22,7 +27,12 @@ class StringLiteralCheckTest extends CheckTestCase { assertNoMsg(check, INTERPOLATION); assertNoMsg(check, NO_INTERPOLATION); assertNoMsg(check, SINGLE_QUOTE_WITH_EXCEPTION); - assertMsg(check, DOUBLE_QUOTE, 'String "test" uses double quotes instead of single quotes'); + assertMessages(check, DOUBLE_QUOTE, [ + 'String "check" uses double quotes instead of single quotes', + 'String "test" uses double quotes instead of single quotes', + 'String "xml" uses double quotes instead of single quotes', + 'String "test" uses double quotes instead of single quotes' + ]); } @Test @@ -31,8 +41,28 @@ class StringLiteralCheckTest extends CheckTestCase { check.policy = ONLY_DOUBLE; check.allowException = false; assertNoMsg(check, DOUBLE_QUOTE); - assertMsg(check, SINGLE_QUOTE, 'String "test" uses single quotes instead of double quotes'); - assertMsg(check, INTERPOLATION, 'String "$$value is $${i++} $$i" uses single quotes instead of double quotes'); + assertMessages(check, SINGLE_QUOTE, [ + 'String "check" uses single quotes instead of double quotes', + 'String "test" uses single quotes instead of double quotes', + 'String "xml" uses single quotes instead of double quotes', + 'String "test" uses single quotes instead of double quotes' + ]); + assertMessages(check, INTERPOLATION, [ + 'String "Value is $$i" uses single quotes instead of double quotes', + 'String "Value is $$i" uses single quotes instead of double quotes', + 'String "$$value is i" uses single quotes instead of double quotes', + 'String "$$value is i" uses single quotes instead of double quotes', + 'String "$$value" uses single quotes instead of double quotes', + 'String "$$value" uses single quotes instead of double quotes', + 'String "Value is $${i++}" uses single quotes instead of double quotes', + 'String "Value is $${i++}" uses single quotes instead of double quotes', + 'String "Value is $${i++}$$" uses single quotes instead of double quotes', + 'String "Value is $${i++}$$" uses single quotes instead of double quotes', + 'String "Value is $${i++} $$i" uses single quotes instead of double quotes', + 'String "Value is $${i++} $$i" uses single quotes instead of double quotes', + 'String "$$value is $${i++} $$i" uses single quotes instead of double quotes', + 'String "$$value is $${i++} $$i" uses single quotes instead of double quotes' + ]); #if (haxeparser < "3.3.0") assertMsg(check, NO_INTERPOLATION, 'String "value $$$$is i" uses single quotes instead of double quotes'); #end @@ -46,8 +76,28 @@ class StringLiteralCheckTest extends CheckTestCase { check.allowException = true; assertNoMsg(check, DOUBLE_QUOTE); assertNoMsg(check, DOUBLE_QUOTE_WITH_EXCEPTION); - assertMsg(check, SINGLE_QUOTE, 'String "test" uses single quotes instead of double quotes'); - assertMsg(check, INTERPOLATION, 'String "$$value is $${i++} $$i" uses single quotes instead of double quotes'); + assertMessages(check, SINGLE_QUOTE, [ + 'String "check" uses single quotes instead of double quotes', + 'String "test" uses single quotes instead of double quotes', + 'String "xml" uses single quotes instead of double quotes', + 'String "test" uses single quotes instead of double quotes' + ]); + assertMessages(check, INTERPOLATION, [ + 'String "Value is $$i" uses single quotes instead of double quotes', + 'String "Value is $$i" uses single quotes instead of double quotes', + 'String "$$value is i" uses single quotes instead of double quotes', + 'String "$$value is i" uses single quotes instead of double quotes', + 'String "$$value" uses single quotes instead of double quotes', + 'String "$$value" uses single quotes instead of double quotes', + 'String "Value is $${i++}" uses single quotes instead of double quotes', + 'String "Value is $${i++}" uses single quotes instead of double quotes', + 'String "Value is $${i++}$$" uses single quotes instead of double quotes', + 'String "Value is $${i++}$$" uses single quotes instead of double quotes', + 'String "Value is $${i++} $$i" uses single quotes instead of double quotes', + 'String "Value is $${i++} $$i" uses single quotes instead of double quotes', + 'String "$$value is $${i++} $$i" uses single quotes instead of double quotes', + 'String "$$value is $${i++} $$i" uses single quotes instead of double quotes' + ]); #if (haxeparser < "3.3.0") assertMsg(check, NO_INTERPOLATION, 'String "value $$$$is i" uses single quotes instead of double quotes'); #end @@ -59,7 +109,12 @@ class StringLiteralCheckTest extends CheckTestCase { check.allowException = false; assertNoMsg(check, DOUBLE_QUOTE); assertNoMsg(check, INTERPOLATION); - assertMsg(check, SINGLE_QUOTE, 'String "test" uses single quotes instead of double quotes'); + assertMessages(check, SINGLE_QUOTE, [ + 'String "check" uses single quotes instead of double quotes', + 'String "test" uses single quotes instead of double quotes', + 'String "xml" uses single quotes instead of double quotes', + 'String "test" uses single quotes instead of double quotes' + ]); #if (haxeparser < "3.3.0") assertMsg(check, NO_INTERPOLATION, 'String "value $$$$is i" uses single quotes instead of double quotes'); #end @@ -73,7 +128,12 @@ class StringLiteralCheckTest extends CheckTestCase { assertNoMsg(check, DOUBLE_QUOTE); assertNoMsg(check, INTERPOLATION); assertNoMsg(check, DOUBLE_QUOTE_WITH_EXCEPTION); - assertMsg(check, SINGLE_QUOTE, 'String "test" uses single quotes instead of double quotes'); + assertMessages(check, SINGLE_QUOTE, [ + 'String "check" uses single quotes instead of double quotes', + 'String "test" uses single quotes instead of double quotes', + 'String "xml" uses single quotes instead of double quotes', + 'String "test" uses single quotes instead of double quotes' + ]); #if (haxeparser < "3.3.0") assertMsg(check, NO_INTERPOLATION, 'String "value $$$$is i" uses single quotes instead of double quotes'); #end diff --git a/test/checkstyle/checks/meta/RedundantAccessMetaCheckTest.hx b/test/checkstyle/checks/meta/RedundantAccessMetaCheckTest.hx index 68f461a2..6a7ca7bf 100644 --- a/test/checkstyle/checks/meta/RedundantAccessMetaCheckTest.hx +++ b/test/checkstyle/checks/meta/RedundantAccessMetaCheckTest.hx @@ -13,9 +13,19 @@ class RedundantAccessMetaCheckTest extends CheckTestCase { public function testModifiers() { var check = new ModifierOrderCheck(); check.modifiers = [DYNAMIC, PUBLIC_PRIVATE, OVERRIDE, INLINE, STATIC, MACRO]; - assertMsg(check, TEST1, 'modifier order for field "test6" is "public static inline" but should be "public inline static"'); + assertMessages(check, TEST1, [ + 'modifier order for field "test1" is "override public" but should be "public override"', + 'modifier order for field "test2" is "override private" but should be "private override"', + 'modifier order for field "test6" is "public static inline" but should be "public inline static"' + ]); assertNoMsg(check, TEST2); assertNoMsg(check, TEST3); assertNoMsg(check, TEST4); diff --git a/test/checkstyle/checks/modifier/RedundantModifierCheckTest.hx b/test/checkstyle/checks/modifier/RedundantModifierCheckTest.hx index da494f18..0e1c8b9a 100644 --- a/test/checkstyle/checks/modifier/RedundantModifierCheckTest.hx +++ b/test/checkstyle/checks/modifier/RedundantModifierCheckTest.hx @@ -28,7 +28,7 @@ class RedundantModifierCheckTest extends CheckTestCase { assertNoMsg(check, TEST); assertMsg(check, TEST1, message); assertMsg(check, TEST2, message); - assertMsg(check, TEST3, message); + assertMessages(check, TEST3, [message, message]); } @Test @@ -55,7 +55,10 @@ class ConstantNameCheckTest extends CheckTestCase { var check = new ConstantNameCheck(); check.format = "^[A-Z][a-z]*$"; - assertMsg(check, TEST, 'Invalid const signature: "COUNT2" (name should be "~/^[A-Z][a-z]*$/")'); + assertMessages(check, TEST, [ + 'Invalid const signature: "COUNT" (name should be "~/^[A-Z][a-z]*$/")', + 'Invalid const signature: "COUNT2" (name should be "~/^[A-Z][a-z]*$/")' + ]); assertNoMsg(check, TEST1); assertNoMsg(check, TEST2); assertNoMsg(check, TEST3); diff --git a/test/checkstyle/checks/naming/LocalVariableNameCheckTest.hx b/test/checkstyle/checks/naming/LocalVariableNameCheckTest.hx index fe065e5d..c02a0968 100644 --- a/test/checkstyle/checks/naming/LocalVariableNameCheckTest.hx +++ b/test/checkstyle/checks/naming/LocalVariableNameCheckTest.hx @@ -34,7 +34,10 @@ class LocalVariableNameCheckTest extends CheckTestCase { assertMsg(check, TEST1, 'Invalid member signature: "Count" (name should be "~/${check.format}/")'); assertMsg(check, TEST2, 'Invalid member signature: "Count" (name should be "~/${check.format}/")'); assertMsg(check, TEST3, 'Invalid typedef member signature: "Count" (name should be "~/${check.format}/")'); - assertMsg(check, TEST5, 'Invalid enum member signature: "VALUE_TEST" (name should be "~/${check.format}/")'); + assertMessages(check, TEST5, [ + 'Invalid enum member signature: "VALUE_TEST_" (name should be "~/^[a-z][a-zA-Z0-9]*$/")', + 'Invalid enum member signature: "VALUE_TEST" (name should be "~/${check.format}/")' + ]); assertMsg(check, PROPERTY_NAME, 'Invalid member signature: "Example" (name should be "~/^[a-z][a-zA-Z0-9]*$/")'); - assertMsg(check, ABSTRACT_FIELDS, 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")'); + assertMessages(check, ABSTRACT_FIELDS, [ + 'Invalid member signature: "EnumConstructor1" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor2" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")' + ]); } @Test @@ -30,7 +37,10 @@ class MemberNameCheckTest extends CheckTestCase { assertMsg(check, TEST2, memberMessage); assertMsg(check, TEST3, 'Invalid typedef member signature: "Count" (name should be "~/${check.format}/")'); assertMsg(check, TEST4, memberMessage); - assertMsg(check, TEST5, 'Invalid enum member signature: "VALUE_TEST" (name should be "~/${check.format}/")'); + assertMessages(check, TEST5, [ + 'Invalid enum member signature: "VALUE_TEST_" (name should be "~/^[a-z][a-zA-Z0-9]*$/")', + 'Invalid enum member signature: "VALUE_TEST" (name should be "~/${check.format}/")' + ]); } @Test @@ -124,8 +134,14 @@ class MemberNameCheckTest extends CheckTestCase { assertNoMsg(check, TEST1); assertNoMsg(check, TEST3); assertNoMsg(check, TEST4); - assertMsg(check, TEST5, 'Invalid enum member signature: "VALUE_TEST" (name should be "~/${check.format}/")'); - assertMsg(check, TEST6, 'Invalid enum member signature: "VALUE" (name should be "~/${check.format}/")'); + assertMessages(check, TEST5, [ + 'Invalid enum member signature: "VALUE_TEST_" (name should be "~/${check.format}/")', + 'Invalid enum member signature: "VALUE_TEST" (name should be "~/${check.format}/")' + ]); + assertMessages(check, TEST6, [ + 'Invalid enum member signature: "VALUE_" (name should be "~/${check.format}/")', + 'Invalid enum member signature: "VALUE" (name should be "~/${check.format}/")' + ]); assertNoMsg(check, ABSTRACT_FIELDS); } @@ -147,14 +163,27 @@ class MemberNameCheckTest extends CheckTestCase { var check = new MemberNameCheck(); check.format = "^[A-Z_]*$"; - assertMsg(check, TEST, 'Invalid typedef member signature: "count2" (name should be "~/${check.format}/")'); + assertMessages(check, TEST, [ + 'Invalid member signature: "a" (name should be "~/${check.format}/")', + 'Invalid member signature: "b" (name should be "~/${check.format}/")', + 'Invalid member signature: "example" (name should be "~/${check.format}/")', + 'Invalid member signature: "count5" (name should be "~/${check.format}/")', + 'Invalid enum member signature: "count" (name should be "~/${check.format}/")', + 'Invalid enum member signature: "a" (name should be "~/${check.format}/")', + 'Invalid typedef member signature: "count1" (name should be "~/${check.format}/")', + 'Invalid typedef member signature: "count2" (name should be "~/${check.format}/")' + ]); assertMsg(check, TEST1, 'Invalid member signature: "Count" (name should be "~/${check.format}/")'); assertMsg(check, TEST2, 'Invalid member signature: "Count" (name should be "~/${check.format}/")'); assertMsg(check, TEST3, 'Invalid typedef member signature: "Count" (name should be "~/${check.format}/")'); assertNoMsg(check, TEST4); assertNoMsg(check, TEST5); assertNoMsg(check, TEST6); - assertMsg(check, ABSTRACT_FIELDS, 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")'); + assertMessages(check, ABSTRACT_FIELDS, [ + 'Invalid member signature: "EnumConstructor1" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor2" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")' + ]); check.format = "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"; assertMsg(check, TEST5, 'Invalid enum member signature: "VALUE_TEST_" (name should be "~/${check.format}/")'); @@ -168,11 +197,19 @@ class MemberNameCheckTest extends CheckTestCase { check.format = "^[A-Z_]*$"; assertNoMsg(check, TEST); - assertMsg(check, ABSTRACT_FIELDS, 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")'); + assertMessages(check, ABSTRACT_FIELDS, [ + 'Invalid member signature: "EnumConstructor1" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor2" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")' + ]); check.tokens = [ABSTRACT]; assertNoMsg(check, TEST); - assertMsg(check, ABSTRACT_FIELDS, 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")'); + assertMessages(check, ABSTRACT_FIELDS, [ + 'Invalid member signature: "EnumConstructor1" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor2" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")' + ]); check.tokens = [ABSTRACT, PRIVATE]; assertNoMsg(check, ABSTRACT_FIELDS); @@ -184,13 +221,25 @@ class MemberNameCheckTest extends CheckTestCase { assertNoMsg(check, ABSTRACT_FIELDS); check.tokens = [ABSTRACT, PUBLIC]; - assertMsg(check, ABSTRACT_FIELDS, 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")'); + assertMessages(check, ABSTRACT_FIELDS, [ + 'Invalid member signature: "EnumConstructor1" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor2" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")' + ]); check.tokens = [PUBLIC]; - assertMsg(check, ABSTRACT_FIELDS, 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")'); + assertMessages(check, ABSTRACT_FIELDS, [ + 'Invalid member signature: "EnumConstructor1" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor2" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")' + ]); check.tokens = [ABSTRACT, CLASS, PUBLIC]; - assertMsg(check, ABSTRACT_FIELDS, 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")'); + assertMessages(check, ABSTRACT_FIELDS, [ + 'Invalid member signature: "EnumConstructor1" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor2" (name should be "~/${check.format}/")', + 'Invalid member signature: "EnumConstructor3" (name should be "~/${check.format}/")' + ]); } @Test diff --git a/test/checkstyle/checks/naming/MethodNameCheckTest.hx b/test/checkstyle/checks/naming/MethodNameCheckTest.hx index 480d0e0d..c058f8e6 100644 --- a/test/checkstyle/checks/naming/MethodNameCheckTest.hx +++ b/test/checkstyle/checks/naming/MethodNameCheckTest.hx @@ -11,11 +11,14 @@ class MethodNameCheckTest extends CheckTestCase { @Test public function testWrongNaming() { var check = new MethodNameCheck(); + var testMessage = 'Invalid method name signature: "Test" (name should be "~/${check.format}/")'; + var test1Message = 'Invalid method name signature: "Test1" (name should be "~/${check.format}/")'; + var test2Message = 'Invalid method name signature: "Test2" (name should be "~/${check.format}/")'; var test3Message = 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'; - assertMsg(check, TEST1, test3Message); - assertMsg(check, TEST2, test3Message); + assertMessages(check, TEST1, [testMessage, test2Message, test3Message]); + assertMessages(check, TEST2, [testMessage, test1Message, test2Message, test3Message]); assertMsg(check, TEST3, 'Invalid method name signature: "Test" (name should be "~/${check.format}/")'); - assertMsg(check, TEST5, test3Message); + assertMessages(check, TEST5, [testMessage, test1Message, test3Message]); } @Test @@ -24,23 +27,29 @@ class MethodNameCheckTest extends CheckTestCase { check.ignoreExtern = false; var testMessage = 'Invalid method name signature: "Test" (name should be "~/${check.format}/")'; + var test1Message = 'Invalid method name signature: "Test1" (name should be "~/${check.format}/")'; + var test2Message = 'Invalid method name signature: "Test2" (name should be "~/${check.format}/")'; var test3Message = 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'; assertNoMsg(check, TEST); - assertMsg(check, TEST1, test3Message); - assertMsg(check, TEST2, test3Message); + assertMessages(check, TEST1, [testMessage, test2Message, test3Message]); + assertMessages(check, TEST2, [testMessage, test1Message, test2Message, test3Message]); assertMsg(check, TEST3, testMessage); assertMsg(check, TEST4, testMessage); - assertMsg(check, TEST5, test3Message); + assertMessages(check, TEST5, [testMessage, test1Message, test3Message]); } @Test public function testTokenPUBLIC() { var check = new MethodNameCheck(); check.tokens = [PUBLIC]; + var testMessage = 'Invalid method name signature: "Test" (name should be "~/${check.format}/")'; + var test1Message = 'Invalid method name signature: "Test1" (name should be "~/${check.format}/")'; + var test2Message = 'Invalid method name signature: "Test2" (name should be "~/${check.format}/")'; + var test3Message = 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'; assertNoMsg(check, TEST); - assertMsg(check, TEST1, 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'); - assertMsg(check, TEST2, 'Invalid method name signature: "Test2" (name should be "~/${check.format}/")'); + assertMessages(check, TEST1, [testMessage, test2Message, test3Message]); + assertMessages(check, TEST2, [testMessage, test1Message, test2Message]); assertMsg(check, TEST3, 'Invalid method name signature: "Test" (name should be "~/${check.format}/")'); assertNoMsg(check, TEST4); assertNoMsg(check, TEST5); @@ -51,38 +60,48 @@ class MethodNameCheckTest extends CheckTestCase { var check = new MethodNameCheck(); check.tokens = [PRIVATE]; + var testMessage = 'Invalid method name signature: "Test" (name should be "~/${check.format}/")'; + var test1Message = 'Invalid method name signature: "Test1" (name should be "~/${check.format}/")'; + var test3Message = 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'; assertNoMsg(check, TEST); assertNoMsg(check, TEST1); - assertMsg(check, TEST2, 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'); + assertMsg(check, TEST2, test3Message); assertNoMsg(check, TEST3); assertNoMsg(check, TEST4); - assertMsg(check, TEST5, 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'); + assertMessages(check, TEST5, [testMessage, test1Message, test3Message]); } @Test public function testTokenSTATIC() { var check = new MethodNameCheck(); check.tokens = [STATIC]; + var testMessage = 'Invalid method name signature: "Test" (name should be "~/${check.format}/")'; + var test1Message = 'Invalid method name signature: "Test1" (name should be "~/${check.format}/")'; + var test3Message = 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'; assertNoMsg(check, TEST); - assertMsg(check, TEST1, 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'); - assertMsg(check, TEST2, 'Invalid method name signature: "Test1" (name should be "~/${check.format}/")'); + assertMessages(check, TEST1, [testMessage, test3Message]); + assertMessages(check, TEST2, [testMessage, test1Message]); assertNoMsg(check, TEST3); assertNoMsg(check, TEST4); - assertMsg(check, TEST5, 'Invalid method name signature: "Test1" (name should be "~/${check.format}/")'); + assertMessages(check, TEST5, [testMessage, test1Message]); } @Test public function testTokenNOTSTATIC() { var check = new MethodNameCheck(); check.tokens = [NOTSTATIC]; + var testMessage = 'Invalid method name signature: "Test" (name should be "~/${check.format}/")'; + var test2Message = 'Invalid method name signature: "Test2" (name should be "~/${check.format}/")'; + var test3Message = 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'; assertNoMsg(check, TEST); - assertMsg(check, TEST1, 'Invalid method name signature: "Test2" (name should be "~/${check.format}/")'); - assertMsg(check, TEST2, 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'); - assertMsg(check, TEST3, 'Invalid method name signature: "Test" (name should be "~/${check.format}/")'); + assertMsg(check, TEST1, test2Message); + assertMessages(check, TEST2, [test2Message, test3Message]); + + assertMsg(check, TEST3, testMessage); assertNoMsg(check, TEST4); - assertMsg(check, TEST5, 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'); + assertMsg(check, TEST5, test3Message); } @Test @@ -102,13 +121,16 @@ class MethodNameCheckTest extends CheckTestCase { public function testTokenNOTINLINE() { var check = new MethodNameCheck(); check.tokens = [NOTINLINE]; + var testMessage = 'Invalid method name signature: "Test" (name should be "~/${check.format}/")'; + var test2Message = 'Invalid method name signature: "Test2" (name should be "~/${check.format}/")'; + var test3Message = 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'; assertNoMsg(check, TEST); - assertMsg(check, TEST1, 'Invalid method name signature: "Test2" (name should be "~/${check.format}/")'); - assertMsg(check, TEST2, 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'); - assertMsg(check, TEST3, 'Invalid method name signature: "Test" (name should be "~/${check.format}/")'); + assertMessages(check, TEST1, [testMessage, test2Message]); + assertMessages(check, TEST2, [testMessage, test2Message, test3Message]); + assertMsg(check, TEST3, testMessage); assertNoMsg(check, TEST4); - assertMsg(check, TEST5, 'Invalid method name signature: "Test3" (name should be "~/${check.format}/")'); + assertMessages(check, TEST5, [testMessage, test3Message]); } @Test @@ -116,7 +138,13 @@ class MethodNameCheckTest extends CheckTestCase { var check = new MethodNameCheck(); check.format = "^[A-Z][a-z0-9]*$"; - assertMsg(check, TEST, 'Invalid method name signature: "testName" (name should be "~/${check.format}/")'); + assertMessages(check, TEST, [ + 'Invalid method name signature: "test" (name should be "~/${check.format}/")', + 'Invalid method name signature: "testName" (name should be "~/${check.format}/")', + 'Invalid method name signature: "testValue" (name should be "~/${check.format}/")', + 'Invalid method name signature: "test" (name should be "~/${check.format}/")', + 'Invalid method name signature: "testName" (name should be "~/${check.format}/")' + ]); assertNoMsg(check, TEST1); assertNoMsg(check, TEST2); assertNoMsg(check, TEST3); diff --git a/test/checkstyle/checks/naming/ParameterNameCheckTest.hx b/test/checkstyle/checks/naming/ParameterNameCheckTest.hx index 6e1ae711..a04d944d 100644 --- a/test/checkstyle/checks/naming/ParameterNameCheckTest.hx +++ b/test/checkstyle/checks/naming/ParameterNameCheckTest.hx @@ -36,7 +36,13 @@ class ParameterNameCheckTest extends CheckTestCase { var check = new ParameterNameCheck(); check.format = "^[A-Z][a-zA-Z]*$"; - assertMsg(check, TEST, 'Invalid parameter name signature: "paramName" (name should be "~/${check.format}/")'); + assertMessages(check, TEST, [ + 'Invalid parameter name signature: "param1" (name should be "~/${check.format}/")', + 'Invalid parameter name signature: "paramName" (name should be "~/${check.format}/")', + 'Invalid parameter name signature: "param" (name should be "~/${check.format}/")', + 'Invalid parameter name signature: "param1" (name should be "~/${check.format}/")', + 'Invalid parameter name signature: "paramName" (name should be "~/${check.format}/")' + ]); assertNoMsg(check, TEST2); assertNoMsg(check, TEST1); assertMsg(check, TEST3, 'Invalid parameter name signature: "param1" (name should be "~/${check.format}/")'); diff --git a/test/checkstyle/checks/naming/TypeNameCheckTest.hx b/test/checkstyle/checks/naming/TypeNameCheckTest.hx index bcaca2b2..e32352fe 100644 --- a/test/checkstyle/checks/naming/TypeNameCheckTest.hx +++ b/test/checkstyle/checks/naming/TypeNameCheckTest.hx @@ -21,7 +21,12 @@ class TypeNameCheckTest extends CheckTestCase { var check = new TypeNameCheck(); check.format = FORMAT_CLASS; - assertMsg(check, TEST, 'Invalid typedef signature: "Test3" (name should be "~/^C[A-Z][a-z]*$/")'); + assertMessages(check, TEST, [ + 'Invalid class signature: "Test" (name should be "~/^C[A-Z][a-z]*$/")', + 'Invalid interface signature: "ITest" (name should be "~/^C[A-Z][a-z]*$/")', + 'Invalid enum signature: "Test2" (name should be "~/^C[A-Z][a-z]*$/")', + 'Invalid typedef signature: "Test3" (name should be "~/^C[A-Z][a-z]*$/")' + ]); assertNoMsg(check, TEST1); assertMsg(check, TEST2, 'Invalid interface signature: "Test" (name should be "~/^C[A-Z][a-z]*$/")'); assertMsg(check, TEST3, 'Invalid typedef signature: "TTest" (name should be "~/^C[A-Z][a-z]*$/")'); diff --git a/test/checkstyle/checks/type/EnforceVarTypeHintCheckTest.hx b/test/checkstyle/checks/type/EnforceVarTypeHintCheckTest.hx deleted file mode 100644 index 313260af..00000000 --- a/test/checkstyle/checks/type/EnforceVarTypeHintCheckTest.hx +++ /dev/null @@ -1,62 +0,0 @@ -package checkstyle.checks.type; - -class EnforceVarTypeHintCheckTest extends CheckTestCase { - @Test - public function testCorrectTypeHints() { - var check = new EnforceVarTypeHintCheck(); - assertNoMsg(check, CORRECT_TYPE_HINTS); - assertNoMsg(check, ABSTRACT_ENUM); - assertNoMsg(check, ABSTRACT_ENUM2); - assertMsg(check, TYPEDEF, 'Variable "risk" has no type hint'); - #if haxe4 - assertNoMsg(check, FINAL_FUNCTION); - assertMsg(check, FINAL_VAR, 'Variable "a" has no type hint'); - - assertNoMsg(check, DOLLAR_VAR_CORRECT); - assertMsg(check, DOLLAR_VAR, 'Variable "$$a" has no type hint'); - #end - - check.ignoreEnumAbstractValues = false; - assertMsg(check, ABSTRACT_ENUM, 'Variable "STYLE" has no type hint'); - assertMsg(check, ABSTRACT_ENUM2, 'Variable "STYLE" has no type hint'); - } -} - -@:enum -abstract EnforceVarTypeHintCheckTests(String) to String { - var CORRECT_TYPE_HINTS = " - abstractAndClass Test { - var a:Int; - - @SuppressWarnings('checkstyle:EnforceVarTypeHint') - var _b; - }"; - var ABSTRACT_ENUM = " - @:enum abstract Category(String) { - var STYLE = 'Style'; - }"; - var ABSTRACT_ENUM2 = " - enum abstract Category(String) { - var STYLE = 'Style'; - }"; - var TYPEDEF = " - typedef Category = { - var risk; - }"; - var FINAL_VAR = " - abstractAndClass Test { - final a; - }"; - var FINAL_FUNCTION = " - abstractAndClass Test { - final function test() {}; - }"; - var DOLLAR_VAR = " - abstractAndClass Test { - var $a; - }"; - var DOLLAR_VAR_CORRECT = " - abstractAndClass Test { - var $a:Int; - }"; -} \ No newline at end of file diff --git a/test/checkstyle/checks/type/VarTypeHintCheckTest.hx b/test/checkstyle/checks/type/VarTypeHintCheckTest.hx new file mode 100644 index 00000000..d12a36f7 --- /dev/null +++ b/test/checkstyle/checks/type/VarTypeHintCheckTest.hx @@ -0,0 +1,342 @@ +package checkstyle.checks.type; + +class VarTypeHintCheckTest extends CheckTestCase { + @Test + public function testEnforceTypeHints() { + var check = new VarTypeHintCheck(); + check.typeHintPolicy = ENFORCE_ALL; + assertNoMsg(check, SUPPRESSED_LOCAL_VARS); + + var messages:Array = [for (t in [ + "test1", "test2", "test3", "test6", "test9", + "test10", "test11", "test12", "test13", "test14", + "test15", "test26", "test27", "test28", "test31", + "test32", "test33", "test34", "test39", "test41" + ]) { + '"$t" should have a type hint'; + }]; + + assertMessages(check, LOCAL_VARS, messages); + #if haxe4 + assertMessages(check, LOCAL_FINALS, messages); + + messages = [for (t in ["test1", "test9", "test13", "test26", "test32", "test39"]) { + '"$t" should have a type hint'; + }]; + assertMessages(check, MODULE_LEVEL_VARS, messages); + assertMessages(check, MODULE_LEVEL_FINALS, messages); + assertMessages(check, TYPEDEF, ['"test0" should have a type hint', '"test1" should have a type hint']); + #end + + assertNoMsg(check, ENUM); + assertMessages(check, INTERFACE, ['"test0" should have a type hint']); + } + + @Test + public function testInferConstAndNewTypeHints() { + var check = new VarTypeHintCheck(); + check.typeHintPolicy = INFER_NEW_OR_CONST; + assertNoMsg(check, SUPPRESSED_LOCAL_VARS); + + var messages:Array = [for (t in ["test1", "test2", "test3", "test6", "test12"]) { + '"$t" should have a type hint'; + }]; + messages = messages.concat([ + for (t in ["test16", "test17", "test20", "test21", "test22", "test29", "test30"]) { + '"$t" type hint not needed'; + } + ]); + messages = messages.concat([for (t in ["test32", "test33", "test34"]) { + '"$t" should have a type hint'; + }]); + messages.push('"test40" type hint not needed'); + + assertMessages(check, LOCAL_VARS, messages); + #if haxe4 + assertMessages(check, LOCAL_FINALS, messages); + + messages = [ + '"test1" should have a type hint', + '"test16" type hint not needed', + '"test29" type hint not needed', + '"test32" should have a type hint' + ]; + assertMessages(check, MODULE_LEVEL_VARS, messages); + assertMessages(check, MODULE_LEVEL_FINALS, messages); + assertMessages(check, TYPEDEF, ['"test0" should have a type hint', '"test1" should have a type hint']); + #end + assertNoMsg(check, ENUM); + assertMessages(check, INTERFACE, ['"test0" should have a type hint']); + } + + @Test + public function testInferAllTypeHints() { + var check = new VarTypeHintCheck(); + check.typeHintPolicy = INFER_ALL; + assertNoMsg(check, SUPPRESSED_LOCAL_VARS); + var messages:Array = [for (t in ["test1", "test2", "test3", "test6", "test12"]) { + '"$t" should have a type hint'; + }]; + messages = messages.concat([for (t in [ + "test16", "test17", "test20", "test21", "test22", "test29", + "test30", "test35", "test36", "test37", "test38", "test40" + ]) { + '"$t" type hint not needed'; + }]); + + assertMessages(check, LOCAL_VARS, messages); + #if haxe4 + assertMessages(check, LOCAL_FINALS, messages); + + messages = [ + '"test1" should have a type hint', + '"test16" type hint not needed', + '"test29" type hint not needed', + '"test35" type hint not needed', + '"test38" type hint not needed' + ]; + assertMessages(check, MODULE_LEVEL_VARS, messages); + assertMessages(check, MODULE_LEVEL_FINALS, messages); + assertMessages(check, TYPEDEF, ['"test0" should have a type hint', '"test1" should have a type hint']); + #end + assertNoMsg(check, ENUM); + assertMessages(check, INTERFACE, ['"test0" should have a type hint']); + } + + @Test + public function testCorrectTypeHints() { + var check = new VarTypeHintCheck(); + check.typeHintPolicy = ENFORCE_ALL; + + assertNoMsg(check, CORRECT_TYPE_HINTS); + assertNoMsg(check, ABSTRACT_ENUM); + assertNoMsg(check, ABSTRACT_ENUM2); + assertMsg(check, TYPEDEF_OLD, '"risk" should have a type hint'); + #if haxe4 + assertNoMsg(check, FINAL_FUNCTION); + assertMsg(check, FINAL_VAR, '"a" should have a type hint'); + + assertNoMsg(check, DOLLAR_VAR_CORRECT); + assertMsg(check, DOLLAR_VAR, '"$$a" should have a type hint'); + #end + + check.ignoreEnumAbstractValues = false; + assertMsg(check, ABSTRACT_ENUM, '"STYLE" should have a type hint'); + assertMsg(check, ABSTRACT_ENUM2, '"STYLE" should have a type hint'); + } +} + +@:enum +abstract VarTypeHintCheckTests(String) to String { + var MODULE_LEVEL_VARS = " + var test0:Int; + var test1; + var test9 = 10; + var test13 = '10'; + var test16:Int = 10; + + var test26 = new Test(); + var test29:Test = new Test(); + var test32 = call(); + var test35:Test = call(); + var test38:Test = /** **/ call(); + + var test39 = true; + "; + var MODULE_LEVEL_FINALS = " + final test0:Int; + final test1; + final test9 = 10; + final test13 = '10'; + final test16:Int = 10; + + final test26 = new Test(); + final test29:Test = new Test(); + final test32 = call(); + final test35:Test = call(); + final test38:Test = /** **/ call(); + + final test39 = true; + "; + var LOCAL_VARS = " + abstractAndClass Test { + function test() { + var test0:Int; + var test1, test2; + var test3, test4:Int; + var test5:Int, test6; + var test7:Int, test8:Int; + + var test9 = 10; + var test10 = 10, test11 = '10'; + var test12, test13 = '10'; + var test14 = 10, test15 = '12'; + + var test16:Int = 10; + var test17:Int = 10, test18:String; + var test19:Int, test20:String = '14'; + var test21:Int = 10, test22:String = '14'; + + // var @:meta test23:Int = 10; + // var @:meta test24:Int = 10, @:meta test25:Int = 10; + + var test26 = new Test(); + var test27 = new Test(), test28 = new Test2(); + + var test29:Test = new Test(); + var test30:Test = new Test(), test31 = new Test2(); + + var test32 = call(); + var test33 = call(), test34 = call(); + + var test35:Test = call(); + var test36:Test = call(), test37:Test = call(); + + var test38:Test = /** **/ call(); + + var test39 = true; + var test40:Bool = true, test41 = false; + }; + } + "; + var LOCAL_FINALS = " + abstractAndClass Test { + function test() { + final test0:Int; + final test1, test2; + final test3, test4:Int; + final test5:Int, test6; + final test7:Int, test8:Int; + + final test9 = 10; + final test10 = 10, test11 = '10'; + final test12, test13 = '10'; + final test14 = 10, test15 = '12'; + + final test16:Int = 10; + final test17:Int = 10, test18:String; + final test19:Int, test20:String = '14'; + final test21:Int = 10, test22:String = '14'; + + // final @:meta test23:Int = 10; + // final @:meta test24:Int = 10, @:meta test25:Int = 10; + + final test26 = new Test(); + final test27 = new Test(), test28 = new Test2(); + + final test29:Test = new Test(); + final test30:Test = new Test(), test31 = new Test2(); + + final test32 = call(); + final test33 = call(), test34 = call(); + + final test35:Test = call(); + final test36:Test = call(), test37:Test = call(); + + final test38:Test = /** **/ call(); + + final test39 = true; + final test40:Bool = true, test41 = false; + }; + } + "; + var SUPPRESSED_LOCAL_VARS = " + abstractAndClass Test { + @SuppressWarnings('checkstyle:VarTypeHint') + function test() { + var test0:Int; + var test1, test2; + var test3, test4:Int; + var test5:Int, test6; + var test7:Int, test8:Int; + + var test9 = 10; + var test10 = 10, test11 = '10'; + var test12, test13 = '10'; + var test14 = 10, test15 = '12'; + + var test16:Int = 10; + var test17:Int = 10, test18:String; + var test19:Int, test20:String = '14'; + var test21:Int = 10, test22:String = '14'; + + // var @:meta test23:Int = 10; + // var @:meta test24:Int = 10, @:meta test25:Int = 10; + + var test26 = new Test(); + var test27 = new Test(), test28 = new Test2(); + + var test29:Test = new Test(); + var test30:Test = new Test(), test31 = new Test2(); + + var test32 = call(); + var test33 = call(), test34 = call(); + + var test35:Test = call(); + var test36:Test = call(), test37:Test = call(); + + var test38:Test = /** **/ call(); + }; + } + "; + var ENUM = " + @:enum abstract Category(String) { + var STYLE = 'Style'; + } + enum abstract Category(String) { + var STYLE = 'Style'; + } + enum Category { + STYLE; + } + "; + var TYPEDEF = " + typedef Category = { + var test0; + var ?test1; + var test2:Int; + var ?test3:Int; + } + "; + var INTERFACE = " + interface Category { + var test0; + var test1:Int; + } + "; + var CORRECT_TYPE_HINTS = " + abstractAndClass Test { + var a:Int; + + @SuppressWarnings('checkstyle:VarTypeHint') + var _b; + }"; + var ABSTRACT_ENUM = " + @:enum abstract Category(String) { + var STYLE = 'Style'; + }"; + var ABSTRACT_ENUM2 = " + enum abstract Category(String) { + var STYLE = 'Style'; + }"; + var TYPEDEF_OLD = " + typedef Category = { + var risk; + }"; + var FINAL_VAR = " + abstractAndClass Test { + final a; + }"; + var FINAL_FUNCTION = " + abstractAndClass Test { + final function test() {}; + }"; + var DOLLAR_VAR = " + abstractAndClass Test { + var $a; + }"; + var DOLLAR_VAR_CORRECT = " + abstractAndClass Test { + var $a:Int; + }"; +} \ No newline at end of file diff --git a/test/checkstyle/checks/whitespace/ArrayAccessCheckTest.hx b/test/checkstyle/checks/whitespace/ArrayAccessCheckTest.hx index eb3befe0..a7dd28fc 100644 --- a/test/checkstyle/checks/whitespace/ArrayAccessCheckTest.hx +++ b/test/checkstyle/checks/whitespace/ArrayAccessCheckTest.hx @@ -11,7 +11,7 @@ class ArrayAccessCheckTest extends CheckTestCase { var check = new ArrayAccessCheck(); assertMsg(check, TEST2, "Space between [ and index"); assertMsg(check, TEST3, "Space between index and ]"); - assertMsg(check, TEST4, "Space between index and ]"); + assertMessages(check, TEST4, ["Space between [ and index", "Space between index and ]"]); } @Test diff --git a/test/checkstyle/checks/whitespace/ExtendedEmptyLinesCheckTest.hx b/test/checkstyle/checks/whitespace/ExtendedEmptyLinesCheckTest.hx index a2fe7980..974c73aa 100644 --- a/test/checkstyle/checks/whitespace/ExtendedEmptyLinesCheckTest.hx +++ b/test/checkstyle/checks/whitespace/ExtendedEmptyLinesCheckTest.hx @@ -1,7 +1,7 @@ package checkstyle.checks.whitespace; -import haxe.PosInfos; import checkstyle.checks.whitespace.ExtendedEmptyLinesCheck.EmptyLinesPlace; +import haxe.PosInfos; class ExtendedEmptyLinesCheckTest extends CheckTestCase { static inline var MSG_NONE:String = "should not have empty line(s)"; @@ -24,12 +24,12 @@ class ExtendedEmptyLinesCheckTest extends CheckTestCase = [for (i in 0...msgCount) MSG_EXACT_1 + postfix]; + assertMessages(check, TEST_EXACT_2, messages); + if (hasFixedPosition) assertMessages(check, TEST_NONE, messages); check.exact = []; check.none = [fieldName]; - assertMsg(check, TEST_EXACT_1, MSG_NONE + postfix); - assertMsg(check, TEST_EXACT_2, MSG_NONE + postfix); + messages = [for (i in 0...msgCount) MSG_NONE + postfix]; + assertMessages(check, TEST_EXACT_1, messages); + assertMessages(check, TEST_EXACT_2, messages); assertNoMsg(check, TEST_NONE); check.none = []; check.upto = [fieldName]; + messages = [for (i in 0...msgCount) MSG_UPTO_1 + postfix]; assertNoMsg(check, TEST_EXACT_1); - assertMsg(check, TEST_EXACT_2, MSG_UPTO_1 + postfix); + assertMessages(check, TEST_EXACT_2, messages); assertNoMsg(check, TEST_NONE); check.upto = []; check.atleast = [fieldName]; assertNoMsg(check, TEST_EXACT_1); assertNoMsg(check, TEST_EXACT_2); - if (hasFixedPosition) assertMsg(check, TEST_NONE, MSG_ATLEAST_1 + postfix); + + messages = [for (i in 0...msgCount) MSG_ATLEAST_1 + postfix]; + if (hasFixedPosition) assertMessages(check, TEST_NONE, messages); } - function runChecksMax2(check:ExtendedEmptyLinesCheck, fieldName:EmptyLinesPlace, postfix:String, hasFixedPosition:Bool = true, ?pos:PosInfos) { + function runChecksMax2(check:ExtendedEmptyLinesCheck, fieldName:EmptyLinesPlace, postfix:String, hasFixedPosition:Bool = true, msgCount:Int = 1, + ?pos:PosInfos) { check.max = 2; check.atleast = []; check.exact = [fieldName]; - assertMsg(check, TEST_EXACT_1, MSG_EXACT_2 + postfix); + var messages:Array = [for (i in 0...msgCount) MSG_EXACT_2 + postfix]; + assertMessages(check, TEST_EXACT_1, messages); assertNoMsg(check, TEST_EXACT_2); - if (hasFixedPosition) assertMsg(check, TEST_NONE, MSG_EXACT_2 + postfix); + if (hasFixedPosition) assertMessages(check, TEST_NONE, messages); check.exact = []; check.none = [fieldName]; - assertMsg(check, TEST_EXACT_1, MSG_NONE + postfix); - assertMsg(check, TEST_EXACT_2, MSG_NONE + postfix); + messages = [for (i in 0...msgCount) MSG_NONE + postfix]; + assertMessages(check, TEST_EXACT_1, messages); + assertMessages(check, TEST_EXACT_2, messages); assertNoMsg(check, TEST_NONE); check.none = []; @@ -255,9 +264,10 @@ class ExtendedEmptyLinesCheckTest extends CheckTestCase { assertNoMsg(check, FUNCTION_BODY_NO_BRACES); assertNoMsg(check, CORRECT_DOUBLE_FOR); assertNoMsg(check, CORRECT_ARROW_INDENT); - assertMsg(check, CORRECT_SPACE_INDENT, 'Indentation mismatch: expected: "\\t"[1], actual: no indentation'); + assertMessages(check, CORRECT_SPACE_INDENT, [ + 'Indentation mismatch: expected: "\\t"[1], actual: no indentation', + 'Indentation mismatch: expected: "\\t"[1], actual: no indentation', + 'Indentation mismatch: expected: "\\t"[1], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t\\t"[3], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t\\t"[3], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t\\t"[3], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t\\t"[3], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t\\t"[3], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t\\t"[3], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation', + 'Indentation mismatch: expected: "\\t"[1], actual: no indentation' + ]); } @Test @@ -20,7 +42,113 @@ class IndentationCheckTest extends CheckTestCase { check.character = cast " "; check.severity = SeverityLevel.INFO; assertNoMsg(check, CORRECT_SPACE_INDENT); - assertMsg(check, CORRECT_TAB_INDENT, 'Indentation mismatch: expected: " "[1], actual: no indentation'); + assertMessages(check, CORRECT_TAB_INDENT, [ + 'Indentation mismatch: expected: " "[1], actual: no indentation', + 'Indentation mismatch: expected: " "[1], actual: no indentation', + 'Indentation mismatch: expected: " "[1], actual: no indentation', + 'Indentation mismatch: expected: " "[1], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[4], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[4], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[4], actual: no indentation', + 'Indentation mismatch: expected: " "[4], actual: no indentation', + 'Indentation mismatch: expected: " "[4], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[4], actual: no indentation', + 'Indentation mismatch: expected: " "[4], actual: no indentation', + 'Indentation mismatch: expected: " "[4], actual: no indentation', + 'Indentation mismatch: expected: " "[4], actual: no indentation', + 'Indentation mismatch: expected: " "[4], actual: no indentation', + 'Indentation mismatch: expected: " "[4], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[4], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[4], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[2], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[3], actual: no indentation', + 'Indentation mismatch: expected: " "[1], actual: no indentation' + ]); } @Test @@ -28,7 +156,10 @@ class IndentationCheckTest extends CheckTestCase { var check = new IndentationCheck(); check.severity = SeverityLevel.INFO; - assertMsg(check, WRONG_CONDITIONAL, 'Indentation mismatch: expected: "\\t"[1], actual: no indentation'); + assertMessages(check, WRONG_CONDITIONAL, [ + 'Indentation mismatch: expected: "\\t"[1], actual: no indentation', + 'Indentation mismatch: expected: "\\t"[1], actual: no indentation' + ]); check.ignoreConditionals = true; assertNoMsg(check, WRONG_CONDITIONAL); assertNoMsg(check, CORRECT_TAB_INDENT); @@ -40,16 +171,41 @@ class IndentationCheckTest extends CheckTestCase { check.conditionalPolicy = FIXED_ZERO; assertNoMsg(check, WRONG_CONDITIONAL); - assertMsg(check, CORRECT_TAB_INDENT, 'Indentation mismatch: expected: no indentation, actual: "\\t\\t\\t"[3]'); + assertMessages(check, CORRECT_TAB_INDENT, [ + 'Indentation mismatch: expected: no indentation, actual: "\\t\\t"[2]', + 'Indentation mismatch: expected: no indentation, actual: "\\t\\t"[2]', + 'Indentation mismatch: expected: no indentation, actual: "\\t\\t\\t"[3]', + 'Indentation mismatch: expected: no indentation, actual: "\\t\\t\\t"[3]', + 'Indentation mismatch: expected: no indentation, actual: "\\t\\t\\t"[3]', + 'Indentation mismatch: expected: no indentation, actual: "\\t\\t\\t"[3]' + ]); check.conditionalPolicy = ALIGNED; - assertMsg(check, WRONG_CONDITIONAL, 'Indentation mismatch: expected: "\\t"[1], actual: no indentation'); + assertMessages(check, WRONG_CONDITIONAL, [ + 'Indentation mismatch: expected: "\\t"[1], actual: no indentation', + 'Indentation mismatch: expected: "\\t"[1], actual: no indentation' + ]); assertNoMsg(check, CORRECT_TAB_INDENT); check.conditionalPolicy = ALIGNED_INCREASE; - assertMsg(check, WRONG_CONDITIONAL, 'Indentation mismatch: expected: "\\t"[1], actual: no indentation'); + assertMessages(check, WRONG_CONDITIONAL, [ + 'Indentation mismatch: expected: "\\t"[1], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: "\\t"[1]', + 'Indentation mismatch: expected: "\\t"[1], actual: no indentation' + ]); assertNoMsg(check, CONDITIONAL_INCREASE); - assertMsg(check, CORRECT_TAB_INDENT, 'Indentation mismatch: expected: "\\t\\t\\t\\t\\t"[5], actual: "\\t\\t\\t\\t"[4]'); + assertMessages(check, CORRECT_TAB_INDENT, [ + 'Indentation mismatch: expected: "\\t\\t\\t"[3], actual: "\\t\\t"[2]', + 'Indentation mismatch: expected: "\\t\\t\\t\\t"[4], actual: "\\t\\t\\t"[3]', + 'Indentation mismatch: expected: "\\t\\t\\t\\t"[4], actual: "\\t\\t\\t"[3]', + 'Indentation mismatch: expected: "\\t\\t\\t\\t"[4], actual: "\\t\\t\\t"[3]', + 'Indentation mismatch: expected: "\\t\\t\\t"[3], actual: "\\t\\t"[2]', + 'Indentation mismatch: expected: "\\t\\t\\t\\t"[4], actual: "\\t\\t\\t"[3]', + 'Indentation mismatch: expected: "\\t\\t\\t\\t\\t"[5], actual: "\\t\\t\\t\\t"[4]', + 'Indentation mismatch: expected: "\\t\\t\\t\\t\\t"[5], actual: "\\t\\t\\t\\t"[4]', + 'Indentation mismatch: expected: "\\t\\t\\t\\t"[4], actual: "\\t\\t\\t"[3]', + 'Indentation mismatch: expected: "\\t\\t\\t\\t\\t"[5], actual: "\\t\\t\\t\\t"[4]' + ]); } @Test @@ -58,7 +214,10 @@ class IndentationCheckTest extends CheckTestCase { check.severity = SeverityLevel.INFO; check.ignoreComments = false; assertNoMsg(check, CORRECT_COMMENTS); - assertMsg(check, CORRECT_TAB_INDENT, 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation'); + assertMessages(check, CORRECT_TAB_INDENT, [ + 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: no indentation' + ]); } @Test @@ -69,17 +228,40 @@ class IndentationCheckTest extends CheckTestCase { assertNoMsg(check, EXACT_WRAPPED_PARAMS); assertNoMsg(check, WRAPPED_STRING); assertNoMsg(check, CORRECT_PCLOSE_WRAPPING_ISSUE_450); - assertMsg(check, NONE_WRAPPED_PARAMS, 'Indentation mismatch: expected: "\\t\\t"[2], actual: "\\t"[1]'); + assertMessages(check, NONE_WRAPPED_PARAMS, [ + 'Indentation mismatch: expected: "\\t\\t"[2], actual: "\\t"[1]', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: "\\t"[1]', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: "\\t"[1]' + ]); check.wrapPolicy = EXACT; assertNoMsg(check, WRAPPED_STRING); assertNoMsg(check, CORRECT_PCLOSE_WRAPPING_ISSUE_450); - assertMsg(check, LARGER_WRAPPED_PARAMS, 'Indentation mismatch: expected: "\\t\\t"[2], actual: "\\t\\t\\t\\t\\t\\t"[6]'); - assertMsg(check, NONE_WRAPPED_PARAMS, 'Indentation mismatch: expected: "\\t\\t"[2], actual: "\\t"[1]'); + assertMessages(check, LARGER_WRAPPED_PARAMS, [ + 'Indentation mismatch: expected: "\\t\\t"[2], actual: "\\t\\t\\t\\t\\t\\t"[6]', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: "\\t\\t\\t\\t\\t\\t"[6]', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: "\\t\\t\\t\\t\\t\\t"[6]' + ]); + assertMessages(check, NONE_WRAPPED_PARAMS, [ + 'Indentation mismatch: expected: "\\t\\t"[2], actual: "\\t"[1]', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: "\\t"[1]', + 'Indentation mismatch: expected: "\\t\\t"[2], actual: "\\t"[1]' + ]); check.wrapPolicy = NONE; assertNoMsg(check, NONE_WRAPPED_PARAMS); - assertMsg(check, LARGER_WRAPPED_PARAMS, 'Indentation mismatch: expected: "\\t"[1], actual: "\\t\\t\\t\\t\\t\\t"[6]'); - assertMsg(check, EXACT_WRAPPED_PARAMS, 'Indentation mismatch: expected: "\\t"[1], actual: "\\t\\t"[2]'); + assertMessages(check, LARGER_WRAPPED_PARAMS, [ + 'Indentation mismatch: expected: "\\t"[1], actual: "\\t\\t"[2]', + 'Indentation mismatch: expected: "\\t"[1], actual: "\\t\\t"[2]', + 'Indentation mismatch: expected: "\\t"[1], actual: "\\t\\t"[2]', + 'Indentation mismatch: expected: "\\t"[1], actual: "\\t\\t\\t\\t\\t\\t"[6]', + 'Indentation mismatch: expected: "\\t"[1], actual: "\\t\\t\\t\\t\\t\\t"[6]', + 'Indentation mismatch: expected: "\\t"[1], actual: "\\t\\t\\t\\t\\t\\t"[6]' + ]); + assertMessages(check, EXACT_WRAPPED_PARAMS, [ + 'Indentation mismatch: expected: "\\t"[1], actual: "\\t\\t"[2]', + 'Indentation mismatch: expected: "\\t"[1], actual: "\\t\\t"[2]', + 'Indentation mismatch: expected: "\\t"[1], actual: "\\t\\t"[2]' + ]); } } diff --git a/test/checkstyle/checks/whitespace/OperatorWhitespaceCheckTest.hx b/test/checkstyle/checks/whitespace/OperatorWhitespaceCheckTest.hx index 196692cb..39a8a3b8 100644 --- a/test/checkstyle/checks/whitespace/OperatorWhitespaceCheckTest.hx +++ b/test/checkstyle/checks/whitespace/OperatorWhitespaceCheckTest.hx @@ -10,12 +10,17 @@ class OperatorWhitespaceCheckTest extends CheckTestCase { static inline var MSG_PLUS_EOL:String = 'Token "+" must be at the end of the line'; + static inline var MSG_PLUS_NL:String = 'Token "+" must be on a new line'; + static inline var MSG_LT_NL:String = 'Token "<" must be on a new line'; static inline var MSG_GT_NL:String = 'Token ">" must be on a new line'; @Test @@ -28,7 +30,7 @@ class OperatorWrapCheckTest extends CheckTestCase { assertNoMsg(check, CORRECT_NL_WRAP_GT); assertNoMsg(check, TYPE_PARAM); - assertMsg(check, CORRECT_EOL_WRAP, MSG_GT_NL); + assertMessages(check, CORRECT_EOL_WRAP, [MSG_PLUS_NL, MSG_LT_NL, MSG_GT_NL]); } } diff --git a/test/checkstyle/checks/whitespace/SeparatorWhitespaceCheckTest.hx b/test/checkstyle/checks/whitespace/SeparatorWhitespaceCheckTest.hx index 72f07f42..996c32c1 100644 --- a/test/checkstyle/checks/whitespace/SeparatorWhitespaceCheckTest.hx +++ b/test/checkstyle/checks/whitespace/SeparatorWhitespaceCheckTest.hx @@ -13,8 +13,8 @@ class SeparatorWhitespaceCheckTest extends CheckTestCase { public function testIncorrectWrap() { var check = new SeparatorWrapCheck(); assertMsg(check, NL_WRAP_FUNC, MSG_COMMA_EOL); - assertMsg(check, NL_WRAP_OBJECT_DECL, MSG_COMMA_EOL); - assertMsg(check, NL_WRAP_ARRAY, MSG_COMMA_EOL); + assertMessages(check, NL_WRAP_OBJECT_DECL, [MSG_COMMA_EOL, MSG_COMMA_EOL]); + assertMessages(check, NL_WRAP_ARRAY, [MSG_COMMA_EOL, MSG_COMMA_EOL, MSG_COMMA_EOL]); } @Test @@ -42,8 +42,8 @@ class SeparatorWrapCheckTest extends CheckTestCase { assertNoMsg(check, EOL_WRAP_IMPORT); check.tokens = [",", "."]; - assertMsg(check, CORRECT_WRAP, MSG_COMMA_NL); - assertMsg(check, EOL_WRAP_ARRAY, MSG_COMMA_NL); + assertMessages(check, CORRECT_WRAP, [MSG_DOT_NL, MSG_COMMA_NL, MSG_COMMA_NL, MSG_COMMA_NL, MSG_COMMA_NL, MSG_COMMA_NL]); + assertMessages(check, EOL_WRAP_ARRAY, [MSG_COMMA_NL, MSG_COMMA_NL, MSG_COMMA_NL]); assertMsg(check, EOL_WRAP_IMPORT, MSG_DOT_NL); } }