From ef8245169ae082bcdb989abd3da14affdd61c03b Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 3 Dec 2018 16:37:10 -0800 Subject: [PATCH 1/2] Converted open rules from a c* to no-* Continues #489. --- src/chaiPreferContainsToIndexOfRule.ts | 2 +- src/chaiVagueErrorsRule.ts | 2 +- src/missingJsdocRule.ts | 2 +- src/noBackboneGetSetOutsideModelRule.ts | 4 +- src/noSuspiciousCommentRule.ts | 4 +- .../ChaiPreferContainsToIndexOfRuleTests.ts | 84 --- src/tests/ChaiVagueErrorsRuleTests.ts | 350 --------- src/tests/FunctionNameRuleTests.ts | 387 ---------- src/tests/ImportNameRuleTests.ts | 263 ------- src/tests/InformativeDocsRuleTests.ts | 193 ----- src/tests/InsecureRandomRuleTests.ts | 65 -- src/tests/MaxFuncBodyLengthRuleTests.ts | 362 --------- src/tests/MissingJsdocRuleTests.ts | 108 --- src/tests/MissingOptionalAnnotationTests.ts | 145 ---- src/tests/MochaAvoidOnlyRuleTests.ts | 167 ---- src/tests/MochaNoSideEffectCodeRuleTests.ts | 595 --------------- src/tests/MochaUnneededDoneRuleTests.ts | 219 ------ .../NoBackboneGetSetOutsideModelRuleTests.ts | 51 -- src/tests/NoBannedTermsTests.ts | 714 ------------------ src/tests/NoConstantConditionRuleTests.ts | 502 ------------ src/tests/NoControlRegexRuleTests.ts | 77 -- src/tests/NoDeleteExpressionTests.ts | 48 -- src/tests/NoDisableAutoSanitizationTests.ts | 30 - src/tests/NoDocumentDomainRuleTests.ts | 74 -- src/tests/NoDocumentWriteTests.ts | 87 --- src/tests/NoDuplicateCaseRuleTests.ts | 94 --- src/tests/NoDuplicateParameterNamesTests.ts | 98 --- src/tests/NoEmptyInterfacesRuleTests.ts | 58 -- .../NoEmptyLineAfterOpeningBraceRuleTests.ts | 41 - src/tests/NoExecScriptTests.ts | 95 --- src/tests/NoForInRuleTests.ts | 46 -- src/tests/NoHttpStringRuleTests.ts | 94 --- src/tests/NoIncrementDecrementTests.ts | 143 ---- src/tests/NoInnerHtmlRuleTests.ts | 132 ---- src/tests/NoInvalidRegexpRuleTests.ts | 47 -- src/tests/NoJqueryRawElementsRuleTests.ts | 154 ---- .../NoMissingVisibilityModifiersRuleTests.ts | 81 -- src/tests/NoMultilineStringTests.ts | 25 - src/tests/NoMultipleVarDeclRuleTests.ts | 40 - src/tests/NoRegexSpacesRuleTests.ts | 75 -- src/tests/NoStatelessClassRuleTests.ts | 165 ---- src/tests/NoSuspiciousCommentRuleTests.ts | 162 ---- src/tests/NoTypeofUndefinedRuleTests.ts | 84 --- src/tests/NoUnexternalizedStringsRuleTests.ts | 173 ----- .../NoUnsupportedBrowserCodeRuleTests.ts | 184 ----- .../jqueryDeferredMustCompleteRuleTests.ts | 420 ----------- .../test.ts.lint | 24 + .../tslint.json | 5 + tests/chai-vague-errors/test.ts.lint | 95 +++ tests/chai-vague-errors/tslint.json | 5 + tests/function-name/default/test.ts.lint | 88 +++ tests/function-name/default/tslint.json | 5 + tests/function-name/names/test.ts.lint | 17 + tests/function-name/names/tslint.json | 13 + .../test.ts.lint | 17 + .../tslint.json | 5 + .../test.ts.lint | 13 + .../tslint.json | 5 + .../test.ts.lint | 24 + .../tslint.json | 5 + tests/import-name/default/test.ts.fix | 32 + tests/import-name/default/test.ts.lint | 38 + tests/import-name/default/tslint.json | 5 + .../ignored-list-fail/test.ts.lint | 7 + .../import-name/ignored-list-fail/tslint.json | 14 + .../ignored-list-pass/test.ts.lint | 5 + .../import-name/ignored-list-pass/tslint.json | 14 + .../import-name/replacements-es6/test.ts.lint | 3 + .../import-name/replacements-es6/tslint.json | 13 + tests/import-name/replacements/test.ts.lint | 4 + tests/import-name/replacements/tslint.json | 14 + tests/informative-docs/aliases/test.ts.lint | 7 + tests/informative-docs/aliases/tslint.json | 12 + tests/informative-docs/default/test.ts.lint | 86 +++ tests/informative-docs/default/tslint.json | 5 + .../uesless-words/test.ts.lint | 7 + .../uesless-words/tslint.json | 10 + tests/insecure-random/test.ts.lint | 19 + tests/insecure-random/tslint.json | 5 + .../test.ts.lint | 227 ++++++ .../jquery-deferred-must-complete/tslint.json | 5 + .../max-func-body-length/default/test.ts.lint | 68 ++ .../max-func-body-length/default/tslint.json | 5 + .../ignore-comments/test.ts.lint | 29 + .../ignore-comments/tslint.json | 5 + .../test.ts.lint | 35 + .../tslint.json | 11 + .../max-length/test.ts.lint | 113 +++ .../max-length/tslint.json | 5 + .../max-lengths-custom/test.ts.lint | 105 +++ .../max-lengths-custom/tslint.json | 14 + .../missing-jsdoc/leading-spaces/test.ts.lint | 5 + .../missing-jsdoc/leading-spaces/tslint.json | 5 + .../missing-comment/test.ts.lint | 2 + .../missing-jsdoc/missing-comment/tslint.json | 5 + .../one-star-comment/test.ts.lint | 5 + .../one-star-comment/tslint.json | 5 + .../three-star-comment - Copy/test.ts.lint | 5 + .../three-star-comment - Copy/tslint.json | 5 + .../three-star-comment/test.ts.lint | 5 + .../three-star-comment/tslint.json | 5 + .../top-level-comment/test.ts.lint | 4 + .../top-level-comment/tslint.json | 5 + .../missing-jsdoc/trailing-chars/test.ts.lint | 5 + .../missing-jsdoc/trailing-chars/tslint.json | 5 + .../missing-optional-annotation/test.ts.lint | 63 ++ tests/missing-optional-annotation/tslint.json | 5 + tests/mocha-avoid-only/test.ts.lint | 72 ++ tests/mocha-avoid-only/tslint.json | 5 + .../complex-arrays/test.ts.lint | 4 + .../complex-arrays/tslint.json | 5 + .../complex-cast/test.ts.lint | 4 + .../complex-cast/tslint.json | 5 + .../complex-json-structures/test.ts.lint | 11 + .../complex-json-structures/tslint.json | 5 + .../configured-factory-methods/test.ts.lint | 7 + .../configured-factory-methods/tslint.json | 5 + .../context/test.ts.lint | 4 + .../context/tslint.json | 5 + .../correct-scoping/test.ts.lint | 34 + .../correct-scoping/tslint.json | 5 + .../date-creation/test.ts.lint | 5 + .../date-creation/tslint.json | 5 + .../describe-skip/test.ts.lint | 7 + .../describe-skip/tslint.json | 5 + .../describe/test.ts.lint | 21 + .../describe/tslint.json | 5 + .../empty-simple-arrays/test.ts.lint | 4 + .../empty-simple-arrays/tslint.json | 5 + .../foreach-complex/test.ts.lint | 10 + .../foreach-complex/tslint.json | 5 + .../foreach-empty/test.ts.lint | 6 + .../foreach-empty/tslint.json | 5 + .../foreach-function-call/test.ts.lint | 10 + .../foreach-function-call/tslint.json | 5 + .../test.ts.lint | 8 + .../foreach-function-side-effects/tslint.json | 5 + .../foreach-simple-object/test.ts.lint | 10 + .../foreach-simple-object/tslint.json | 5 + .../foreach-simple/test.ts.lint | 6 + .../foreach-simple/tslint.json | 5 + .../function-calls/test.ts.lint | 4 + .../function-calls/tslint.json | 5 + .../function-declaration/test.ts.lint | 6 + .../function-declaration/tslint.json | 5 + .../global-scope/test.ts.lint | 7 + .../global-scope/tslint.json | 5 + .../mocha-api/test.ts.lint | 11 + .../mocha-api/tslint.json | 5 + .../multiline-string/test.ts.lint | 7 + .../multiline-string/tslint.json | 5 + .../nested-simple-arrays/test.ts.lint | 9 + .../nested-simple-arrays/tslint.json | 5 + .../newly-declared-classes/test.ts.lint | 16 + .../newly-declared-classes/tslint.json | 5 + .../not-a-test/test.ts.lint | 1 + .../not-a-test/tslint.json | 5 + .../simple-cases/test.ts.lint | 40 + .../simple-cases/tslint.json | 5 + .../simple-cast/test.ts.lint | 3 + .../simple-cast/tslint.json | 5 + .../simple-json-structures/test.ts.lint | 10 + .../simple-json-structures/tslint.json | 5 + .../skip-only/test.ts.lint | 17 + .../skip-only/tslint.json | 5 + .../string-concatenation/test.ts.lint | 7 + .../string-concatenation/tslint.json | 5 + .../variable-aliasing/test.ts.lint | 5 + .../variable-aliasing/tslint.json | 5 + tests/mocha-unneeded-done/test.ts.lint | 114 +++ tests/mocha-unneeded-done/tslint.json | 5 + .../test.ts.lint | 16 + .../tslint.json | 5 + tests/no-banned-terms/test.ts.lint | 223 ++++++ tests/no-banned-terms/tslint.json | 5 + tests/no-constant-condition/test.ts.lint | 131 ++++ tests/no-constant-condition/tslint.json | 5 + tests/no-control-regex/test.ts.lint | 18 + tests/no-control-regex/tslint.json | 5 + tests/no-delete-expression/test.ts.lint | 19 + tests/no-delete-expression/tslint.json | 5 + .../no-disable-auto-sanitization/test.ts.lint | 7 + .../no-disable-auto-sanitization/tslint.json | 5 + tests/no-document-domain/test.ts.lint | 21 + tests/no-document-domain/tslint.json | 5 + tests/no-document-write/test.ts.lint | 52 ++ tests/no-document-write/tslint.json | 5 + tests/no-duplicate-case/test.ts.lint | 51 ++ tests/no-duplicate-case/tslint.json | 5 + .../no-duplicate-parameter-names/test.ts.lint | 44 ++ .../no-duplicate-parameter-names/tslint.json | 5 + tests/no-empty-interfaces/test.ts.lint | 20 + tests/no-empty-interfaces/tslint.json | 5 + .../test.ts.lint | 10 + .../tslint.json | 5 + tests/no-exec-script/test.ts.lint | 19 + tests/no-exec-script/tslint.json | 5 + tests/no-for-in/test.ts.lint | 6 + tests/no-for-in/tslint.json | 5 + tests/no-http-string/default/test.ts.lint | 13 + tests/no-http-string/default/tslint.json | 5 + tests/no-http-string/exclude/test.ts.lint | 5 + tests/no-http-string/exclude/tslint.json | 5 + .../allow-for-loops/test.ts.lint | 15 + .../allow-for-loops/tslint.json | 5 + .../default/test.ts.lint | 12 + .../default/tslint.json | 5 + tests/no-inner-html/default/test.ts.lint | 28 + tests/no-inner-html/default/tslint.json | 5 + .../html-lib-matcher/test.ts.lint | 8 + .../html-lib-matcher/tslint.json | 11 + tests/no-invalid-regexp/test.ts.lint | 12 + tests/no-invalid-regexp/tslint.json | 5 + tests/no-jquery-raw-elements/test.ts.lint | 36 + tests/no-jquery-raw-elements/tslint.json | 5 + .../test.ts.lint | 36 + .../tslint.json | 5 + tests/no-multiline-string/test.ts.lint | 6 + tests/no-multiline-string/tslint.json | 5 + tests/no-multiple-var-decl/test.ts.lint | 13 + tests/no-multiple-var-decl/tslint.json | 5 + tests/no-regex-spaces/test.ts.lint | 13 + tests/no-regex-spaces/tslint.json | 5 + tests/no-stateless-class/test.ts.lint | 72 ++ tests/no-stateless-class/tslint.json | 5 + .../default/test.ts.lint | 109 +++ .../no-suspicious-comment/default/tslint.json | 5 + .../exceptions/test.ts.lint | 81 ++ .../exceptions/tslint.json | 5 + tests/no-typeof-undefined/test.ts.lint | 33 + tests/no-typeof-undefined/tslint.json | 5 + .../signatures/test.ts.lint | 43 ++ .../signatures/tslint.json | 11 + 233 files changed, 3363 insertions(+), 6939 deletions(-) delete mode 100644 src/tests/ChaiPreferContainsToIndexOfRuleTests.ts delete mode 100644 src/tests/ChaiVagueErrorsRuleTests.ts delete mode 100644 src/tests/FunctionNameRuleTests.ts delete mode 100644 src/tests/ImportNameRuleTests.ts delete mode 100644 src/tests/InformativeDocsRuleTests.ts delete mode 100644 src/tests/InsecureRandomRuleTests.ts delete mode 100644 src/tests/MaxFuncBodyLengthRuleTests.ts delete mode 100644 src/tests/MissingJsdocRuleTests.ts delete mode 100644 src/tests/MissingOptionalAnnotationTests.ts delete mode 100644 src/tests/MochaAvoidOnlyRuleTests.ts delete mode 100644 src/tests/MochaNoSideEffectCodeRuleTests.ts delete mode 100644 src/tests/MochaUnneededDoneRuleTests.ts delete mode 100644 src/tests/NoBackboneGetSetOutsideModelRuleTests.ts delete mode 100644 src/tests/NoBannedTermsTests.ts delete mode 100644 src/tests/NoConstantConditionRuleTests.ts delete mode 100644 src/tests/NoControlRegexRuleTests.ts delete mode 100644 src/tests/NoDeleteExpressionTests.ts delete mode 100644 src/tests/NoDisableAutoSanitizationTests.ts delete mode 100644 src/tests/NoDocumentDomainRuleTests.ts delete mode 100644 src/tests/NoDocumentWriteTests.ts delete mode 100644 src/tests/NoDuplicateCaseRuleTests.ts delete mode 100644 src/tests/NoDuplicateParameterNamesTests.ts delete mode 100644 src/tests/NoEmptyInterfacesRuleTests.ts delete mode 100644 src/tests/NoEmptyLineAfterOpeningBraceRuleTests.ts delete mode 100644 src/tests/NoExecScriptTests.ts delete mode 100644 src/tests/NoForInRuleTests.ts delete mode 100644 src/tests/NoHttpStringRuleTests.ts delete mode 100644 src/tests/NoIncrementDecrementTests.ts delete mode 100644 src/tests/NoInnerHtmlRuleTests.ts delete mode 100644 src/tests/NoInvalidRegexpRuleTests.ts delete mode 100644 src/tests/NoJqueryRawElementsRuleTests.ts delete mode 100644 src/tests/NoMissingVisibilityModifiersRuleTests.ts delete mode 100644 src/tests/NoMultilineStringTests.ts delete mode 100644 src/tests/NoMultipleVarDeclRuleTests.ts delete mode 100644 src/tests/NoRegexSpacesRuleTests.ts delete mode 100644 src/tests/NoStatelessClassRuleTests.ts delete mode 100644 src/tests/NoSuspiciousCommentRuleTests.ts delete mode 100644 src/tests/NoTypeofUndefinedRuleTests.ts delete mode 100644 src/tests/NoUnexternalizedStringsRuleTests.ts delete mode 100644 src/tests/NoUnsupportedBrowserCodeRuleTests.ts delete mode 100644 src/tests/jqueryDeferredMustCompleteRuleTests.ts create mode 100644 tests/chai-prefer-contains-to-index-of/test.ts.lint create mode 100644 tests/chai-prefer-contains-to-index-of/tslint.json create mode 100644 tests/chai-vague-errors/test.ts.lint create mode 100644 tests/chai-vague-errors/tslint.json create mode 100644 tests/function-name/default/test.ts.lint create mode 100644 tests/function-name/default/tslint.json create mode 100644 tests/function-name/names/test.ts.lint create mode 100644 tests/function-name/names/tslint.json create mode 100644 tests/function-name/validate-private-statics-as-either/test.ts.lint create mode 100644 tests/function-name/validate-private-statics-as-either/tslint.json create mode 100644 tests/function-name/validate-private-statics-as-private/test.ts.lint create mode 100644 tests/function-name/validate-private-statics-as-private/tslint.json create mode 100644 tests/function-name/validate-private-statics-as-static/test.ts.lint create mode 100644 tests/function-name/validate-private-statics-as-static/tslint.json create mode 100644 tests/import-name/default/test.ts.fix create mode 100644 tests/import-name/default/test.ts.lint create mode 100644 tests/import-name/default/tslint.json create mode 100644 tests/import-name/ignored-list-fail/test.ts.lint create mode 100644 tests/import-name/ignored-list-fail/tslint.json create mode 100644 tests/import-name/ignored-list-pass/test.ts.lint create mode 100644 tests/import-name/ignored-list-pass/tslint.json create mode 100644 tests/import-name/replacements-es6/test.ts.lint create mode 100644 tests/import-name/replacements-es6/tslint.json create mode 100644 tests/import-name/replacements/test.ts.lint create mode 100644 tests/import-name/replacements/tslint.json create mode 100644 tests/informative-docs/aliases/test.ts.lint create mode 100644 tests/informative-docs/aliases/tslint.json create mode 100644 tests/informative-docs/default/test.ts.lint create mode 100644 tests/informative-docs/default/tslint.json create mode 100644 tests/informative-docs/uesless-words/test.ts.lint create mode 100644 tests/informative-docs/uesless-words/tslint.json create mode 100644 tests/insecure-random/test.ts.lint create mode 100644 tests/insecure-random/tslint.json create mode 100644 tests/jquery-deferred-must-complete/test.ts.lint create mode 100644 tests/jquery-deferred-must-complete/tslint.json create mode 100644 tests/max-func-body-length/default/test.ts.lint create mode 100644 tests/max-func-body-length/default/tslint.json create mode 100644 tests/max-func-body-length/ignore-comments/test.ts.lint create mode 100644 tests/max-func-body-length/ignore-comments/tslint.json create mode 100644 tests/max-func-body-length/ignore-parameters-to-function-regex/test.ts.lint create mode 100644 tests/max-func-body-length/ignore-parameters-to-function-regex/tslint.json create mode 100644 tests/max-func-body-length/max-length/test.ts.lint create mode 100644 tests/max-func-body-length/max-length/tslint.json create mode 100644 tests/max-func-body-length/max-lengths-custom/test.ts.lint create mode 100644 tests/max-func-body-length/max-lengths-custom/tslint.json create mode 100644 tests/missing-jsdoc/leading-spaces/test.ts.lint create mode 100644 tests/missing-jsdoc/leading-spaces/tslint.json create mode 100644 tests/missing-jsdoc/missing-comment/test.ts.lint create mode 100644 tests/missing-jsdoc/missing-comment/tslint.json create mode 100644 tests/missing-jsdoc/one-star-comment/test.ts.lint create mode 100644 tests/missing-jsdoc/one-star-comment/tslint.json create mode 100644 tests/missing-jsdoc/three-star-comment - Copy/test.ts.lint create mode 100644 tests/missing-jsdoc/three-star-comment - Copy/tslint.json create mode 100644 tests/missing-jsdoc/three-star-comment/test.ts.lint create mode 100644 tests/missing-jsdoc/three-star-comment/tslint.json create mode 100644 tests/missing-jsdoc/top-level-comment/test.ts.lint create mode 100644 tests/missing-jsdoc/top-level-comment/tslint.json create mode 100644 tests/missing-jsdoc/trailing-chars/test.ts.lint create mode 100644 tests/missing-jsdoc/trailing-chars/tslint.json create mode 100644 tests/missing-optional-annotation/test.ts.lint create mode 100644 tests/missing-optional-annotation/tslint.json create mode 100644 tests/mocha-avoid-only/test.ts.lint create mode 100644 tests/mocha-avoid-only/tslint.json create mode 100644 tests/mocha-no-side-effect-code/complex-arrays/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/complex-arrays/tslint.json create mode 100644 tests/mocha-no-side-effect-code/complex-cast/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/complex-cast/tslint.json create mode 100644 tests/mocha-no-side-effect-code/complex-json-structures/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/complex-json-structures/tslint.json create mode 100644 tests/mocha-no-side-effect-code/configured-factory-methods/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/configured-factory-methods/tslint.json create mode 100644 tests/mocha-no-side-effect-code/context/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/context/tslint.json create mode 100644 tests/mocha-no-side-effect-code/correct-scoping/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/correct-scoping/tslint.json create mode 100644 tests/mocha-no-side-effect-code/date-creation/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/date-creation/tslint.json create mode 100644 tests/mocha-no-side-effect-code/describe-skip/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/describe-skip/tslint.json create mode 100644 tests/mocha-no-side-effect-code/describe/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/describe/tslint.json create mode 100644 tests/mocha-no-side-effect-code/empty-simple-arrays/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/empty-simple-arrays/tslint.json create mode 100644 tests/mocha-no-side-effect-code/foreach-complex/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/foreach-complex/tslint.json create mode 100644 tests/mocha-no-side-effect-code/foreach-empty/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/foreach-empty/tslint.json create mode 100644 tests/mocha-no-side-effect-code/foreach-function-call/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/foreach-function-call/tslint.json create mode 100644 tests/mocha-no-side-effect-code/foreach-function-side-effects/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/foreach-function-side-effects/tslint.json create mode 100644 tests/mocha-no-side-effect-code/foreach-simple-object/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/foreach-simple-object/tslint.json create mode 100644 tests/mocha-no-side-effect-code/foreach-simple/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/foreach-simple/tslint.json create mode 100644 tests/mocha-no-side-effect-code/function-calls/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/function-calls/tslint.json create mode 100644 tests/mocha-no-side-effect-code/function-declaration/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/function-declaration/tslint.json create mode 100644 tests/mocha-no-side-effect-code/global-scope/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/global-scope/tslint.json create mode 100644 tests/mocha-no-side-effect-code/mocha-api/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/mocha-api/tslint.json create mode 100644 tests/mocha-no-side-effect-code/multiline-string/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/multiline-string/tslint.json create mode 100644 tests/mocha-no-side-effect-code/nested-simple-arrays/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/nested-simple-arrays/tslint.json create mode 100644 tests/mocha-no-side-effect-code/newly-declared-classes/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/newly-declared-classes/tslint.json create mode 100644 tests/mocha-no-side-effect-code/not-a-test/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/not-a-test/tslint.json create mode 100644 tests/mocha-no-side-effect-code/simple-cases/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/simple-cases/tslint.json create mode 100644 tests/mocha-no-side-effect-code/simple-cast/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/simple-cast/tslint.json create mode 100644 tests/mocha-no-side-effect-code/simple-json-structures/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/simple-json-structures/tslint.json create mode 100644 tests/mocha-no-side-effect-code/skip-only/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/skip-only/tslint.json create mode 100644 tests/mocha-no-side-effect-code/string-concatenation/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/string-concatenation/tslint.json create mode 100644 tests/mocha-no-side-effect-code/variable-aliasing/test.ts.lint create mode 100644 tests/mocha-no-side-effect-code/variable-aliasing/tslint.json create mode 100644 tests/mocha-unneeded-done/test.ts.lint create mode 100644 tests/mocha-unneeded-done/tslint.json create mode 100644 tests/no-backbone-get-set-outside-model/test.ts.lint create mode 100644 tests/no-backbone-get-set-outside-model/tslint.json create mode 100644 tests/no-banned-terms/test.ts.lint create mode 100644 tests/no-banned-terms/tslint.json create mode 100644 tests/no-constant-condition/test.ts.lint create mode 100644 tests/no-constant-condition/tslint.json create mode 100644 tests/no-control-regex/test.ts.lint create mode 100644 tests/no-control-regex/tslint.json create mode 100644 tests/no-delete-expression/test.ts.lint create mode 100644 tests/no-delete-expression/tslint.json create mode 100644 tests/no-disable-auto-sanitization/test.ts.lint create mode 100644 tests/no-disable-auto-sanitization/tslint.json create mode 100644 tests/no-document-domain/test.ts.lint create mode 100644 tests/no-document-domain/tslint.json create mode 100644 tests/no-document-write/test.ts.lint create mode 100644 tests/no-document-write/tslint.json create mode 100644 tests/no-duplicate-case/test.ts.lint create mode 100644 tests/no-duplicate-case/tslint.json create mode 100644 tests/no-duplicate-parameter-names/test.ts.lint create mode 100644 tests/no-duplicate-parameter-names/tslint.json create mode 100644 tests/no-empty-interfaces/test.ts.lint create mode 100644 tests/no-empty-interfaces/tslint.json create mode 100644 tests/no-empty-line-after-opening-brace/test.ts.lint create mode 100644 tests/no-empty-line-after-opening-brace/tslint.json create mode 100644 tests/no-exec-script/test.ts.lint create mode 100644 tests/no-exec-script/tslint.json create mode 100644 tests/no-for-in/test.ts.lint create mode 100644 tests/no-for-in/tslint.json create mode 100644 tests/no-http-string/default/test.ts.lint create mode 100644 tests/no-http-string/default/tslint.json create mode 100644 tests/no-http-string/exclude/test.ts.lint create mode 100644 tests/no-http-string/exclude/tslint.json create mode 100644 tests/no-increment-decrement/allow-for-loops/test.ts.lint create mode 100644 tests/no-increment-decrement/allow-for-loops/tslint.json create mode 100644 tests/no-increment-decrement/default/test.ts.lint create mode 100644 tests/no-increment-decrement/default/tslint.json create mode 100644 tests/no-inner-html/default/test.ts.lint create mode 100644 tests/no-inner-html/default/tslint.json create mode 100644 tests/no-inner-html/html-lib-matcher/test.ts.lint create mode 100644 tests/no-inner-html/html-lib-matcher/tslint.json create mode 100644 tests/no-invalid-regexp/test.ts.lint create mode 100644 tests/no-invalid-regexp/tslint.json create mode 100644 tests/no-jquery-raw-elements/test.ts.lint create mode 100644 tests/no-jquery-raw-elements/tslint.json create mode 100644 tests/no-missing-visibility-modifiers/test.ts.lint create mode 100644 tests/no-missing-visibility-modifiers/tslint.json create mode 100644 tests/no-multiline-string/test.ts.lint create mode 100644 tests/no-multiline-string/tslint.json create mode 100644 tests/no-multiple-var-decl/test.ts.lint create mode 100644 tests/no-multiple-var-decl/tslint.json create mode 100644 tests/no-regex-spaces/test.ts.lint create mode 100644 tests/no-regex-spaces/tslint.json create mode 100644 tests/no-stateless-class/test.ts.lint create mode 100644 tests/no-stateless-class/tslint.json create mode 100644 tests/no-suspicious-comment/default/test.ts.lint create mode 100644 tests/no-suspicious-comment/default/tslint.json create mode 100644 tests/no-suspicious-comment/exceptions/test.ts.lint create mode 100644 tests/no-suspicious-comment/exceptions/tslint.json create mode 100644 tests/no-typeof-undefined/test.ts.lint create mode 100644 tests/no-typeof-undefined/tslint.json create mode 100644 tests/no-unexternalized-strings/signatures/test.ts.lint create mode 100644 tests/no-unexternalized-strings/signatures/tslint.json diff --git a/src/chaiPreferContainsToIndexOfRule.ts b/src/chaiPreferContainsToIndexOfRule.ts index 552b2c85c..655bcbecd 100644 --- a/src/chaiPreferContainsToIndexOfRule.ts +++ b/src/chaiPreferContainsToIndexOfRule.ts @@ -5,7 +5,7 @@ import { AstUtils } from './utils/AstUtils'; import { ChaiUtils } from './utils/ChaiUtils'; import { ExtendedMetadata } from './utils/ExtendedMetadata'; -const FAILURE_STRING: string = 'Found chai call with indexOf that can be converted to .contain assertion: '; +const FAILURE_STRING: string = 'Found chai call with indexOf that can be converted to .contain assertion.'; export class Rule extends Lint.Rules.AbstractRule { public static metadata: ExtendedMetadata = { diff --git a/src/chaiVagueErrorsRule.ts b/src/chaiVagueErrorsRule.ts index 4a64175c6..0bcf885a5 100644 --- a/src/chaiVagueErrorsRule.ts +++ b/src/chaiVagueErrorsRule.ts @@ -9,7 +9,7 @@ const FAILURE_STRING: string = BASE_ERROR + 'Please add an explicit failure mess const FAILURE_STRING_COMPARE_TRUE: string = BASE_ERROR + 'Move the strict equality comparison from the expect call into the assertion value'; const FAILURE_STRING_COMPARE_FALSE: string = - BASE_ERROR + 'Move the strict inequality comparison from the expect call into the assertion value. '; + BASE_ERROR + 'Move the strict inequality comparison from the expect call into the assertion value'; export class Rule extends Lint.Rules.AbstractRule { public static metadata: ExtendedMetadata = { diff --git a/src/missingJsdocRule.ts b/src/missingJsdocRule.ts index a47e523ed..f8cfc16e9 100644 --- a/src/missingJsdocRule.ts +++ b/src/missingJsdocRule.ts @@ -35,7 +35,7 @@ export class Rule extends Lint.Rules.AbstractRule { class MissingJSDocWalker extends Lint.RuleWalker { protected visitSourceFile(node: ts.SourceFile): void { if (!/^\/\*\*\s*$/gm.test(node.getFullText())) { - this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING); + this.addFailureAt(0, 0, Rule.FAILURE_STRING); } // do not continue walking } diff --git a/src/noBackboneGetSetOutsideModelRule.ts b/src/noBackboneGetSetOutsideModelRule.ts index b80dbea3f..194031f08 100644 --- a/src/noBackboneGetSetOutsideModelRule.ts +++ b/src/noBackboneGetSetOutsideModelRule.ts @@ -34,11 +34,11 @@ class NoBackboneGetSetOutsideModelRuleWalker extends Lint.RuleWalker { const functionName: string = AstUtils.getFunctionName(node); if (functionName === 'get' && node.arguments.length === 1 && node.arguments[0].kind === ts.SyntaxKind.StringLiteral) { const msg: string = Rule.GET_FAILURE_STRING + node.getText(); - this.addFailureAt(node.getStart(), node.getEnd(), msg); + this.addFailureAt(node.getStart(), node.getWidth(), msg); } if (functionName === 'set' && node.arguments.length === 2 && node.arguments[0].kind === ts.SyntaxKind.StringLiteral) { const msg: string = Rule.SET_FAILURE_STRING + node.getText(); - this.addFailureAt(node.getStart(), node.getEnd(), msg); + this.addFailureAt(node.getStart(), node.getWidth(), msg); } } super.visitCallExpression(node); diff --git a/src/noSuspiciousCommentRule.ts b/src/noSuspiciousCommentRule.ts index f4085a9e4..13d3c5324 100644 --- a/src/noSuspiciousCommentRule.ts +++ b/src/noSuspiciousCommentRule.ts @@ -6,7 +6,7 @@ import { ExtendedMetadata } from './utils/ExtendedMetadata'; const FAILURE_STRING: string = 'Suspicious comment found: '; const SUSPICIOUS_WORDS = ['BUG', 'HACK', 'FIXME', 'LATER', 'LATER2', 'TODO']; -const FAILURE_STRING_OPTION: string = '\nTo disable this warning, the comment should include one of the following regex: '; +const FAILURE_STRING_OPTION: string = 'To disable this warning, the comment should include one of the following regex: '; export class Rule extends Lint.Rules.AbstractRule { public static metadata: ExtendedMetadata = { @@ -76,7 +76,7 @@ class NoSuspiciousCommentRuleWalker extends Lint.RuleWalker { private foundSuspiciousComment(startPosition: number, commentText: string, suspiciousWord: string) { let errorMessage: string = FAILURE_STRING + suspiciousWord; if (this.exceptionRegex.length > 0) { - errorMessage += '.' + this.getFailureMessageWithExceptionRegexOption(); + errorMessage += '. ' + this.getFailureMessageWithExceptionRegexOption(); } this.addFailureAt(startPosition, commentText.length, errorMessage); } diff --git a/src/tests/ChaiPreferContainsToIndexOfRuleTests.ts b/src/tests/ChaiPreferContainsToIndexOfRuleTests.ts deleted file mode 100644 index b5d11301b..000000000 --- a/src/tests/ChaiPreferContainsToIndexOfRuleTests.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('chaiPreferContainsToIndexOfRule', (): void => { - const ruleName: string = 'chai-prefer-contains-to-index-of'; - - it('should pass on contain', (): void => { - const script: string = ` - expect(targetUrl).to.contain(twitterAuthUrl, '...'); - chai.expect(targetUrl).to.contain(twitterAuthUrl, '...'); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on not contain', (): void => { - const script: string = ` - expect(targetUrl).to.not.contain(twitterAuthUrl,'...'); - chai.expect(targetUrl).to.not.contain(twitterAuthUrl,'...'); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on indexOf equal to -1 in call expression', (): void => { - const script: string = ` - expect(targetUrl.indexOf(twitterAuthUrl)).to.equal(-1,'...'); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found chai call with indexOf that can be converted to .contain assertion: ', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-prefer-contains-to-index-of', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on indexOf equal to -1 in property expression', (): void => { - const script: string = ` - chai.expect(targetUrl.indexOf(twitterAuthUrl)).to.equal(-1,'...'); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found chai call with indexOf that can be converted to .contain assertion: ', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-prefer-contains-to-index-of', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on indexOf not equal to -1 in call expression', (): void => { - const script: string = ` - expect(targetUrl.indexOf(twitterAuthUrl)).not.to.equal(-1,'...'); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found chai call with indexOf that can be converted to .contain assertion: ', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-prefer-contains-to-index-of', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on indexOf not equal to -1 in property expression', (): void => { - const script: string = ` - chai.expect(targetUrl.indexOf(twitterAuthUrl)).not.to.equal(-1,'...'); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found chai call with indexOf that can be converted to .contain assertion: ', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-prefer-contains-to-index-of', - startPosition: { character: 13, line: 2 } - } - ]); - }); -}); diff --git a/src/tests/ChaiVagueErrorsRuleTests.ts b/src/tests/ChaiVagueErrorsRuleTests.ts deleted file mode 100644 index ed2a2c036..000000000 --- a/src/tests/ChaiVagueErrorsRuleTests.ts +++ /dev/null @@ -1,350 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('chaiVagueErrorsRule', (): void => { - const ruleName: string = 'chai-vague-errors'; - - it('should pass on xxx', (): void => { - const script: string = ` - expect(something).to.equal(true, 'message'); - expect(something).to.be.equal(false, 'message'); - expect(something).to.not.equal(null, 'message'); - expect(something).to.not.be.equal(undefined, 'message'); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on xxx fluent', (): void => { - const script: string = ` - expect(something, 'message').to.be.true; - expect(something, 'message').to.be.false; - expect(something, 'message').to.not.be.null; - expect(something, 'message').to.not.be.undefined; - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on ok', (): void => { - const script: string = ` - expect(something).to.ok; - chai.expect(something).to.ok; - expect(something).to.be.ok; - chai.expect(something).to.not.be.ok; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 3 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 4 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 5 } - } - ]); - }); - - it('should fail on true', (): void => { - const script: string = ` - expect(something).to.true; - chai.expect(something).to.be.true; - expect(something).to.not.be.true; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 3 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 4 } - } - ]); - }); - - it('should fail on false', (): void => { - const script: string = ` - expect(something).to.false; - expect(something).to.be.false; - expect(something).to.not.be.false; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 3 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 4 } - } - ]); - }); - - it('should fail on null', (): void => { - const script: string = ` - expect(something).to.null; - expect(something).to.be.null; - expect(something).to.not.be.null; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 3 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 4 } - } - ]); - }); - - it('should fail on undefined', (): void => { - const script: string = ` - expect(something).to.undefined; - expect(something).to.be.undefined; - expect(something).to.not.be.undefined; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 3 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 4 } - } - ]); - }); - - it('should fail on equal', (): void => { - const script: string = ` - expect(something).to.equal(true); - expect(something).to.equals(true); - expect(something).to.be.equal(true); - expect(something).to.be.equals(true); - expect(something).to.not.be.equal(false); - expect(something).to.deep.equal(null); - expect(something).to.not.equal(undefined); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 3 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 4 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 5 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 6 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 7 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 8 } - } - ]); - }); - - it('should fail on eql', (): void => { - const script: string = ` - expect(something).to.eql(true); - expect(something).to.be.eql(true); - chai.expect(something).to.not.be.eql(false); - expect(something).to.deep.eql(null); - chai.expect(something).to.not.eql(undefined); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 3 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 4 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 5 } - }, - { - failure: 'Found chai call with vague failure message. Please add an explicit failure message', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 6 } - } - ]); - }); - - it('should fail on strict equality in expectation', (): void => { - const script: string = ` - expect(something === undefined).to.equal(true, 'something should not have been set'); - chai.expect(something === undefined).to.equal(true, 'something should not have been set'); - expect(something !== undefined).to.equal(false, 'something should not have been set'); - chai.expect(something !== undefined).to.equal(false, 'something should not have been set'); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'Found chai call with vague failure message. ' + - 'Move the strict equality comparison from the expect call into the assertion value', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 2 } - }, - { - failure: - 'Found chai call with vague failure message. ' + - 'Move the strict equality comparison from the expect call into the assertion value', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 3 } - }, - { - failure: - 'Found chai call with vague failure message. ' + - 'Move the strict inequality comparison from the expect call into the assertion value. ', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 4 } - }, - { - failure: - 'Found chai call with vague failure message. ' + - 'Move the strict inequality comparison from the expect call into the assertion value. ', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 5 } - } - ]); - }); - - it('should fail on strictly in-equality in expectation', (): void => { - const script: string = ` - expect(something !== undefined).to.equal(true, 'something should not have been set'); - expect(something === undefined).to.equal(false, 'something should not have been set'); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'Found chai call with vague failure message. ' + - 'Move the strict inequality comparison from the expect call into the assertion value. ', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 2 } - }, - { - failure: - 'Found chai call with vague failure message. ' + - 'Move the strict equality comparison from the expect call into the assertion value', - name: Utils.absolutePath('file.ts'), - ruleName: 'chai-vague-errors', - startPosition: { character: 13, line: 3 } - } - ]); - }); -}); diff --git a/src/tests/FunctionNameRuleTests.ts b/src/tests/FunctionNameRuleTests.ts deleted file mode 100644 index 6a4522919..000000000 --- a/src/tests/FunctionNameRuleTests.ts +++ /dev/null @@ -1,387 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('functionNameRule', (): void => { - const ruleName: string = 'function-name'; - - it('should pass on correctly named functions', (): void => { - const script: string = ` - function foo() {} - class MyClass { - foo() {} - foo1() {} - myFoo() {} - myFoo1() {} - - private bar() {} - private bar1() {} - private myBar() {} - private myBar1() {} - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on functions as symbol properties', (): void => { - const script: string = ` - class MyClass { - static [Symbol.staticDefault](): any {} - public static [Symbol.staticPublic](): any {} - protected static [Symbol.staticProtected](): any {} - private static [Symbol.staticPrivate](): any {} - - static [Symbol.methodDefault](): any {} - public static [Symbol.methodPublic](): any {} - protected static [Symbol.methodProtected](): any {} - private static [Symbol.methodPrivate](): any {} - } - - const objLiteral = { - [Symbol.toStringTag](): string => "hello world" - } - `; - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on correctly public static methods', (): void => { - const script: string = ` - class MyClass { - static FOO() {} - static FOO_BAR() {} - static FOO_2() {} - static FO__O() {} - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on correctly private static methods', (): void => { - const script: string = ` - class MyClass { - private static bar() {} - private static bar1() {} - private static myBar() {} - private static myBar1() {} - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on correctly protected static methods', (): void => { - const script: string = ` - class MyClass { - protected static bar() {} - protected static bar1() {} - protected static myBar() {} - protected static myBar1() {} - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on correctly private static methods as static with option', (): void => { - const script: string = ` - class MyClass { - private static BAR() {} - private static BAR_1() {} - private static MY_BAR() {} - private static MY_BAR_1() {} - } - `; - - TestHelper.assertNoViolationWithOptions(ruleName, ['true', 'validate-private-statics-as-static'], script); - }); - - it('should pass on correctly protected static methods as static with option', (): void => { - const script: string = ` - class MyClass { - protected static BAR() {} - protected static BAR_1() {} - protected static MY_BAR() {} - protected static MY_BAR_1() {} - } - `; - - TestHelper.assertNoViolationWithOptions(ruleName, ['true', 'validate-private-statics-as-static'], script); - }); - - it('should pass on correctly private static methods as private with option', (): void => { - const script: string = ` - class MyClass { - private static bar() {} - private static bar1() {} - private static myBar() {} - private static myBar1() {} - } - `; - - TestHelper.assertNoViolationWithOptions(ruleName, ['true', 'validate-private-statics-as-private'], script); - }); - - it('should pass on correctly protected static methods as private with option', (): void => { - const script: string = ` - class MyClass { - protected static bar() {} - protected static bar1() {} - protected static myBar() {} - protected static myBar1() {} - } - `; - - TestHelper.assertNoViolationWithOptions(ruleName, ['true', 'validate-private-statics-as-private'], script); - }); - - it('should pass on correctly private or protected static methods as either with option', (): void => { - const script: string = ` - class MyClass { - private static bar() {} - private static bar1() {} - private static BAR() {} - private static BAR_1() {} - protected static myBar() {} - protected static myBar1() {} - protected static MY_BAR() {} - protected static MY_BAR_1() {} - } - `; - - TestHelper.assertNoViolationWithOptions(ruleName, ['true', 'validate-private-statics-as-either'], script); - }); - - it('should fail on incorrect public methods', (): void => { - const script: string = ` - class MyClass { - Foo() {} - _foo() {} - FOO() {} - _FOO() {} - _foo() {} - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Method name does not match /^[a-z][\\w\\d]+$/: Foo', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 17, line: 3 } - }, - { - failure: 'Method name does not match /^[a-z][\\w\\d]+$/: _foo', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 17, line: 4 } - }, - { - failure: 'Method name does not match /^[a-z][\\w\\d]+$/: FOO', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 17, line: 5 } - }, - { - failure: 'Method name does not match /^[a-z][\\w\\d]+$/: _FOO', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 17, line: 6 } - }, - { - failure: 'Method name does not match /^[a-z][\\w\\d]+$/: _foo', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 17, line: 7 } - } - ]); - }); - - it('should fail on incorrect private methods', (): void => { - const script: string = ` - class MyClass { - private Foo() {} - private _foo() {} - private FOO() {} - private _FOO() {} - private _foo() {} - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Private method name does not match /^[a-z][\\w\\d]+$/: Foo', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 25, line: 3 } - }, - { - failure: 'Private method name does not match /^[a-z][\\w\\d]+$/: _foo', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 25, line: 4 } - }, - { - failure: 'Private method name does not match /^[a-z][\\w\\d]+$/: FOO', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 25, line: 5 } - }, - { - failure: 'Private method name does not match /^[a-z][\\w\\d]+$/: _FOO', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 25, line: 6 } - }, - { - failure: 'Private method name does not match /^[a-z][\\w\\d]+$/: _foo', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 25, line: 7 } - } - ]); - }); - - it('should fail on incorrect protected methods', (): void => { - const script: string = ` - class MyClass { - protected Foo() {} - protected _foo() {} - protected FOO() {} - protected _FOO() {} - protected _foo() {} - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Protected method name does not match /^[a-z][\\w\\d]+$/: Foo', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 27, line: 3 } - }, - { - failure: 'Protected method name does not match /^[a-z][\\w\\d]+$/: _foo', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 27, line: 4 } - }, - { - failure: 'Protected method name does not match /^[a-z][\\w\\d]+$/: FOO', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 27, line: 5 } - }, - { - failure: 'Protected method name does not match /^[a-z][\\w\\d]+$/: _FOO', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 27, line: 6 } - }, - { - failure: 'Protected method name does not match /^[a-z][\\w\\d]+$/: _foo', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 27, line: 7 } - } - ]); - }); - - it('should fail on incorrect static methods', (): void => { - const script: string = ` - class MyClass { - static Foo() {} - static _foo() {} - static _foo2() {} - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Static method name does not match /^[A-Z_\\d]+$/: Foo', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 24, line: 3 } - }, - { - failure: 'Static method name does not match /^[A-Z_\\d]+$/: _foo', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 24, line: 4 } - }, - { - failure: 'Static method name does not match /^[A-Z_\\d]+$/: _foo2', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 24, line: 5 } - } - ]); - }); - - describe('reading options', (): void => { - let options: [boolean, object]; - - beforeEach( - (): void => { - options = [ - true, - { - 'method-regex': '^myMethod$', - 'private-method-regex': '^myPrivateMethod$', - 'static-method-regex': '^myStaticMethod$', - 'function-regex': '^myFunction$' - } - ]; - } - ); - - it('should allow passing names', (): void => { - const script: string = ` - function myFunction() {} - class MyClass { - myMethod() {} - private myPrivateMethod() {} - static myStaticMethod() {} - }`; - - TestHelper.assertViolationsWithOptions(ruleName, options, script, []); - }); - - it('should ban non-passing names', (): void => { - const script: string = ` - function notMyFunction() {} - class MyClass { - notMyMethod() {} - private notMyPrivateMethod() {} - static notMyStaticMethod() {} - }`; - - TestHelper.assertViolationsWithOptions(ruleName, options, script, [ - { - failure: 'Function name does not match /^myFunction$/: notMyFunction', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 22, line: 2 } - }, - { - failure: 'Method name does not match /^myMethod$/: notMyMethod', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 17, line: 4 } - }, - { - failure: 'Private method name does not match /^myPrivateMethod$/: notMyPrivateMethod', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 25, line: 5 } - }, - { - failure: 'Static method name does not match /^myStaticMethod$/: notMyStaticMethod', - name: Utils.absolutePath('file.ts'), - ruleName: 'function-name', - startPosition: { character: 24, line: 6 } - } - ]); - }); - }); -}); diff --git a/src/tests/ImportNameRuleTests.ts b/src/tests/ImportNameRuleTests.ts deleted file mode 100644 index d9a051500..000000000 --- a/src/tests/ImportNameRuleTests.ts +++ /dev/null @@ -1,263 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('importNameRule', (): void => { - const ruleName: string = 'import-name'; - - it('should pass on matching names of external module', (): void => { - const script: string = ` - import App = require('App'); - import App = require('x/y/z/App'); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on matching names of ES6 import', (): void => { - const script: string = ` - import App from 'App'; - import App from 'x/y/z/App'; - import graphqlTag from 'graphql-tag' - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on matching names of simple import', (): void => { - const script: string = ` - import DependencyManager = DM.DependencyManager; - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on misnamed external module', (): void => { - const script: string = ` - import MyCoolApp = require('App'); - import MyCoolApp2 = require('x/y/z/App'); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Misnamed import. Import should be named 'App' but found 'MyCoolApp'", - name: Utils.absolutePath('file.ts'), - ruleName: 'import-name', - startPosition: { character: 13, line: 2 }, - fix: { - innerStart: 20, - innerLength: 9, - innerText: 'App' - } - }, - { - failure: "Misnamed import. Import should be named 'App' but found 'MyCoolApp2'", - name: Utils.absolutePath('file.ts'), - ruleName: 'import-name', - startPosition: { character: 13, line: 3 }, - fix: { - innerStart: 67, - innerLength: 10, - innerText: 'App' - } - } - ]); - }); - - it('should fail on misnamed import', (): void => { - const script: string = ` - import MyCoolApp from 'App'; - import MyCoolApp2 from 'x/y/z/App'; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Misnamed import. Import should be named 'App' but found 'MyCoolApp'", - name: Utils.absolutePath('file.ts'), - ruleName: 'import-name', - startPosition: { character: 13, line: 2 }, - fix: { - innerStart: 20, - innerLength: 9, - innerText: 'App' - } - }, - { - failure: "Misnamed import. Import should be named 'App' but found 'MyCoolApp2'", - name: Utils.absolutePath('file.ts'), - ruleName: 'import-name', - startPosition: { character: 13, line: 3 }, - fix: { - innerStart: 61, - innerLength: 10, - innerText: 'App' - } - } - ]); - }); - - it('should fail on misnamed rename', (): void => { - const script: string = ` - import Service = DM.DependencyManager; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Misnamed import. Import should be named 'DependencyManager' but found 'Service'", - name: Utils.absolutePath('file.ts'), - ruleName: 'import-name', - startPosition: { character: 13, line: 2 }, - fix: { - innerStart: 20, - innerLength: 7, - innerText: 'DependencyManager' - } - } - ]); - }); - - it('should fail import with punctuation and underscore', (): void => { - const script: string = ` - import UserSettings from "./user-settings.detail_view"; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Misnamed import. Import should be named 'userSettingsDetailView' but found 'UserSettings'", - name: Utils.absolutePath('file.ts'), - ruleName: 'import-name', - startPosition: { character: 13, line: 2 }, - fix: { - innerStart: 20, - innerLength: 12, - innerText: 'userSettingsDetailView' - } - } - ]); - }); - - it('should pass on differing names when rule is configured with replacements', (): void => { - const script: string = ` - import Backbone = require('backbone'); - import React = require('react'); - import isPlainObject from 'is-plain-object'; - import baseChartOptions = require('common/component/chart/options/BaseChartOptions'); - `; - - const options = [ - true, - { - backbone: 'Backbone', - react: 'React', - 'is-plain-object': 'isPlainObject', - BaseChartOptions: 'baseChartOptions' - } - ]; - TestHelper.assertViolationsWithOptions(ruleName, options, script, []); - }); - - it('should pass on differing names when rule is configured with replacements for ES6', (): void => { - const script: string = ` - import pkg from 'fs/package-name', - import abc from 'abc-tag', - import pqr from 'my-module' - `; - const options = [ - true, - { - 'fs/package-name': 'pkg', - 'abc-tag': 'abc', - myModule: 'pqr' - } - ]; - TestHelper.assertViolationsWithOptions(ruleName, options, script, []); - }); - - it('should pass on ignoring modules from ignoredList(string[] from third argument)', (): void => { - const script: string = ` - import pkg from 'fs/package-name', - import abc from 'abc-tag', - import pqr from 'my-module' - import what from 'what-module' - import Up from 'up-module' - `; - const options = [ - true, - { - 'fs/package-name': 'pkg', - 'abc-tag': 'abc', - myModule: 'pqr' - }, - ['what-module', 'up-module'] - ]; - TestHelper.assertViolationsWithOptions(ruleName, options, script, []); - }); - - it('should pass on ignoring third argument value other than string[]', (): void => { - const script: string = ` - import pkg from 'fs/package-name', - import abc from 'abc-tag', - import pqr from 'my-module' - import what from 'what-module' - import Up from 'up-module' - `; - const options = [ - true, - { - 'fs/package-name': 'pkg', - 'abc-tag': 'abc', - myModule: 'pqr' - }, - [123, { whatever: 'object' }] - ]; - TestHelper.assertViolationsWithOptions(ruleName, options, script, [ - { - failure: "Misnamed import. Import should be named 'whatModule' but found 'what'", - name: Utils.absolutePath('file.ts'), - ruleName: 'import-name', - startPosition: { character: 9, line: 5 }, - fix: { - innerStart: 130, - innerLength: 4, - innerText: 'whatModule' - } - }, - { - failure: "Misnamed import. Import should be named 'upModule' but found 'Up'", - name: Utils.absolutePath('file.ts'), - ruleName: 'import-name', - startPosition: { character: 9, line: 6 }, - fix: { - innerStart: 169, - innerLength: 2, - innerText: 'upModule' - } - } - ]); - }); - - it('should pass on index path modules', () => { - const script = ` - import AnyName = require('.'); - import AnyName = require('..'); - import AnyName = require('./'); - import AnyName = require('../'); - import AnyName = require('../path/./..'); - import AnyName = require('../../..'); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on index path ES6 modules', () => { - const script = ` - import AnyName from '.'; - import AnyName from '..'; - import AnyName from './'; - import AnyName from '../'; - import AnyName from '../path/./..'; - import AnyName from '../../..'; - `; - - TestHelper.assertViolations(ruleName, script, []); - }); -}); diff --git a/src/tests/InformativeDocsRuleTests.ts b/src/tests/InformativeDocsRuleTests.ts deleted file mode 100644 index 17b7ce7c0..000000000 --- a/src/tests/InformativeDocsRuleTests.ts +++ /dev/null @@ -1,193 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('informativeDocsRule', (): void => { - it('should pass on well-described functions', (): void => { - const script: string = ` - /** - * Does X Y Z work. - */ - function foo() {} - - /** - * Transforms the processed data. - */ - function bar() {} - - /** - * Transforms the processed baz data. - */ - function bazProcessor() {} - `; - - TestHelper.assertViolations('informative-docs', script, []); - }); - - it('should pass on a non-commented function', (): void => { - const script: string = ` - function foo() {} - `; - - TestHelper.assertViolations('informative-docs', script, []); - }); - - it('should fail on uninformative docs comments of all kinds', (): void => { - const script: string = ` - /** - * Foo class - */ - class FooClass { - /** - * the foo method declaration - */ - fooMethodDeclaration() {} - - /** - * The foo property declaration. - */ - public fooPropertyDeclaration; - } - - /** - * the Foo enum. - */ - enum FooEnum {} - - /** - * The foo function - */ - function fooFunction() {} - - const _ = { - /** - * The foo get accessor. - */ - get fooGetAccessor() { - return 0; - } - }; - - /** - * The foo interface. - */ - interface IFooInterface {} - - /** - * The foo module. - */ - module FooModule {} - - /** - * The foo type. - */ - type fooType = {}; - `; - - TestHelper.assertViolations('informative-docs', script, [ - { - failure: "This comment is roughly the same as the object's name. Either be more informative or don't include a comment.", - name: Utils.absolutePath('file.ts'), - ruleName: 'informative-docs', - startPosition: { character: 13, line: 5 } - }, - { - failure: "This comment is roughly the same as the object's name. Either be more informative or don't include a comment.", - name: Utils.absolutePath('file.ts'), - ruleName: 'informative-docs', - startPosition: { character: 17, line: 9 } - }, - { - failure: "This comment is roughly the same as the object's name. Either be more informative or don't include a comment.", - name: Utils.absolutePath('file.ts'), - ruleName: 'informative-docs', - startPosition: { character: 17, line: 14 } - }, - { - failure: "This comment is roughly the same as the object's name. Either be more informative or don't include a comment.", - name: Utils.absolutePath('file.ts'), - ruleName: 'informative-docs', - startPosition: { character: 13, line: 20 } - }, - { - failure: "This comment is roughly the same as the object's name. Either be more informative or don't include a comment.", - name: Utils.absolutePath('file.ts'), - ruleName: 'informative-docs', - startPosition: { character: 13, line: 25 } - }, - { - failure: "This comment is roughly the same as the object's name. Either be more informative or don't include a comment.", - name: Utils.absolutePath('file.ts'), - ruleName: 'informative-docs', - startPosition: { character: 17, line: 31 } - }, - { - failure: "This comment is roughly the same as the object's name. Either be more informative or don't include a comment.", - name: Utils.absolutePath('file.ts'), - ruleName: 'informative-docs', - startPosition: { character: 13, line: 39 } - }, - { - failure: "This comment is roughly the same as the object's name. Either be more informative or don't include a comment.", - name: Utils.absolutePath('file.ts'), - ruleName: 'informative-docs', - startPosition: { character: 13, line: 44 } - }, - { - failure: "This comment is roughly the same as the object's name. Either be more informative or don't include a comment.", - name: Utils.absolutePath('file.ts'), - ruleName: 'informative-docs', - startPosition: { character: 13, line: 49 } - } - ]); - }); - - it('should fail on uninformative docs comments using alias options', (): void => { - const script: string = ` - /** - * The FancyFoo. - */ - function foo() {} - `; - - const options = [ - { - aliases: { - foo: ['FancyFoo'] - } - } - ]; - - TestHelper.assertViolationsWithOptions('informative-docs', options, script, [ - { - failure: "This comment is roughly the same as the object's name. Either be more informative or don't include a comment.", - name: Utils.absolutePath('file.ts'), - ruleName: 'informative-docs', - startPosition: { character: 13, line: 5 } - } - ]); - }); - - it('should fail on uninformative docs comments using useless word options', (): void => { - const script: string = ` - /** - * Also foo. - */ - function foo() {} - `; - - const options = [ - { - uselessWords: ['also'] - } - ]; - - TestHelper.assertViolationsWithOptions('informative-docs', options, script, [ - { - failure: "This comment is roughly the same as the object's name. Either be more informative or don't include a comment.", - name: Utils.absolutePath('file.ts'), - ruleName: 'informative-docs', - startPosition: { character: 13, line: 5 } - } - ]); - }); -}); diff --git a/src/tests/InsecureRandomRuleTests.ts b/src/tests/InsecureRandomRuleTests.ts deleted file mode 100644 index 8b0af9f5d..000000000 --- a/src/tests/InsecureRandomRuleTests.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; -describe('insecureRandomRule', (): void => { - const ruleName: string = 'insecure-random'; - - it('should pass on non related functions', (): void => { - const script: string = ` - import crypto = require('crypto') - Math.abs(x) - crypto.randomBytes(2) - window.crypto.getRandomValues() - `; - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on Math.random', (): void => { - const script: string = ` - Math.random(); - const x = Math.random; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'Math.random produces insecure random numbers. ' + - 'Use crypto.randomBytes() or window.crypto.getRandomValues() instead', - name: Utils.absolutePath('file.ts'), - ruleName: 'insecure-random', - startPosition: { character: 13, line: 2 } - }, - { - failure: - 'Math.random produces insecure random numbers. ' + - 'Use crypto.randomBytes() or window.crypto.getRandomValues() instead', - name: Utils.absolutePath('file.ts'), - ruleName: 'insecure-random', - startPosition: { character: 23, line: 3 } - } - ]); - }); - - it('should fail on pseudoRandomBytes', (): void => { - const script: string = ` - import crypto = require('crypto') - - crypto.pseudoRandomBytes(0); - const x = crypto.pseudoRandomBytes; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'crypto.pseudoRandomBytes produces insecure random numbers. Use crypto.randomBytes() instead', - name: Utils.absolutePath('file.ts'), - ruleName: 'insecure-random', - startPosition: { character: 13, line: 4 } - }, - { - failure: 'crypto.pseudoRandomBytes produces insecure random numbers. Use crypto.randomBytes() instead', - name: Utils.absolutePath('file.ts'), - ruleName: 'insecure-random', - startPosition: { character: 23, line: 5 } - } - ]); - }); -}); diff --git a/src/tests/MaxFuncBodyLengthRuleTests.ts b/src/tests/MaxFuncBodyLengthRuleTests.ts deleted file mode 100644 index cc1fc858a..000000000 --- a/src/tests/MaxFuncBodyLengthRuleTests.ts +++ /dev/null @@ -1,362 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('maxFuncBodyLengthRule', (): void => { - let options: [boolean, number | object, object?]; - const script: string = ` - // https://github.com/Microsoft/tslint-microsoft-contrib/issues/468#issuecomment-407456317 - - // 1-line arrow function - const plusOne: (x: number) => number = (x: number): number => x + 1; // Line 1 - - // 3-line arrow function - const plusTwo: (x: number) => number = (x: number): number => { // Line 1 - return x + 2; // Line 2 - }; // Line 3 - - // 5-line "declared" function - function plusThree(x: number): number { // Line 1 - let retVal: number = x; // Line 2 - retVal += 3; // Line 3 - return retVal; // Line 4 - } // Line 5 - - // 7-line "expressed" function - const plusFour: (x: number) => number = function (x: number): number { // Line 1 - let retVal: number = x; // Line 2 - retVal += 1; // Line 3 - retVal += 1; // Line 4 - retVal += 2; // Line 5 - return retVal; // Line 6 - }; // Line 7 - - class PlusPlus { - public num: number; - - // 4-line constructor - constructor(num: number) { // Line 1 - this.num = num; // Line 2 - this.num *= 1; // Line 3 - } // Line 4 - - // 9-line method - public plusFive(): number { // Line 1 - let ret: number = this.num; // Line 2 - // Line 3 - for (let iter: number = 0; iter < 5; iter += 1) { // Line 4 - ret += 1; // Line 5 - } // Line 6 - // Line 7 - return ret; // Line 8 - } // Line 9 - } - - // 10-line arrow function (with counted comments amd blanks) - const plusSix: (x: number) => number = function (x: number): number { // Line 1 - /* KEEP */ // Line 2 - /* CALM */ // Line 3 - /* AND */ // Line 4 - // MIND // Line 5 - // THE // Line 6 - // GAP // Line 7 - - return x + 6; // Line 9 - }; // Line 10 - - // 11-nameless class - export default class extends PlusPlus {} - - console.log(plusOne(1)); // 2 - console.log(plusTwo(2)); // 4 - console.log(plusThree(3)); // 6 - console.log(plusFour(4)); // 8 - console.log(new PlusPlus(5).plusFive()); // 10 - console.log(plusSix(6)); // 12 - `; - - const ruleName: string = 'max-func-body-length'; - - describe('when functions do not exceed general option value and syntax kind wise options are not used', () => { - it('should not fail', (): void => { - TestHelper.assertViolations(ruleName, script, []); - }); - }); - - describe('when general option is used and functions lengths exceed its value', () => { - beforeEach(() => { - options = [true, 0]; - }); - - it('should fail', (): void => { - TestHelper.assertViolationsWithOptions(ruleName, options, script, [ - { - failure: 'Max arrow function body length exceeded - max: 0, actual: 1', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - ruleSeverity: 'ERROR', - startPosition: { - character: 48, - line: 5 - } - }, - { - failure: 'Max arrow function body length exceeded - max: 0, actual: 3', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - ruleSeverity: 'ERROR', - startPosition: { - character: 48, - line: 8 - } - }, - { - failure: 'Max function body length exceeded in function plusThree() - max: 0, actual: 5', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - ruleSeverity: 'ERROR', - startPosition: { - character: 9, - line: 13 - } - }, - { - failure: 'Max function expression body length exceeded in function expression () - max: 0, actual: 7', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - ruleSeverity: 'ERROR', - startPosition: { - character: 49, - line: 20 - } - }, - { - failure: 'Max constructor body length exceeded in class PlusPlus - max: 0, actual: 4', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - ruleSeverity: 'ERROR', - startPosition: { - character: 13, - line: 32 - } - }, - { - failure: 'Max method body length exceeded in method plusFive() - max: 0, actual: 9', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - ruleSeverity: 'ERROR', - startPosition: { - character: 13, - line: 38 - } - }, - { - failure: 'Max function expression body length exceeded in function expression () - max: 0, actual: 10', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - ruleSeverity: 'ERROR', - startPosition: { - character: 48, - line: 50 - } - } - ]); - }); - }); - - describe('when syntax kind wise options are used and functions lengths exceed their value', () => { - beforeEach(() => { - options = [ - true, - { - 'arrow-body-length': 2, - 'ctor-body-length': 3, - 'func-body-length': 4, - 'func-express-body-length': 7, - 'method-body-length': 8 - } - ]; - }); - - it('should fail', (): void => { - TestHelper.assertViolationsWithOptions(ruleName, options, script, [ - { - failure: 'Max arrow function body length exceeded - max: 2, actual: 3', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - ruleSeverity: 'ERROR', - startPosition: { - character: 48, - line: 8 - } - }, - { - failure: 'Max function body length exceeded in function plusThree() - max: 4, actual: 5', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - ruleSeverity: 'ERROR', - startPosition: { - character: 9, - line: 13 - } - }, - { - failure: 'Max constructor body length exceeded in class PlusPlus - max: 3, actual: 4', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - ruleSeverity: 'ERROR', - startPosition: { - character: 13, - line: 32 - } - }, - { - failure: 'Max method body length exceeded in method plusFive() - max: 8, actual: 9', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - ruleSeverity: 'ERROR', - startPosition: { - character: 13, - line: 38 - } - }, - { - failure: 'Max function expression body length exceeded in function expression () - max: 7, actual: 10', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - ruleSeverity: 'ERROR', - startPosition: { - character: 48, - line: 50 - } - } - ]); - }); - }); - - describe('when ignoring comments option is used and function lengths exceed their value', () => { - beforeEach(() => { - options = [true, 3, { 'ignore-comments': true }]; - }); - - it('should not fail due to single- or multi- line comments', (): void => { - TestHelper.assertNoViolationWithOptions( - ruleName, - options, - ` - function sum(a,b) { - /** - * add both a and b together - * this is some complex math, - * so it's best we abstract - * it away from the user - */ - return a + b; - } - - function sub(a,b) { - // similarly to sub, this is - // some pretty complex - // arithmetic. - // let's keep this away from - // the user as well. - return a - b; - } - ` - ); - }); - - it('should fail due to lines with mixed code and comments', (): void => { - TestHelper.assertViolationsWithOptions( - ruleName, - options, - ` - function sum(a,b) { - let sum = a; // start with a - sum += b; // now add b - return sum; // return the result - } - `, - [ - { - failure: 'Max function body length exceeded in function sum() - max: 3, actual: 5', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - startPosition: { - character: 17, - line: 2 - } - } - ] - ); - }); - }); - - describe('when using mocha describe blocks', () => { - beforeEach(() => { - options = [ - true, - 5, // max length is now 5 - { - 'ignore-parameters-to-function-regex': '^describe$' - } - ]; - }); - - it('should be able to ignore describe calls', (): void => { - TestHelper.assertViolationsWithOptions( - ruleName, - options, - ` - describe('something', (): void => { - // line 2 - // line 3 - // line 4 - // line 5 - }); // line 6 - describe('something', function name() { - // line 2 - // line 3 - // line 4 - // line 5 - // line 6 - }); // line 7 - describe('something', function () { - // line 2 - // line 3 - // line 4 - // line 5 - // line 6 - }); // line 7 - `, - [] - ); - }); - - it('should not ignore calls of functions that are not exactly named "describe"', (): void => { - TestHelper.assertViolationsWithOptions( - ruleName, - options, - ` - describeThings('something', (): void => { - // line 2 - // line 3 - // line 4 - // line 5 - }); // line 6 - `, - [ - { - failure: 'Max arrow function body length exceeded - max: 5, actual: 6', - name: Utils.absolutePath('file.ts'), - ruleName: 'max-func-body-length', - ruleSeverity: 'ERROR', - startPosition: { - character: 49, - line: 2 - } - } - ] - ); - }); - }); -}); diff --git a/src/tests/MissingJsdocRuleTests.ts b/src/tests/MissingJsdocRuleTests.ts deleted file mode 100644 index b2ed60e04..000000000 --- a/src/tests/MissingJsdocRuleTests.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('missing-jsdoc', (): void => { - const ruleName: string = 'missing-jsdoc'; - - it('should not fail on top level comment', (): void => { - const script: string = ` -/** - * whatever - */ -function whatever() { }`; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should not fail on top level comment with trailing spaces', (): void => { - const script: string = ` -/** - * whatever - */ -function whatever() { }`; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on missing comment', (): void => { - const script: string = ` -function whatever() { }`; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'File missing JSDoc comment at the top-level.', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-jsdoc', - startPosition: { character: 1, line: 2 } - } - ]); - }); - - it('should fail on one star comment', (): void => { - const script: string = ` -/* - * whatever - */ -function whatever() { }`; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'File missing JSDoc comment at the top-level.', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-jsdoc', - startPosition: { character: 1, line: 5 } - } - ]); - }); - - it('should fail on three star comment', (): void => { - const script: string = ` -/*** - * whatever - */ -function whatever() { }`; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'File missing JSDoc comment at the top-level.', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-jsdoc', - startPosition: { character: 1, line: 5 } - } - ]); - }); - - it('should fail on trailing chars', (): void => { - const script: string = ` -/** bad format - * whatever - */ -function whatever() { }`; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'File missing JSDoc comment at the top-level.', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-jsdoc', - startPosition: { character: 1, line: 5 } - } - ]); - }); - - it('should fail on leading spaces', (): void => { - const script: string = ` - /** - * whatever - */ - function indentedLikeAModuleFunction() { }`; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'File missing JSDoc comment at the top-level.', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-jsdoc', - startPosition: { character: 5, line: 5 } - } - ]); - }); -}); diff --git a/src/tests/MissingOptionalAnnotationTests.ts b/src/tests/MissingOptionalAnnotationTests.ts deleted file mode 100644 index c77da47af..000000000 --- a/src/tests/MissingOptionalAnnotationTests.ts +++ /dev/null @@ -1,145 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('missingOptionalAnnotationRule', (): void => { - const ruleName: string = 'missing-optional-annotation'; - - it('should not produce violations', (): void => { - const inputScript: string = ` -class MissingOptionalAnnotationPassingTestInput { - - constructor() {} - constructor(arg1?) {} - constructor(arg1, arg2?) {} - constructor(arg1, arg2?, arg3?) {} - - voidMethod() {} - unaryMethod(arg1) {} - bindaryMethod(arg1, arg2?) {} - ternaryMethod(arg1, arg2?, arg3?) {} - - private arrow0 = () => {}; - private arrow1 = (arg?) => {}; - private arrow2 = (arg1, arg2?) => {}; - private arrow3 = (arg1, arg2?, arg3?) => {}; - - private literalFunction0 = function() {}; - private literalFunction1 = function(arg?) {}; - private literalFunction2 = function(arg1, arg2?) {}; - private literalFunction3 = function(arg1, arg2?, arg3?) {}; - -} - -// these declarations need to be made outside of a class -function function0() {} -function function1(arg) {} -function function2(arg1, arg2?) {} -function function3(arg1, arg2?, arg3?) {}`; - TestHelper.assertViolations(ruleName, inputScript, []); - }); - - it('should not produce violations for 2nd parameter that has a default initializer', (): void => { - const script: string = 'function something(data? : any, others: Object = {}) { }'; - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should produce a violation when 1st parameter has a default initializer', (): void => { - const script: string = 'function something(data : Object = {}, others: any) { }'; - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Argument following optional argument missing optional annotation: others: any', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-optional-annotation', - startPosition: { - character: 40, - line: 1 - } - } - ]); - }); - - it('should produce violations', (): void => { - const inputFile: string = ` -class MissingOptionalAnnotationPassingTestInput { - - constructor(optionalArg1?, requiredArg2) {} - constructor(requiredArg1, optionalArg2?, requiredArg3) {} - - bindaryMethod(optionalArg1?, requiredArg2) {} - ternaryMethod(requiredArg1, optionalArg2?, requiredArg3) {} - - private arrow2 = (optionalArg1?, requiredArg2) => {}; - private arrow3 = (requiredArg1, optionalArg2?, requiredArg3) => {}; - - private literalFunction2 = function(optionalArg1?, requiredArg2) {}; - private literalFunction3 = function(requiredArg1, optionalArg2?, requiredArg3) {}; - -} - -// these declarations need to be made outside of a class -function function2(optionalArg1?, requiredArg2) {} -function function3(requiredArg1, optionalArg2?, requiredArg3) {}`; - TestHelper.assertViolations(ruleName, inputFile, [ - { - failure: 'Argument following optional argument missing optional annotation: requiredArg2', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-optional-annotation', - startPosition: { line: 4, character: 32 } - }, - { - failure: 'Argument following optional argument missing optional annotation: requiredArg3', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-optional-annotation', - startPosition: { line: 5, character: 46 } - }, - { - failure: 'Argument following optional argument missing optional annotation: requiredArg2', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-optional-annotation', - startPosition: { line: 7, character: 34 } - }, - { - failure: 'Argument following optional argument missing optional annotation: requiredArg3', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-optional-annotation', - startPosition: { line: 8, character: 48 } - }, - { - failure: 'Argument following optional argument missing optional annotation: requiredArg2', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-optional-annotation', - startPosition: { line: 10, character: 38 } - }, - { - failure: 'Argument following optional argument missing optional annotation: requiredArg3', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-optional-annotation', - startPosition: { line: 11, character: 52 } - }, - { - failure: 'Argument following optional argument missing optional annotation: requiredArg2', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-optional-annotation', - startPosition: { line: 13, character: 56 } - }, - { - failure: 'Argument following optional argument missing optional annotation: requiredArg3', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-optional-annotation', - startPosition: { line: 14, character: 70 } - }, - { - failure: 'Argument following optional argument missing optional annotation: requiredArg2', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-optional-annotation', - startPosition: { line: 19, character: 35 } - }, - { - failure: 'Argument following optional argument missing optional annotation: requiredArg3', - name: Utils.absolutePath('file.ts'), - ruleName: 'missing-optional-annotation', - startPosition: { line: 20, character: 49 } - } - ]); - }); -}); diff --git a/src/tests/MochaAvoidOnlyRuleTests.ts b/src/tests/MochaAvoidOnlyRuleTests.ts deleted file mode 100644 index fd2e71a3f..000000000 --- a/src/tests/MochaAvoidOnlyRuleTests.ts +++ /dev/null @@ -1,167 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('mochaAvoidOnlyRule', (): void => { - const ruleName: string = 'mocha-avoid-only'; - - it('should pass when only is not invoked', (): void => { - const script: string = ` - describe('some unit test', () => { - it('some test', () => { - // some test code - }); - - // these are not calls to mocha's it.only - it.only(); - it.only(''); - it.only(() => {}); - it.only(something, () => {}); - it.only('', something); - it.only(something, somethingElse); - - // these are not calls to mocha's describe.only - describe.only(); - describe.only(''); - describe.only(() => {}); - describe.only(something, () => {}); - describe.only('', something); - describe.only(something, somethingElse); - - // these are not calls to mocha's context.only - context.only(); - context.only(''); - context.only(() => {}); - context.only(something, () => {}); - context.only('', something); - context.only(something, somethingElse); - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on it.only with lambda', (): void => { - const script: string = ` - describe('some unit test', () => { - it.only('some test', () => { - // some test code - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Do not commit Mocha it.only function call', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-avoid-only', - startPosition: { character: 17, line: 3 } - } - ]); - }); - - it('should fail on specify.only with lambda', (): void => { - const script: string = ` - context('some unit test', () => { - specify.only('some test', () => { - // some test code - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Do not commit Mocha specify.only function call', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-avoid-only', - startPosition: { character: 17, line: 3 } - } - ]); - }); - - it('should fail on it.only with function', (): void => { - const script: string = ` - describe('some unit test', () => { - it.only('some test', function() { - // some test code - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Do not commit Mocha it.only function call', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-avoid-only', - startPosition: { character: 17, line: 3 } - } - ]); - }); - - it('should fail on describe.only with lambda', (): void => { - const script: string = ` - describe.only('some unit test', () => { - // some test code - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Do not commit Mocha describe.only function call', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-avoid-only', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on describe.only with function', (): void => { - const script: string = ` - describe.only('some unit test', function() { - // some test code - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Do not commit Mocha describe.only function call', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-avoid-only', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on context.only with lambda', (): void => { - const script: string = ` - context.only('some unit test', () => { - // some test code - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Do not commit Mocha context.only function call', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-avoid-only', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on context.only with function', (): void => { - const script: string = ` - context.only('some unit test', function() { - // some test code - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Do not commit Mocha context.only function call', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-avoid-only', - startPosition: { character: 13, line: 2 } - } - ]); - }); -}); diff --git a/src/tests/MochaNoSideEffectCodeRuleTests.ts b/src/tests/MochaNoSideEffectCodeRuleTests.ts deleted file mode 100644 index 40609b4b9..000000000 --- a/src/tests/MochaNoSideEffectCodeRuleTests.ts +++ /dev/null @@ -1,595 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('mochaNoSideEffectCodeRule', (): void => { - const ruleName: string = 'mocha-no-side-effect-code'; - - it('should pass on not a mocha test', (): void => { - const script: string = ` - var blah = foo; - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on most simple case', (): void => { - const script: string = ` - describe('someTest', (): void => { - const CONST1 = 'one'; - const CONST2 = 2; - const CONST3 = true; - const CONST4 = false; - - before((): void => { - const foo = someValue(); - }); - beforeEach((): void => { - const foo = someValue(); - }); - beforeAll((): void => { - const foo = someValue(); - }); - after((): void => { - const foo = someValue(); - }); - afterEach((): void => { - const foo = someValue(); - }); - afterAll((): void => { - const foo = someValue(); - }); - it((): void => { - const foo = someValue(); - }); - describe((): void => { - const CONST4 = false; - it((): void => { - const foo = someValue(); - }); - }); - context((): void => { - const CONST4 = false; - specify((): void => { - const foo = someValue(); - }); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on usage of skip/only', (): void => { - const script: string = ` - describe('someTest', (): void => { - - it.skip((): void => { - }); - - describe.skip((): void => { - it.skip((): void => { - }); - }); - - it.only((): void => { - }); - describe.only((): void => { - it.only((): void => { - }); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on function declarations', (): void => { - const script: string = ` - describe('someTest', (): void => { - - function doSomething() { - const x = doSomethingElse(); - } - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on multiline string', (): void => { - const script: string = ` - describe('someTest', (): void => { - - const CONST1 = \`some - multi-line - string\`; - - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on simple cast', (): void => { - const script: string = ` - describe('someTest', (): void => { - const publisher: DTO.Publisher = { '@class': 'Publisher' }; - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on describe.skip', (): void => { - const script: string = ` - describe('someTest', (): void => { - describe.skip('someTest', (): void => { - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on complex cast', (): void => { - const script: string = ` - describe('someTest', (): void => { - const publisher: DTO.Publisher = doSomething(); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'Mocha test contains dangerous variable initialization. ' + - 'Move to before()/beforeEach(): publisher: DTO.Publisher = <...', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-no-side-effect-code', - startPosition: { character: 23, line: 3 } - } - ]); - }); - - it('should fail on function calls', (): void => { - const script: string = ` - describe('someTest', (): void => { - expect(convertedTags).to.deep.equal(tags); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'Mocha test contains dangerous variable initialization. ' + - 'Move to before()/beforeEach(): expect(convertedTags).to.dee...', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-no-side-effect-code', - startPosition: { character: 17, line: 3 } - } - ]); - }); - - it('should fail on context', (): void => { - const script: string = ` - context('someTest', (): void => { - expect(convertedTags).to.deep.equal(tags); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'Mocha test contains dangerous variable initialization. ' + - 'Move to before()/beforeEach(): expect(convertedTags).to.dee...', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-no-side-effect-code', - startPosition: { character: 17, line: 3 } - } - ]); - }); - - it('should pass on correct scoping', (): void => { - const script: string = ` - describe('someTest', (): void => { - const CONST1 = 'one'; - const CONST2 = 2; - const CONST3 = true; - const CONST4 = false; - - before((): void => { - const foo = someValue(); - }); - beforeEach((): void => { - const foo = someValue(); - }); - beforeAll((): void => { - const foo = someValue(); - }); - after((): void => { - const foo = someValue(); - }); - afterEach((): void => { - const foo = someValue(); - }); - afterAll((): void => { - const foo = someValue(); - }); - it((): void => { - const foo = someValue(); - }); - describe((): void => { - const CONST4 = false; - it((): void => { - const foo = someValue(); - }); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on variable aliasing', (): void => { - const script: string = ` - let expect: Chai.ExpectStatic = chai.expect; - - describe('someTest', (): void => { - let expect2: Chai.ExpectStatic = chai.expect; - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass when using methods allowed by the Mocha API', (): void => { - const script: string = ` - describe('retries', (): void => { - this.retries(42); - - describe('slow', (): void => { - this.slow(2500); - - describe('timeout', (): void => { - this.timeout(5000); - }); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on date creation', (): void => { - const script: string = ` - let date = moment(); - let firstActiveDay: Moment = moment().subtract(2, 'years'); - let date2 = new Date(123123123); - describe('someTest', (): void => { - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on simple JSON structures', (): void => { - const script: string = ` - let onDaySelected: (newDate: Moment) => void = (newDate: Moment) => { - return; - }; - let inputProps: DatePicker.Props = { - selectedDate: moment(), - onDaySelected: onDaySelected, - componentName: 'test' - }; - describe('someTest', (): void => { - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on complex JSON structures', (): void => { - const script: string = ` - let searchItems: DTO.SearchItem[] = [ - {'id': '4', 'name': 'All Search Topics', owner: undefined, ownerName: '', createdDate: undefined}, - {'id': '66', 'name': 'Products', 'parentId': '4', owner: undefined, ownerName: '', createdDate: undefined}, - {'id': '314012', 'name': 'Honey', 'parentId': '66', owner: undefined, ownerName: '', createdDate: undefined}, - {'id': '314072', 'name': 'Bonny', 'parentId': '66', owner: undefined, ownerName: '', createdDate: undefined}, - {'id': '65', 'name': 'Uncategorized', 'parentId': '4', owner: undefined, ownerName: '', createdDate: undefined}, - {'id': '216102', 'name': 'Blub', 'parentId': '65', owner: undefined, ownerName: '', createdDate: undefined}, - {'id': '314022', 'name': 'Bnutsch', 'parentId': '65', owner: undefined, ownerName: '', createdDate: undefined} - ]; - describe('someTest', (): void => { - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass string concatenation', (): void => { - const script: string = ` - const SMALL_IMAGE: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+' + - 'AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAASdAAAEnQB3mYfeAAAAE9JREFUCB0BRAC7/wAAAAAAAAAAAAAAAAAAA' + - 'AAAAAAAAAD/H1f/AAAA/wAAAAAAAAAAAAAAAP///Vf/AAAAAAAAAAAAAAAAAAAAAAAAAAAA/GsHxbcKPckAAAAASUVORK5CYII='; - - const HOUR: number = 60 * 60; - - describe('someTest', (): void => { }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass configured factory methods', (): void => { - const script: string = ` - const x = RestDataFactory.createSocialProfile() - - describe('someTest', (): void => { - const < = RestDataFactory.createSocialProfileToken() - }); - `; - - TestHelper.assertViolationsWithOptions(ruleName, [true, { ignore: '^RestDataFactory\\.create.*' }], script, []); - }); - - it('should pass newly declared classes', (): void => { - const script: string = ` - describe('someTest', (): void => { - - class MockModel extends Backbone.Model { - - public fetch(options?: Backbone.ModelFetchOptions): JQueryXHR { - let request: JQueryXHR = super.fetch(options); - return request; - } - - public save(attributes?: any, options?: Backbone.ModelSaveOptions): JQueryXHR { - let request: JQueryXHR = super.save(attributes, options); - return request; - } - - } - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on describe', (): void => { - const script: string = ` - describe('someTest', (): void => { - const VIOLATION1 = this.myMethod(); - const VIOLATION2 = new MyClass(); - - it((): void => { - const foo = someValue(); // OK - }); - - describe('someTest', (): void => { - const VIOLATION3 = true ? false : true; - const VIOLATION4 = x || 'some value'; - - it((): void => { - const foo = someValue(); // OK - }); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'Mocha test contains dangerous variable initialization. ' + - 'Move to before()/beforeEach(): VIOLATION1 = this.myMethod()', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-no-side-effect-code', - startPosition: { character: 23, line: 3 } - }, - { - failure: - 'Mocha test contains dangerous variable initialization. ' + 'Move to before()/beforeEach(): VIOLATION2 = new MyClass()', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-no-side-effect-code', - startPosition: { character: 23, line: 4 } - }, - { - failure: - 'Mocha test contains dangerous variable initialization. ' + - 'Move to before()/beforeEach(): VIOLATION3 = true ? false : ...', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-no-side-effect-code', - startPosition: { character: 27, line: 11 } - }, - { - failure: - 'Mocha test contains dangerous variable initialization. ' + - "Move to before()/beforeEach(): VIOLATION4 = x || 'some value'", - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-no-side-effect-code', - startPosition: { character: 27, line: 12 } - } - ]); - }); - - it('should fail on global scope', (): void => { - const script: string = ` - - const VIOLATION1 = new MyClass(); - - describe('someTest', (): void => { - it((): void => { - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'Mocha test contains dangerous variable initialization. ' + 'Move to before()/beforeEach(): VIOLATION1 = new MyClass()', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-no-side-effect-code', - startPosition: { character: 19, line: 3 } - } - ]); - }); - - describe('arrays', (): void => { - it('should pass on empty and simple arrays', (): void => { - const script: string = ` - describe('someTest', (): void => { - const CONST1 = []; - const CONST2 = [ true, false, 1, 0, 'value', null]; - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on nested simple arrays', (): void => { - const script: string = ` - describe('someTest', (): void => { - const options = [true, [ - 'Mobile IE 10', - 'IE >= 10', - 'Chrome > 45', - 'Firefox', - 'Mobile Safari < 10' - ]]; - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on complex arrays', (): void => { - const script: string = ` - describe('someTest', (): void => { - const VIOLATION = [ someCall() ]; - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'Mocha test contains dangerous variable initialization. ' + - 'Move to before()/beforeEach(): VIOLATION = [ someCall() ]', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-no-side-effect-code', - startPosition: { character: 23, line: 3 } - } - ]); - }); - }); - - describe('Array.forEach', (): void => { - it('should pass on Array.forEach with empty arrays', (): void => { - const script: string = ` - describe('something', (): void => { - [].forEach((): void => { - it('test', (): void => { - }); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on Array.forEach with simple arrays', (): void => { - const script: string = ` - describe('something', (): void => { - [ true, false, 1, 0, 'value', null].forEach((): void => { - it('test', (): void => { - }); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on Array.forEach of simple object arrays', (): void => { - const script: string = ` - describe('something', (): void => { - [ - { name: 'alpha', value: 1 }, - { name: 'beta', value: 2 }, - { name: 'gamma', value: 3 } - ].forEach((): void => { - it('test', (): void => { - }); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on Array.forEach of complex arrays', (): void => { - const script: string = ` - describe('something', (): void => { - [ someCall() ].forEach((): void => { - it('test', (): void => { - }); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'Mocha test contains dangerous variable initialization. ' + - 'Move to before()/beforeEach(): [ someCall() ].forEach((): v...', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-no-side-effect-code', - startPosition: { character: 21, line: 3 } - } - ]); - }); - - it('should fail on Array.forEach from function call', (): void => { - const script: string = ` - describe('something', (): void => { - someCall().forEach((): void => { - it('test', (): void => { - }); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'Mocha test contains dangerous variable initialization. ' + - 'Move to before()/beforeEach(): someCall().forEach((): void ...', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-no-side-effect-code', - startPosition: { character: 21, line: 3 } - } - ]); - }); - - it('should fail on Array.forEach with side effects in function', (): void => { - const script: string = ` - describe('something', (): void => { - [1, 2, 3].forEach((): void => { - const VIOLATION = new MyClass(); - it('test', (): void => { - }); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'Mocha test contains dangerous variable initialization. ' + - 'Move to before()/beforeEach(): VIOLATION = new MyClass()', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-no-side-effect-code', - startPosition: { character: 31, line: 4 } - } - ]); - }); - }); -}); diff --git a/src/tests/MochaUnneededDoneRuleTests.ts b/src/tests/MochaUnneededDoneRuleTests.ts deleted file mode 100644 index b25135c19..000000000 --- a/src/tests/MochaUnneededDoneRuleTests.ts +++ /dev/null @@ -1,219 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('mochaUnneededDoneRule', (): void => { - const ruleName: string = 'mocha-unneeded-done'; - - it('should pass on standard usage - arrow functions', (): void => { - const script: string = ` - describe('...', (): void => { - before((done: MochaDone): void => { - something(done); - }); - after((done: MochaDone): void => { - something(done); - }); - beforeEach((done: MochaDone): void => { - something(done); - }); - afterEach((done: MochaDone): void => { - something(done); - }); - it('...', (done: MochaDone): void => { - something(done); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on standard usage - functions expressions', (): void => { - const script: string = ` - describe('...', function(): void { - before(function(done: MochaDone): void { - something(done); - }); - after(function(done: MochaDone): void { - something(done); - }); - beforeEach(function(done: MochaDone): void { - something(done); - }); - afterEach(function(done: MochaDone): void { - something(done); - }); - it('...', function(done: MochaDone): void { - something(done); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on standard usage - context/specify', (): void => { - const script: string = ` - context('...', function(): void { - specify('...', function(done: MochaDone): void { - something(done); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on reassignment', (): void => { - const script: string = ` - describe('something...', (): void => { - it('...', (done): void => { - var x = done; - done(); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on unneeded dones in arrow functions', (): void => { - const script: string = ` - describe('...', (): void => { - before((done): void => { - doSomething(); - done(); - }); - after((done: MochaDone): void => { - done(); // it doesn't matter what order done() comes in. - doSomething(); - }); - beforeEach((aliasedDone: MochaDone): void => { - doSomething(); - aliasedDone(); - }); - afterEach((done: MochaDone): void => { - doSomething(); - done(); - }); - it('...', (done: MochaDone): void => { - doSomething(); - done(); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Unneeded Mocha Done. Parameter can be safely removed: done', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-unneeded-done', - startPosition: { character: 25, line: 3 } - }, - { - failure: 'Unneeded Mocha Done. Parameter can be safely removed: done', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-unneeded-done', - startPosition: { character: 24, line: 7 } - }, - { - failure: 'Unneeded Mocha Done. Parameter can be safely removed: aliasedDone', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-unneeded-done', - startPosition: { character: 29, line: 11 } - }, - { - failure: 'Unneeded Mocha Done. Parameter can be safely removed: done', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-unneeded-done', - startPosition: { character: 28, line: 15 } - }, - { - failure: 'Unneeded Mocha Done. Parameter can be safely removed: done', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-unneeded-done', - startPosition: { character: 28, line: 19 } - } - ]); - }); - - it('should fail on unneeded dones - context/specify', (): void => { - const script: string = ` - context('...', (): void => { - specify('...', (done: MochaDone): void => { - doSomething(); - done(); - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Unneeded Mocha Done. Parameter can be safely removed: done', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-unneeded-done', - startPosition: { character: 33, line: 3 } - } - ]); - }); - - it('should fail on unneeded done - functions expressions', (): void => { - const script: string = ` - describe('...', function(): void { - before(function(done): void { - something(); - done() - }); - after(function(myDone: MochaDone): void { - myDone(); // it doesn't matter what order it comes in - something(); - }); - beforeEach(function(done: MochaDone): void { - something(); - done() - }); - afterEach(function(done: MochaDone): void { - something(); - done() - }); - it('...', function(done: MochaDone): void { - something(); - done() - }); - }); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Unneeded Mocha Done. Parameter can be safely removed: done', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-unneeded-done', - startPosition: { character: 33, line: 3 } - }, - { - failure: 'Unneeded Mocha Done. Parameter can be safely removed: myDone', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-unneeded-done', - startPosition: { character: 32, line: 7 } - }, - { - failure: 'Unneeded Mocha Done. Parameter can be safely removed: done', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-unneeded-done', - startPosition: { character: 37, line: 11 } - }, - { - failure: 'Unneeded Mocha Done. Parameter can be safely removed: done', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-unneeded-done', - startPosition: { character: 36, line: 15 } - }, - { - failure: 'Unneeded Mocha Done. Parameter can be safely removed: done', - name: Utils.absolutePath('file.ts'), - ruleName: 'mocha-unneeded-done', - startPosition: { character: 36, line: 19 } - } - ]); - }); -}); diff --git a/src/tests/NoBackboneGetSetOutsideModelRuleTests.ts b/src/tests/NoBackboneGetSetOutsideModelRuleTests.ts deleted file mode 100644 index 01b0741bc..000000000 --- a/src/tests/NoBackboneGetSetOutsideModelRuleTests.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noBackboneGetSetOutsideModelRule', (): void => { - const ruleName: string = 'no-backbone-get-set-outside-model'; - - it('should pass on get and set calls on the this reference', (): void => { - const script: string = ` - var datetime = this.get('timestamp'); - this.set('modificationdate', datetime); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on get and set calls with wrong # parameters and wrong parameter types', (): void => { - const script: string = ` - model.get(); - model.get(someIdentifier); - model.get('timestamp', 'someOtherValue'); - - model.set(); - model.set('modificationdate'); - model.set('modificationdate', value1, value2); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on get and set on an object different than this', (): void => { - const script: string = ` - var datetime = model.get('timestamp'); - model.set('modificationdate', datetime); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Backbone get() called outside of owning model: model.get('timestamp')", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-backbone-get-set-outside-model', - startPosition: { character: 28, line: 2 } - }, - { - failure: "Backbone set() called outside of owning model: model.set('modificationdate', datetime)", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-backbone-get-set-outside-model', - startPosition: { character: 13, line: 3 } - } - ]); - }); -}); diff --git a/src/tests/NoBannedTermsTests.ts b/src/tests/NoBannedTermsTests.ts deleted file mode 100644 index e25a92a99..000000000 --- a/src/tests/NoBannedTermsTests.ts +++ /dev/null @@ -1,714 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noBannedTermsRule', (): void => { - const RULE_NAME: string = 'no-banned-terms'; - - describe('module variables', () => { - it('should not refer to caller', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - var caller; - }`, - [ - { - failure: 'Forbidden reference to banned term: caller', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 25, line: 2 } - } - ] - ); - }); - - it('should not refer to callee', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - var callee; - }`, - [ - { - failure: 'Forbidden reference to banned term: callee', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 25, line: 2 } - } - ] - ); - }); - - it('should not refer to arguments', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - var arguments; - }`, - [ - { - failure: 'Forbidden reference to banned term: arguments', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 25, line: 2 } - } - ] - ); - }); - - it('should not refer to eval', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - var eval; - }`, - [ - { - failure: 'Forbidden reference to banned term: eval', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 25, line: 2 } - } - ] - ); - }); - }); - - describe('module functions', () => { - it('should not refer to caller', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - function caller() {} - }`, - [ - { - failure: 'Forbidden reference to banned term: caller', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - - it('should not refer to callee', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - function callee() {} - }`, - [ - { - failure: 'Forbidden reference to banned term: callee', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - - it('should not refer to arguments', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - function arguments() {} - }`, - [ - { - failure: 'Forbidden reference to banned term: arguments', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - - it('should not refer to eval', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - function eval() {} - }`, - [ - { - failure: 'Forbidden reference to banned term: eval', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - }); - - describe('class variables', () => { - it('should not refer to caller', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - private caller; - }`, - [ - { - failure: 'Forbidden reference to banned term: caller', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - - it('should not refer to callee', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - private callee; - }`, - [ - { - failure: 'Forbidden reference to banned term: callee', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - - it('should not refer to arguments', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - private arguments; - }`, - [ - { - failure: 'Forbidden reference to banned term: arguments', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - - it('should not refer to eval', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - private eval; - }`, - [ - { - failure: 'Forbidden reference to banned term: eval', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - }); - - describe('class properties', () => { - it('should not refer to caller', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - private var; - set caller(value) {} - get caller() { return var;} - }`, - [ - { - failure: 'Forbidden reference to banned term: caller', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 3 } - }, - { - failure: 'Forbidden reference to banned term: caller', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 4 } - } - ] - ); - }); - - it('should not refer to callee', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - private var; - set callee(value) {} - get callee() { return var;} - }`, - [ - { - failure: 'Forbidden reference to banned term: callee', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 3 } - }, - { - failure: 'Forbidden reference to banned term: callee', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 4 } - } - ] - ); - }); - - it('should not refer to arguments', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - private var; - set arguments(value) {} - get arguments() { return var;} - }`, - [ - { - failure: 'Forbidden reference to banned term: arguments', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 3 } - }, - { - failure: 'Forbidden reference to banned term: arguments', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 4 } - } - ] - ); - }); - - it('should not refer to eval', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - private var; - set eval(value) {} - get eval() { return var;} - }`, - [ - { - failure: 'Forbidden reference to banned term: eval', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 3 } - }, - { - failure: 'Forbidden reference to banned term: eval', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 4 } - } - ] - ); - }); - }); - - describe('class methods', () => { - it('should not refer to caller', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - caller() {} - }`, - [ - { - failure: 'Forbidden reference to banned term: caller', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - - it('should not refer to callee', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - callee() {} - }`, - [ - { - failure: 'Forbidden reference to banned term: callee', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - - it('should not refer to arguments', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - arguments() {} - }`, - [ - { - failure: 'Forbidden reference to banned term: arguments', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - - it('should not refer to eval', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - eval() {} - }`, - [ - { - failure: 'Forbidden reference to banned term: eval', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - }); - - describe('methods parameters', () => { - it('should not refer to caller', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - method(caller) {} - }`, - [ - { - failure: 'Forbidden reference to banned term: caller', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 28, line: 2 } - } - ] - ); - }); - - it('should not refer to callee', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - method(callee) {} - }`, - [ - { - failure: 'Forbidden reference to banned term: callee', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 28, line: 2 } - } - ] - ); - }); - - it('should not refer to arguments', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - method(arguments) {} - }`, - [ - { - failure: 'Forbidden reference to banned term: arguments', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 28, line: 2 } - } - ] - ); - }); - - it('should not refer to eval', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `class Sample { - method(eval) {} - }`, - [ - { - failure: 'Forbidden reference to banned term: eval', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 28, line: 2 } - } - ] - ); - }); - }); - - describe('function parameters', () => { - it('should not refer to caller', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - function method(caller) {} - }`, - [ - { - failure: 'Forbidden reference to banned term: caller', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 37, line: 2 } - } - ] - ); - }); - - it('should not refer to callee', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - function method(callee) {} - }`, - [ - { - failure: 'Forbidden reference to banned term: callee', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 37, line: 2 } - } - ] - ); - }); - - it('should not refer to arguments', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - function method(arguments) {} - }`, - [ - { - failure: 'Forbidden reference to banned term: arguments', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 37, line: 2 } - } - ] - ); - }); - - it('should not refer to eval', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - function method(eval) {} - }`, - [ - { - failure: 'Forbidden reference to banned term: eval', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 37, line: 2 } - } - ] - ); - }); - }); - - describe('arrow function parameters', () => { - it('should not refer to caller', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - var func = (caller) => {}; - }`, - [ - { - failure: 'Forbidden reference to banned term: caller', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 33, line: 2 } - } - ] - ); - }); - - it('should not refer to callee', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - var func = (callee) => {}; - }`, - [ - { - failure: 'Forbidden reference to banned term: callee', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 33, line: 2 } - } - ] - ); - }); - - it('should not refer to arguments', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - var func = (arguments) => {}; - }`, - [ - { - failure: 'Forbidden reference to banned term: arguments', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 33, line: 2 } - } - ] - ); - }); - - it('should not refer to eval', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `module Sample { - var func = (eval) => {}; - }`, - [ - { - failure: 'Forbidden reference to banned term: eval', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 33, line: 2 } - } - ] - ); - }); - }); - - describe('local variables', () => { - it('should not refer to caller', (): void => { - TestHelper.assertViolations(RULE_NAME, `var caller;`, [ - { - failure: 'Forbidden reference to banned term: caller', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 5, line: 1 } - } - ]); - }); - - it('should not refer to callee', (): void => { - TestHelper.assertViolations(RULE_NAME, `var callee;`, [ - { - failure: 'Forbidden reference to banned term: callee', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 5, line: 1 } - } - ]); - }); - - it('should not refer to arguments', (): void => { - TestHelper.assertViolations(RULE_NAME, `var arguments`, [ - { - failure: 'Forbidden reference to banned term: arguments', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 5, line: 1 } - } - ]); - }); - - it('should not refer to eval', (): void => { - TestHelper.assertViolations(RULE_NAME, `var eval;`, [ - { - failure: 'Forbidden reference to banned term: eval', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 5, line: 1 } - } - ]); - }); - }); - - describe('interface declarations', () => { - it('should not refer to caller', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `interface Sample { - caller: any; - }`, - [ - { - failure: 'Forbidden reference to banned term: caller', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - - it('should not refer to callee', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `interface Sample { - callee: any; - }`, - [ - { - failure: 'Forbidden reference to banned term: callee', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - - it('should not refer to arguments', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `interface Sample { - arguments: any; - }`, - [ - { - failure: 'Forbidden reference to banned term: arguments', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - - it('should not refer to eval', (): void => { - TestHelper.assertViolations( - RULE_NAME, - `interface Sample { - eval: any; - }`, - [ - { - failure: 'Forbidden reference to banned term: eval', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-banned-terms', - startPosition: { character: 21, line: 2 } - } - ] - ); - }); - }); -}); diff --git a/src/tests/NoConstantConditionRuleTests.ts b/src/tests/NoConstantConditionRuleTests.ts deleted file mode 100644 index 895df59e0..000000000 --- a/src/tests/NoConstantConditionRuleTests.ts +++ /dev/null @@ -1,502 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noConstantConditionRule', (): void => { - const ruleName: string = 'no-constant-condition'; - - it('should pass on comparisons', (): void => { - const script: string = ` - if (something === false) {} - if (something === true) {} - if (something > 1) {} - if (1 > something) {} - if (0 < 9 < 4 > something) {} - if (something < 9 < 4 > 2) {} - if (0 && 9 || 4 && !something) {} - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on hard coded loops when checkLoops is false', (): void => { - const script: string = ` - while (true) { - doSomething(); - }; - - for (;true;) { - doSomething(); - }; - - do { - doSomething(); - } while (true)`; - - const options = [true, { checkLoops: false }]; - TestHelper.assertViolationsWithOptions(ruleName, options, script, []); - }); - - it('should fail on if-booleans', (): void => { - const script: string = ` - if (false) {} - if (true) {} - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: if (false)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found constant conditional: if (true)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 3 } - } - ]); - }); - - it('should fail on constant comparisons', (): void => { - const script: string = ` - if (0 < 9) {} - if (0 > 9) {} - if (0 <= 9) {} - if (0 >= 9) {} - if (0 == 9) {} - if (0 != 9) {} - if (0 === 9) {} - if (0 !== 9) {} - if (0 >= 9) {} - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: if (0 < 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found constant conditional: if (0 > 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 3 } - }, - { - failure: 'Found constant conditional: if (0 <= 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 4 } - }, - { - failure: 'Found constant conditional: if (0 >= 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 5 } - }, - { - failure: 'Found constant conditional: if (0 == 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 6 } - }, - { - failure: 'Found constant conditional: if (0 != 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 7 } - }, - { - failure: 'Found constant conditional: if (0 === 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 8 } - }, - { - failure: 'Found constant conditional: if (0 !== 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 9 } - }, - { - failure: 'Found constant conditional: if (0 >= 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 10 } - } - ]); - }); - - it('should fail on nested constant comparison', (): void => { - const script: string = ` - if (0 < 9 < 4 > 2) {} - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: if (0 < 9 < 4 > 2)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on constant infix arithmetic', (): void => { - const script: string = ` - if (0 + 9) {} - if (0 - 9) {} - if (0 * 9) {} - if (0 / 9) {} - if (0 % 9) {} - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: if (0 + 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found constant conditional: if (0 - 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 3 } - }, - { - failure: 'Found constant conditional: if (0 * 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 4 } - }, - { - failure: 'Found constant conditional: if (0 / 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 5 } - }, - { - failure: 'Found constant conditional: if (0 % 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 6 } - } - ]); - }); - - it('should fail on constant postfix arithmetic', (): void => { - const script: string = ` - if (0++) {} - if (0--) {} - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: if (0++)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found constant conditional: if (0--)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 3 } - } - ]); - }); - - it('should fail on constant prefix arithmetic', (): void => { - const script: string = ` - if (++0) {} - if (--0) {} - if (!true) {} - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: if (++0)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found constant conditional: if (--0)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 3 } - }, - { - failure: 'Found constant conditional: if (!true)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 4 } - } - ]); - }); - - it('should fail on logic operators', (): void => { - const script: string = ` - if (0 && 2) {} - if (3 || 9) {} - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: if (0 && 2)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found constant conditional: if (3 || 9)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 3 } - } - ]); - }); - - it('should fail on if-numbers', (): void => { - const script: string = ` - if (0) {} - if (1) {} - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: if (0)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Found constant conditional: if (1)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 13, line: 3 } - } - ]); - }); - - it('should fail on ternary-booleans', (): void => { - const script: string = ` - var x = true ? 1 : 0; - var y = false ? 1 : 0; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: true ?', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 21, line: 2 } - }, - { - failure: 'Found constant conditional: false ?', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { character: 21, line: 3 } - } - ]); - }); - - it('should fail on ternary-numbers', (): void => { - const script: string = ` - var x = 1 ? 1 : 0; - var y = 0 ? 1 : 0; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: 1 ?', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 21, - line: 2 - } - }, - { - failure: 'Found constant conditional: 0 ?', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 21, - line: 3 - } - } - ]); - }); - - it('should fail on while-booleans', (): void => { - const script: string = ` - while (false) {} - while (true) {} - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: while (false)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 13, - line: 2 - } - }, - { - failure: 'Found constant conditional: while (true)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 13, - line: 3 - } - } - ]); - }); - - it('should fail on while-numbers', (): void => { - const script: string = ` - while (0) {} - while (1) {} - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: while (0)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 13, - line: 2 - } - }, - { - failure: 'Found constant conditional: while (1)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 13, - line: 3 - } - } - ]); - }); - - it('should fail on do-while-booleans', (): void => { - const script: string = ` - do {} while (true) - do {} while (false) - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: while (true)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 13, - line: 2 - } - }, - { - failure: 'Found constant conditional: while (false)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 13, - line: 3 - } - } - ]); - }); - - it('should fail on do-while-numbers', (): void => { - const script: string = ` - do {} while (1) - do {} while (0) - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: while (1)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 13, - line: 2 - } - }, - { - failure: 'Found constant conditional: while (0)', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 13, - line: 3 - } - } - ]); - }); - - it('should fail on for-booleans', (): void => { - const script: string = ` - for (;true;) { } - for (;false;) { } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: ;true;', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 13, - line: 2 - } - }, - { - failure: 'Found constant conditional: ;false;', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 13, - line: 3 - } - } - ]); - }); - - it('should fail on for-numbers', (): void => { - const script: string = ` - for (;1;) { } - for (;0;) { } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Found constant conditional: ;1;', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 13, - line: 2 - } - }, - { - failure: 'Found constant conditional: ;0;', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-constant-condition', - startPosition: { - character: 13, - line: 3 - } - } - ]); - }); -}); diff --git a/src/tests/NoControlRegexRuleTests.ts b/src/tests/NoControlRegexRuleTests.ts deleted file mode 100644 index c1eac548c..000000000 --- a/src/tests/NoControlRegexRuleTests.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noControlRegexRule', (): void => { - const ruleName: string = 'no-control-regex'; - - it('should pass on chars higher than x20', (): void => { - const script: string = ` - var pattern1 = /\\x20/; - var pattern2 = /\\x21/; - var pattern3 = /\\x30/; - var pattern4 = /\\x31/; - var pattern5 = /\\x20/; - var pattern6 = new RegExp("\\x20"); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on x1f', (): void => { - const script: string = ` - var pattern1 = /\\x1f/; - var pattern2 = new RegExp("something \\x1f something else"); - var pattern3 = RegExp("\\x1f trailing text"); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Unexpected control character in regular expression', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-control-regex', - startPosition: { character: 28, line: 2 } - }, - { - failure: 'Unexpected control character in regular expression', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-control-regex', - startPosition: { character: 39, line: 3 } - }, - { - failure: 'Unexpected control character in regular expression', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-control-regex', - startPosition: { character: 35, line: 4 } - } - ]); - }); - - it('should fail on x00', (): void => { - const script: string = ` - var pattern1 = /\\x00/; - var pattern2 = new RegExp("\\x00"); - var pattern3 = RegExp("\\x00"); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Unexpected control character in regular expression', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-control-regex', - startPosition: { character: 28, line: 2 } - }, - { - failure: 'Unexpected control character in regular expression', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-control-regex', - startPosition: { character: 39, line: 3 } - }, - { - failure: 'Unexpected control character in regular expression', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-control-regex', - startPosition: { character: 35, line: 4 } - } - ]); - }); -}); diff --git a/src/tests/NoDeleteExpressionTests.ts b/src/tests/NoDeleteExpressionTests.ts deleted file mode 100644 index b9fd29ea0..000000000 --- a/src/tests/NoDeleteExpressionTests.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noDeleteExpressionRule', (): void => { - const RULE_NAME: string = 'no-delete-expression'; - - it('should not produce violations', (): void => { - const script: string = ` - var x = { - myProperty: 'sometext' - }; - delete x.myProperty; - delete x[myProperty] - - delete this.router.routes[routeName]; - - delete this.router.routes.moreRoutes[routeName];`; - TestHelper.assertViolations(RULE_NAME, script, []); - }); - - it('should not fail when using subelement notation', (): void => { - const script: string = ` - delete rights[name]; - `; - TestHelper.assertViolations(RULE_NAME, script, []); - }); - - it('should produce violations ', (): void => { - const inputFile: string = ` - var something: int = 22; - - if (something) { - var variableForDeletion = 10; - delete variableForDeletion; - } `; - TestHelper.assertViolations(RULE_NAME, inputFile, [ - { - failure: 'Variables should not be deleted: variableForDeletion', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-delete-expression', - startPosition: { - line: 6, - character: 24 - } - } - ]); - }); -}); diff --git a/src/tests/NoDisableAutoSanitizationTests.ts b/src/tests/NoDisableAutoSanitizationTests.ts deleted file mode 100644 index 856f7a5f5..000000000 --- a/src/tests/NoDisableAutoSanitizationTests.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noDisableAutoSanitizationRule', (): void => { - it('should produce violation for execUnsafeLocalFunction', (): void => { - const ruleName: string = 'no-disable-auto-sanitization'; - const script: string = 'var retVal = MSApp.execUnsafeLocalFunction(() => {});'; - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Forbidden call to execUnsafeLocalFunction', - ruleName: 'no-disable-auto-sanitization', - name: Utils.absolutePath('file.ts'), - startPosition: { line: 1, character: 14 } - } - ]); - }); - - it('should produce violation for setInnerHTMLUnsafe', (): void => { - const ruleName: string = 'no-disable-auto-sanitization'; - const script: string = 'WinJS.Utilities.setInnerHTMLUnsafe(element, text);'; - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Forbidden call to setInnerHTMLUnsafe', - ruleName: 'no-disable-auto-sanitization', - name: Utils.absolutePath('file.ts'), - startPosition: { line: 1, character: 1 } - } - ]); - }); -}); diff --git a/src/tests/NoDocumentDomainRuleTests.ts b/src/tests/NoDocumentDomainRuleTests.ts deleted file mode 100644 index e809c070e..000000000 --- a/src/tests/NoDocumentDomainRuleTests.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noDocumentDomainRule', (): void => { - const ruleName: string = 'no-document-domain'; - - it('should pass when not setting a value to document.domain', (): void => { - const script: string = ` - console.log(document.domain); - console.log(document.domain.value); - let x = document.domain; - let y = document.domain.value; - - document.domain.value = 'some value'; - model.domain = 'some model value'; - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on assigning constant', (): void => { - const script: string = ` - document.domain = 'some value'; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Forbidden write to document.domain: document.domain = 'some value'", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-document-domain', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on assigning variable', (): void => { - const script: string = ` - document.domain = someValue; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Forbidden write to document.domain: document.domain = someValue', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-document-domain', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on assigning variable on window', (): void => { - const script: string = ` - window.document.domain = someValue; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Forbidden write to document.domain: window.document.domain = someValue', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-document-domain', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should pass when document is aliased because the type checker is so weak', (): void => { - const script: string = ` - let doc: Document = document; - doc.domain = 'some value'; - `; - - TestHelper.assertViolations(ruleName, script, []); - }); -}); diff --git a/src/tests/NoDocumentWriteTests.ts b/src/tests/NoDocumentWriteTests.ts deleted file mode 100644 index ad5406122..000000000 --- a/src/tests/NoDocumentWriteTests.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noDocumentWriteRule', (): void => { - const RULE_NAME: string = 'no-document-write'; - - it('should not produce violations ', (): void => { - const script: string = ` -interface DocumentLikeAPI { - write: ((arg : string) => void); - writeln: ((arg : string) => void); -} - -function documentLikeAPIFunction() : DocumentLikeAPI { - return { - write: () => {}, - writeln: () => {}, - }; -} - -// These usages are OK because they are not on the DOM document -var documentAPI : DocumentLikeAPI = documentLikeAPIFunction(); -documentAPI.write('...'); -documentAPI.writeln('...'); -documentLikeAPIFunction().write('...'); -documentLikeAPIFunction().writeln('...'); - -// wrong # of args -document.write(); -document.write('', ''); -document.writeln(); -document.writeln('', ''); - -// type system has no idea what 'doc' is -var doc = document; -doc.write('...'); -doc.writeln('...'); - -// type system has no idea what 'documentFunction' returns -function documentFunction() : Document { - return window.document; -} -documentFunction().write('...'); -documentFunction().writeln('...'); - -// this is not the window presumably -this.document.write('...'); -this.document.writeln('...'); -`; - TestHelper.assertViolations(RULE_NAME, script, []); - }); - - it('should produce violations ', (): void => { - const script: string = ` -document.write('...'); -document.writeln('...'); -window.document.write('...'); -window.document.writeln('...'); -`; - TestHelper.assertViolations(RULE_NAME, script, [ - { - failure: 'Forbidden call to document.write', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-document-write', - startPosition: { character: 1, line: 2 } - }, - { - failure: 'Forbidden call to document.writeln', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-document-write', - startPosition: { character: 1, line: 3 } - }, - { - failure: 'Forbidden call to document.write', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-document-write', - startPosition: { character: 1, line: 4 } - }, - { - failure: 'Forbidden call to document.writeln', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-document-write', - startPosition: { character: 1, line: 5 } - } - ]); - }); -}); diff --git a/src/tests/NoDuplicateCaseRuleTests.ts b/src/tests/NoDuplicateCaseRuleTests.ts deleted file mode 100644 index 668d0e76b..000000000 --- a/src/tests/NoDuplicateCaseRuleTests.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noDuplicateCaseRule', (): void => { - const ruleName: string = 'no-duplicate-case'; - - it('should pass on valid switch', (): void => { - const script: string = ` - var a = 1; - - switch (a) { - case 1: - break; - case 2: - break; - default: - break; - } `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on string duplicates', (): void => { - const script: string = ` - switch (a) { - case 1: - break; - case 1: /*error Duplicate case label.*/ - break; - case 2: - break; - default: - break; - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Duplicate case found in switch statement: 1', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-duplicate-case', - startPosition: { character: 17, line: 5 } - } - ]); - }); - - it('should fail on number duplicates', (): void => { - const script: string = ` - switch (a) { - case "1": - break; - case "1": /*error Duplicate case label.*/ - break; - case "2": - break; - default: - break; - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Duplicate case found in switch statement: "1"', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-duplicate-case', - startPosition: { character: 17, line: 5 } - } - ]); - }); - - it('should fail on identifier duplicates', (): void => { - const script: string = ` - switch (a) { - case one: - break; - case one: /*error Duplicate case label.*/ - break; - case two: - break; - default: - break; - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Duplicate case found in switch statement: one', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-duplicate-case', - startPosition: { character: 17, line: 5 } - } - ]); - }); -}); diff --git a/src/tests/NoDuplicateParameterNamesTests.ts b/src/tests/NoDuplicateParameterNamesTests.ts deleted file mode 100644 index 45f1c7d68..000000000 --- a/src/tests/NoDuplicateParameterNamesTests.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noDuplicateParameterNames', (): void => { - const RULE_NAME: string = 'no-duplicate-parameter-names'; - - it('should produce violations ', (): void => { - /* tslint:disable:max-line-length */ - const inputFile: string = ` -class NoDuplicateParameterNamesTestInput { - - /** - * The following code should have no errors: - */ - constructor() {} - - constructor(arg1) {} - - constructor(arg1, arg2) {} - - voidMethod() {} - unaryMethod(arg1) {} - bindaryMethod(arg1, arg2) {} - - private arrow0 = () => {}; - private arrow1 = (arg) => {}; - private arrow2 = (arg1, arg2) => {}; - - private arrowFunction0 = function() {}; - private arrowFunction1 = function(arg) {}; - private arrowFunction2 = function(arg1, arg2) {}; - - /** - * The following code should have errors: - */ - constructor(arg1, duplicateConstructorParameter, duplicateConstructorParameter) {} // triggers visitConstructorDeclaration - binaryMethod2(duplicateMethodParameter, duplicateMethodParameter?) {} // triggers visitMethodDeclaration - private arrowFunction3 = (duplicateArrowFunctionParameter, duplicateArrowFunctionParameter) => {}; // triggers visitArrowFunction - private function3 = function(duplicateFunctionExpParameter, duplicateFunctionExpParameter) {}; // triggers visitFunctionExpression -} - -// these declarations need to be made outside of a class -function function0() {} -function function1(arg) {} -function function2(arg1, arg2) {} -function function3(duplicateFunctionParameter, duplicateFunctionParameter) {} // triggers visitFunctionDeclaration - -`; - /* tslint:enable:max-line-length */ - TestHelper.assertViolations(RULE_NAME, inputFile, [ - { - failure: "Duplicate parameter name: 'duplicateConstructorParameter'", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-duplicate-parameter-names', - startPosition: { - line: 28, - character: 54 - } - }, - { - failure: "Duplicate parameter name: 'duplicateMethodParameter'", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-duplicate-parameter-names', - startPosition: { - line: 29, - character: 45 - } - }, - { - failure: "Duplicate parameter name: 'duplicateArrowFunctionParameter'", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-duplicate-parameter-names', - startPosition: { - line: 30, - character: 64 - } - }, - { - failure: "Duplicate parameter name: 'duplicateFunctionExpParameter'", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-duplicate-parameter-names', - startPosition: { - line: 31, - character: 65 - } - }, - { - failure: "Duplicate parameter name: 'duplicateFunctionParameter'", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-duplicate-parameter-names', - startPosition: { - line: 38, - character: 48 - } - } - ]); - }); -}); diff --git a/src/tests/NoEmptyInterfacesRuleTests.ts b/src/tests/NoEmptyInterfacesRuleTests.ts deleted file mode 100644 index fe1db886f..000000000 --- a/src/tests/NoEmptyInterfacesRuleTests.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noEmptyInterfacesRule', (): void => { - const ruleName: string = 'no-empty-interfaces'; - - it('should pass on interface with 1 attribute', (): void => { - const script: string = ` - interface MyInterface { - attribute: string; - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on interface with two different parents', (): void => { - const script: string = ` - interface MyInterface extends First, Second { - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on interface with only 1 parent (what is the point?)', (): void => { - const script: string = ` - interface MyInterface extends First { - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Do not declare empty interfaces: 'MyInterface'", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-empty-interfaces', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on empty interface', (): void => { - const script: string = ` - interface MyInterface { - // adding comments will not help you. - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Do not declare empty interfaces: 'MyInterface'", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-empty-interfaces', - startPosition: { character: 13, line: 2 } - } - ]); - }); -}); diff --git a/src/tests/NoEmptyLineAfterOpeningBraceRuleTests.ts b/src/tests/NoEmptyLineAfterOpeningBraceRuleTests.ts deleted file mode 100644 index 012c6fdd5..000000000 --- a/src/tests/NoEmptyLineAfterOpeningBraceRuleTests.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noEmptyLineAfterOpeningBraceRule', (): void => { - const ruleName: string = 'no-empty-line-after-opening-brace'; - - it('should allow a single-line block', (): void => { - const inputScript: string = 'function () { }'; - - TestHelper.assertViolations(ruleName, inputScript, []); - }); - - it('should allow a multiline block without a newline after the opening brace', (): void => { - const inputScript: string = ` - function () { - } - `; - - TestHelper.assertViolations(ruleName, inputScript, []); - }); - - it('should ban a multiline block with a newline after the opening brace', (): void => { - const inputScript: string = ` - function () { - - } - `; - - TestHelper.assertViolations(ruleName, inputScript, [ - { - failure: 'Opening brace cannot be followed by empty line', - name: Utils.absolutePath('file.ts'), - ruleName: ruleName, - startPosition: { - character: 1, - line: 3 - } - } - ]); - }); -}); diff --git a/src/tests/NoExecScriptTests.ts b/src/tests/NoExecScriptTests.ts deleted file mode 100644 index 3291d14af..000000000 --- a/src/tests/NoExecScriptTests.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noExecScriptRule', (): void => { - const RULE_NAME: string = 'no-exec-script'; - - it('should produce violations ', (): void => { - const inputFile: string = ` -execScript('alert("hello world")'); -this.execScript('alert("hello world")'); -window.execScript('alert("hello world")'); -(window).execScript('alert("hello world")'); - -var a = execScript('alert("hello world")'); -var b = this.execScript('alert("hello world")'); -var c = window.execScript('alert("hello world")'); -var d = (window).execScript('alert("hello world")'); - -`; - TestHelper.assertViolations(RULE_NAME, inputFile, [ - { - failure: 'forbidden execScript: execScript', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-exec-script', - startPosition: { - line: 2, - character: 1 - } - }, - { - failure: 'forbidden execScript: this.execScript', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-exec-script', - startPosition: { - line: 3, - character: 1 - } - }, - { - failure: 'forbidden execScript: window.execScript', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-exec-script', - startPosition: { - line: 4, - character: 1 - } - }, - { - failure: 'forbidden execScript: (window).execScript', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-exec-script', - startPosition: { - line: 5, - character: 1 - } - }, - { - failure: 'forbidden execScript: execScript', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-exec-script', - startPosition: { - line: 7, - character: 9 - } - }, - { - failure: 'forbidden execScript: this.execScript', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-exec-script', - startPosition: { - line: 8, - character: 9 - } - }, - { - failure: 'forbidden execScript: window.execScript', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-exec-script', - startPosition: { - line: 9, - character: 9 - } - }, - { - failure: 'forbidden execScript: (window).execScript', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-exec-script', - startPosition: { - line: 10, - character: 9 - } - } - ]); - }); -}); diff --git a/src/tests/NoForInRuleTests.ts b/src/tests/NoForInRuleTests.ts deleted file mode 100644 index f7538cb93..000000000 --- a/src/tests/NoForInRuleTests.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* tslint:disable:max-line-length */ - -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noForInRule', (): void => { - const ruleName: string = 'no-for-in'; - - it('should pass on a regular for statement', (): void => { - const script: string = ` - for (var i = 0; i < 100; i++) { - - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on a regular for-of statement', (): void => { - const script: string = ` - for (const item of array) { - - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on for-in statement', (): void => { - const script: string = ` - for (name in object) { - - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - "Do not use the 'for in' statement: 'for (name in object)'. If this is an object, use 'Object.keys' instead. If this is an array use a standard 'for' loop instead.", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-for-in', - startPosition: { character: 13, line: 2 } - } - ]); - }); -}); diff --git a/src/tests/NoHttpStringRuleTests.ts b/src/tests/NoHttpStringRuleTests.ts deleted file mode 100644 index ac3d56220..000000000 --- a/src/tests/NoHttpStringRuleTests.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* tslint:disable:no-http-string */ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noHttpStringRule', (): void => { - const ruleName: string = 'no-http-string'; - - it('should ban http strings in variables', (): void => { - const inputScript: string = "var x = 'http://www.examples.com'"; - TestHelper.assertViolations(ruleName, inputScript, [ - { - failure: "Forbidden http url in string: 'http://www.examples.com'", - name: Utils.absolutePath('file.ts'), - ruleName: ruleName, - startPosition: { character: 9, line: 1 } - } - ]); - }); - - it('should ban http template strings in variables', (): void => { - const inputScript: string = 'var x = `http://www.examples.com`'; - TestHelper.assertViolations(ruleName, inputScript, [ - { - failure: "Forbidden http url in string: 'http://www.examples.com'", - name: Utils.absolutePath('file.ts'), - ruleName: ruleName, - startPosition: { character: 9, line: 1 } - } - ]); - }); - - it('should ban http multipart template strings in variables', (): void => { - // tslint:disable-next-line:no-invalid-template-strings - const inputScript: string = 'var x = `http://www.${example}.com`'; - TestHelper.assertViolations(ruleName, inputScript, [ - { - failure: "Forbidden http url in string: 'http://www.'", - name: Utils.absolutePath('file.ts'), - ruleName: ruleName, - startPosition: { character: 9, line: 1 } - } - ]); - }); - - it('should ban http strings in default values', (): void => { - const inputScript: string = "function f(x : string = 'http://www.example.com/whatever') {}"; - TestHelper.assertViolations(ruleName, inputScript, [ - { - failure: "Forbidden http url in string: 'http://www.example.com/whatever'", - name: Utils.absolutePath('file.ts'), - ruleName: ruleName, - startPosition: { character: 25, line: 1 } - } - ]); - }); - - it('should allow https strings in variables', (): void => { - const inputScript: string = "var x = 'https://www.microsoft.com'"; - TestHelper.assertViolations(ruleName, inputScript, []); - }); - - it('should allow http in middle of string', (): void => { - const inputScript: string = "var x = 'The prototcol may be http:// or https://'"; - TestHelper.assertViolations(ruleName, inputScript, []); - }); - - it('should allow https strings in default values', (): void => { - const inputScript: string = "function f(x : string = 'https://www.microsoft.com') {}"; - TestHelper.assertViolations(ruleName, inputScript, []); - }); - - it('should allow http strings in that match the exclude regex', (): void => { - const inputScript: string = 'var x = "http://www.allowed.com"'; - const excludeRules = ['http://www\\.allowed\\.com/?']; - TestHelper.assertNoViolationWithOptions(ruleName, excludeRules, inputScript); - }); - - it('should disallow http strings in that do not match the exclude regex', (): void => { - const inputScript: string = 'var x = "http://www.notallowed.com"'; - const excludeRules = ['http://www\\.allowed\\.com/?']; - TestHelper.assertViolationsWithOptions(ruleName, excludeRules, inputScript, [ - { - failure: "Forbidden http url in string: 'http://www.notallowed.com'", - name: Utils.absolutePath('file.ts'), - ruleName: ruleName, - startPosition: { - character: 9, - line: 1 - } - } - ]); - }); -}); -/* tslint:enable:no-http-string */ diff --git a/src/tests/NoIncrementDecrementTests.ts b/src/tests/NoIncrementDecrementTests.ts deleted file mode 100644 index f90fd59db..000000000 --- a/src/tests/NoIncrementDecrementTests.ts +++ /dev/null @@ -1,143 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -/** - * Unit tests. - */ -describe('noIncrementDecrementRule', (): void => { - const RULE_NAME: string = 'no-increment-decrement'; - const OPTION_ALLOW_FOR_LOOPS = 'allow-for-loops'; - - it('should produce violations ', (): void => { - const inputFile: string = ` -var x; - -x++; -x--; -++x; ---x; - -`; - TestHelper.assertViolations(RULE_NAME, inputFile, [ - { - failure: 'Forbidden ++ operator', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-increment-decrement', - startPosition: { - line: 4, - character: 1 - } - }, - { - failure: 'Forbidden -- operator', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-increment-decrement', - startPosition: { - line: 5, - character: 1 - } - }, - { - failure: 'Forbidden ++ operator', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-increment-decrement', - startPosition: { - line: 6, - character: 1 - } - }, - { - failure: 'Forbidden -- operator', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-increment-decrement', - startPosition: { - line: 7, - character: 1 - } - } - ]); - }); - it('allows increments and decrements in loop incrementor clause, if allow-for-loops option is specified', (): void => { - const inputFile: string = ` -for(let x=0; x<10; x++) {} -for(let y=10; y>=0; y--) {} -`; - TestHelper.assertNoViolationWithOptions(RULE_NAME, [true, OPTION_ALLOW_FOR_LOOPS], inputFile); - TestHelper.assertViolations(RULE_NAME, inputFile, [ - { - failure: 'Forbidden ++ operator', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-increment-decrement', - startPosition: { - line: 2, - character: 20 - } - }, - { - failure: 'Forbidden -- operator', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-increment-decrement', - startPosition: { - line: 3, - character: 21 - } - } - ]); - }); - it('forbids increments and decrements in loop bodies, even with allow-for-loops', (): void => { - const inputFile: string = ` -for(let x=0; x<10; x+=1) { - x++; - x--; -} -`; - const expectedViolations: TestHelper.ExpectedFailure[] = [ - { - failure: 'Forbidden ++ operator', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-increment-decrement', - startPosition: { - line: 3, - character: 5 - } - }, - { - failure: 'Forbidden -- operator', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-increment-decrement', - startPosition: { - line: 4, - character: 5 - } - } - ]; - TestHelper.assertViolationsWithOptions(RULE_NAME, [true, OPTION_ALLOW_FOR_LOOPS], inputFile, expectedViolations); - TestHelper.assertViolations(RULE_NAME, inputFile, expectedViolations); - }); - - it('forbids increments and decrements in loop initializer and condition, even with allow-for-loops', (): void => { - const inputFile: string = `for(let x=++y; x<--y; x+=1) {}`; - const expectedViolations: TestHelper.ExpectedFailure[] = [ - { - failure: 'Forbidden ++ operator', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-increment-decrement', - startPosition: { - line: 1, - character: 11 - } - }, - { - failure: 'Forbidden -- operator', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-increment-decrement', - startPosition: { - line: 1, - character: 18 - } - } - ]; - TestHelper.assertViolationsWithOptions(RULE_NAME, [true, OPTION_ALLOW_FOR_LOOPS], inputFile, expectedViolations); - TestHelper.assertViolations(RULE_NAME, inputFile, expectedViolations); - }); -}); diff --git a/src/tests/NoInnerHtmlRuleTests.ts b/src/tests/NoInnerHtmlRuleTests.ts deleted file mode 100644 index 31b2ae27e..000000000 --- a/src/tests/NoInnerHtmlRuleTests.ts +++ /dev/null @@ -1,132 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noInnerHtmlRule', (): void => { - const ruleName: string = 'no-inner-html'; - - it('should pass on reading innerHTML strings', (): void => { - const script: string = ` - var foo = element.innerHTML; - var bar = element.outerHTML; - var baz = $(element).html(); - var quxFunction = $(element).html; - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on writing to innerHTML', (): void => { - const script: string = ` - element.innerHTML = '
'; - parent.child.innerHTML = '
'; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Writing a string to the innerHTML property is insecure: element.innerHTML = '
'", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-inner-html', - startPosition: { character: 13, line: 2 } - }, - { - failure: "Writing a string to the innerHTML property is insecure: parent.child.innerHTML = '
'", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-inner-html', - startPosition: { character: 13, line: 3 } - } - ]); - }); - - it('should fail on writing to outerHTML', (): void => { - const script: string = ` - element.outerHTML = '
'; - parent.child.outerHTML = someVariable; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Writing a string to the outerHTML property is insecure: element.outerHTML = '
'", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-inner-html', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Writing a string to the outerHTML property is insecure: parent.child.outerHTML = someVariable', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-inner-html', - startPosition: { character: 13, line: 3 } - } - ]); - }); - - it('should fail on invoking html(x)', (): void => { - const script: string = ` - $(element).html('whatever'); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Using the html() function to write a string to innerHTML is insecure: $(element).html('whatever')", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-inner-html', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should pass on non-jQuery HTML method calls', (): void => { - const script: string = ` - var myCustomObject = { - html: function (text) { - console.log('Called html with ' + text); - }, - }; - myCustomObject.html('here I am'); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - describe('with options', (): void => { - let options: [boolean, object]; - - beforeEach( - (): void => { - options = [ - true, - { - 'html-lib-matcher': 'cheerio|[j|J][q|Q]uery' - } - ]; - } - ); - - it('should fail on invoking html(x) with different jQuery matcher', (): void => { - const script: string = ` - cheerio(element).html('whatever'); - `; - - TestHelper.assertViolationsWithOptions(ruleName, options, script, [ - { - failure: "Using the html() function to write a string to innerHTML is insecure: cheerio(element).html('whatever')", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-inner-html', - startPosition: { character: 17, line: 2 } - } - ]); - }); - - it('should pass on non-jQuery HTML method calls with options', (): void => { - const script: string = ` - var myCustomObject = { - html: function (text) { - console.log('Called html with ' + text); - }, - }; - myCustomObject.html('here I am'); - `; - - TestHelper.assertViolationsWithOptions(ruleName, options, script, []); - }); - }); -}); diff --git a/src/tests/NoInvalidRegexpRuleTests.ts b/src/tests/NoInvalidRegexpRuleTests.ts deleted file mode 100644 index d174e4399..000000000 --- a/src/tests/NoInvalidRegexpRuleTests.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noInvalidRegexpRule', (): void => { - const ruleName: string = 'no-invalid-regexp'; - - it('should pass on valid input', (): void => { - const script: string = ` - var a = new RegExp('.'); // valid constructor - var b = RegExp('.'); // this is the constructor as well - var c = this.RegExp('['); // clearly not the typescript RegExp object - var d = new RegExp(whatever); // non-string literal parameter - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on invalid string in constuctor', (): void => { - const script: string = ` - new RegExp('\\\\') /*error Invalid regular expression: /\/: \ at end of pattern*/ - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Invalid regular expression: /\\/: \\ at end of pattern', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-invalid-regexp', - startPosition: { character: 24, line: 2 } - } - ]); - }); - - it('should fail on invalid string in function call', (): void => { - const script: string = ` - RegExp('[') /*error Invalid regular expression: /[/: Unterminated character class*/ - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Invalid regular expression: /[/: Unterminated character class', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-invalid-regexp', - startPosition: { character: 20, line: 2 } - } - ]); - }); -}); diff --git a/src/tests/NoJqueryRawElementsRuleTests.ts b/src/tests/NoJqueryRawElementsRuleTests.ts deleted file mode 100644 index 4f51f5520..000000000 --- a/src/tests/NoJqueryRawElementsRuleTests.ts +++ /dev/null @@ -1,154 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noJqueryRawElementsRule', (): void => { - const ruleName: string = 'no-jquery-raw-elements'; - - it('should pass on string literals that is not a tag', (): void => { - const script: string = ` - $("div"); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on simple opening tag (Issue #153)', (): void => { - const script: string = ` - const x = { - html: "
" + $("
").text(message).html() + "
" - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on simple open and close tags', (): void => { - const script: string = ` - $("
"); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on any simple content inside tags', (): void => { - const script: string = ` - $("
some simple content
"); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on any simple self closing tags', (): void => { - const script: string = ` - $("
"); - $("
"); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on tag with nested elements', (): void => { - const script: string = ` - $("

"); // nested elements are better expressed in JQuery API - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Replace complex HTML strings with jQuery API: $("

")', - name: Utils.absolutePath('file.ts'), - ruleName: ruleName, - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on tag with attributes', (): void => { - const script: string = ` - $(""); // attributes are better expressed in JQuery API - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Replace complex HTML strings with jQuery API: $("")', - name: Utils.absolutePath('file.ts'), - ruleName: ruleName, - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on tag with default attributes', (): void => { - const script: string = ` - $(""); // default attributes are better expressed in JQuery API - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Replace complex HTML strings with jQuery API: $("")', - name: Utils.absolutePath('file.ts'), - ruleName: ruleName, - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on tag string concatenation', (): void => { - const script: string = ` - $("<" + tagName + " />"); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Replace HTML string manipulation with jQuery API: $("<" + tagName + " />")', - name: Utils.absolutePath('file.ts'), - ruleName: ruleName, - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on attribute string concatenation', (): void => { - const script: string = ` - $("
"); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Replace HTML string manipulation with jQuery API: $("
")', - name: Utils.absolutePath('file.ts'), - ruleName: ruleName, - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on dynamic open tag', (): void => { - const script: string = ` - $(someTagOpening + content + '>'); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Replace HTML string manipulation with jQuery API: $(someTagOpening + content + '>')", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-jquery-raw-elements', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on dynamic close tag', (): void => { - const script: string = ` - jquery('<' + tagName + closingBits); - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Replace HTML string manipulation with jQuery API: jquery('<' + tagName + closingBits)", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-jquery-raw-elements', - startPosition: { character: 13, line: 2 } - } - ]); - }); -}); diff --git a/src/tests/NoMissingVisibilityModifiersRuleTests.ts b/src/tests/NoMissingVisibilityModifiersRuleTests.ts deleted file mode 100644 index e51602aec..000000000 --- a/src/tests/NoMissingVisibilityModifiersRuleTests.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noMissingVisibilityModifiers', (): void => { - const ruleName: string = 'no-missing-visibility-modifiers'; - - it('should allow field modifiers', (): void => { - const inputScript: string = ` -class { - private myField1; - protected myField2; - public myField3; - private static myField4; - protected static myField5; - public static myField6; -}`; - - TestHelper.assertViolations(ruleName, inputScript, []); - }); - - it('should allow method modifiers', (): void => { - const inputScript: string = ` -class { - private myMethod1() {}; - protected myMethod2() {}; - public myMethod3() {}; - private static myMethod4() {}; - protected static myMethod5() {}; - public static myMethod6() {}; -}`; - - TestHelper.assertViolations(ruleName, inputScript, []); - }); - - it('should not allow missing field modifiers', (): void => { - const inputScript: string = ` -class { - myField1; - static myField2; -}`; - - TestHelper.assertViolations(ruleName, inputScript, [ - { - failure: 'Field missing visibility modifier: myField1;', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-missing-visibility-modifiers', - startPosition: { character: 5, line: 3 } - }, - { - failure: 'Field missing visibility modifier: static myField2;', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-missing-visibility-modifiers', - startPosition: { character: 5, line: 4 } - } - ]); - }); - - it('should not allow missing method modifiers', (): void => { - const inputScript: string = ` -class { - myMethod1() { - }; - static myMethod2() {}; -}`; - - TestHelper.assertViolations(ruleName, inputScript, [ - { - failure: 'Method missing visibility modifier: myMethod1() {', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-missing-visibility-modifiers', - startPosition: { character: 5, line: 3 } - }, - { - failure: 'Method missing visibility modifier: static myMethod2() {}', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-missing-visibility-modifiers', - startPosition: { character: 5, line: 5 } - } - ]); - }); -}); diff --git a/src/tests/NoMultilineStringTests.ts b/src/tests/NoMultilineStringTests.ts deleted file mode 100644 index 06999c11d..000000000 --- a/src/tests/NoMultilineStringTests.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noMultilineStringRule', (): void => { - const RULE_NAME: string = 'no-multiline-string'; - - it('should produce violations ', (): void => { - const inputFile: string = ` - -var x = \`some - multiline - string\`;`; - TestHelper.assertViolations(RULE_NAME, inputFile, [ - { - failure: 'Forbidden Multiline string: `some...', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-multiline-string', - startPosition: { - line: 3, - character: 9 - } - } - ]); - }); -}); diff --git a/src/tests/NoMultipleVarDeclRuleTests.ts b/src/tests/NoMultipleVarDeclRuleTests.ts deleted file mode 100644 index 1d45d0643..000000000 --- a/src/tests/NoMultipleVarDeclRuleTests.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noMultipleVarDeclRule', (): void => { - const ruleName: string = 'no-multiple-var-decl'; - - it('should pass on separate var declaration and multiple var declarations within a for loop', (): void => { - const script: string = ` - var x = 1; - var y: number = 2; - var z = [3, 4]; - for (var i = x, j = y; i < j; i++) {} - `; - - TestHelper.assertNoViolation(ruleName, script); - }); - - it('should fail on multiple var declaration', (): void => { - const script: string = ` - var x = 1, - y = 2; - var x, y = 2, z; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Do not use comma separated variable declarations: x = 1,', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-multiple-var-decl', - startPosition: { character: 13, line: 2 } - }, - { - failure: 'Do not use comma separated variable declarations: x,', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-multiple-var-decl', - startPosition: { character: 13, line: 4 } - } - ]); - }); -}); diff --git a/src/tests/NoRegexSpacesRuleTests.ts b/src/tests/NoRegexSpacesRuleTests.ts deleted file mode 100644 index 959d90b7e..000000000 --- a/src/tests/NoRegexSpacesRuleTests.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noRegexSpacesRule', (): void => { - const ruleName: string = 'no-regex-spaces'; - - it('should pass on single space', (): void => { - const script: string = ` - var re = /foo {3}bar/; - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on RegExp object', (): void => { - const script: string = ` - var re = new RegExp("foo bar"); - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on no spaces', (): void => { - const script: string = ` - var re = /foobar/; - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on spaces in middle', (): void => { - const script: string = ` - var re = /foo bar/; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Spaces in regular expressions are hard to count. Use {3}', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-regex-spaces', - startPosition: { character: 22, line: 2 } - } - ]); - }); - - it('should fail on leading spaces', (): void => { - const script: string = ` - var re = / bar/; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Spaces in regular expressions are hard to count. Use {2}', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-regex-spaces', - startPosition: { character: 22, line: 2 } - } - ]); - }); - - it('should fail on trailing spaces', (): void => { - const script: string = ` - var re = /bar /; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Spaces in regular expressions are hard to count. Use {4}', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-regex-spaces', - startPosition: { character: 22, line: 2 } - } - ]); - }); -}); diff --git a/src/tests/NoStatelessClassRuleTests.ts b/src/tests/NoStatelessClassRuleTests.ts deleted file mode 100644 index d82488c98..000000000 --- a/src/tests/NoStatelessClassRuleTests.ts +++ /dev/null @@ -1,165 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noStatelessClassRule', (): void => { - const ruleName: string = 'no-stateless-class'; - - it('should pass on when class has some state', (): void => { - const script: string = ` - // classes with instance fields have state - class ClassWithField { - private field; - } - - // classes with instance methods have state - class ClassWithMethod { - private someMethod() { - } - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass when class has parent', (): void => { - const script: string = ` - class ClassWithParent extends MyOtherClass { - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass when class has parent and parent interface', (): void => { - const script: string = ` - // classes that extend others have state from parent - class ClassWithParentAndInterface implements MyInterface extends MyOtherClass { - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass when constructor declares public properties', (): void => { - const script: string = ` - class Point { - constructor(public x: number, public y: number) { } - }`; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass when constructor declares protected properties', (): void => { - const script: string = ` - class Point { - constructor(protected x: number, protected y: number) { } - }`; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass when constructor declares private properties', (): void => { - const script: string = ` - class Point { - constructor(private x: number, private y: number) { } - }`; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass when constructor declares readonly properties', (): void => { - const script: string = ` - class Point { - constructor(readonly x: number, readonly y: number) { } - }`; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on empty class', (): void => { - const script: string = ` - // empty class can be a module instead - class MyClass { - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'A stateless class was found. This indicates a failure in the object model: MyClass', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-stateless-class', - startPosition: { character: 13, line: 3 } - } - ]); - }); - - it('should fail on empty class with only a constructor', (): void => { - const script: string = ` - // empty class can be a module instead - class MyClass { - constructor() { - } - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'A stateless class was found. This indicates a failure in the object model: MyClass', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-stateless-class', - startPosition: { character: 13, line: 3 } - } - ]); - }); - - it('should fail on empty class that implements an interface', (): void => { - const script: string = ` - class MyClass implements MyInterface{ - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'A stateless class was found. This indicates a failure in the object model: MyClass', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-stateless-class', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on class with only static fields', (): void => { - const script: string = ` - class MyClass { - private static field; - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'A stateless class was found. This indicates a failure in the object model: MyClass', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-stateless-class', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should fail on class with only static methods', (): void => { - const script: string = ` - class MyClass { - private static myMethod() { - } - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'A stateless class was found. This indicates a failure in the object model: MyClass', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-stateless-class', - startPosition: { character: 13, line: 2 } - } - ]); - }); -}); diff --git a/src/tests/NoSuspiciousCommentRuleTests.ts b/src/tests/NoSuspiciousCommentRuleTests.ts deleted file mode 100644 index 0c35a7a0e..000000000 --- a/src/tests/NoSuspiciousCommentRuleTests.ts +++ /dev/null @@ -1,162 +0,0 @@ -/* tslint:disable:quotemark */ -/* tslint:disable:no-multiline-string */ - -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noSuspiciousCommentRule', (): void => { - const ruleName: string = 'no-suspicious-comment'; - const option: string[] = ['https://example.com/*']; - - it('should pass on normal comments', (): void => { - const script: string = ` - // this comment is not suspicious - `; - - TestHelper.assertViolations(ruleName, script, []); - TestHelper.assertViolationsWithOptions(ruleName, option, script, []); - }); - - it('should pass on multi-line comments', (): void => { - const script: string = ` - /** - * This comment - * is not suspicious. - */ - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on TODOlike comments', (): void => { - const script: string = ` - /** - * This comment - * is not suspicious, even if it contains the word TODOlike. - */ - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on multiline TODO comments', (): void => { - const script: string = ` - /** - * TODO: add failing example and update assertions - */ - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: 'Suspicious comment found: TODO', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-suspicious-comment', - startPosition: { character: 13, line: 2 } - } - ]); - }); - - it('should pass on multiline TODO comments with regex option', (): void => { - const script: string = ` - /** - * TODO: add failing example and update assertions - * See https://example.com/article/123 - */ - `; - - TestHelper.assertViolationsWithOptions(ruleName, option, script, []); - }); - - it('should pass on lower case todo comments without colons', (): void => { - const script: string = ` - // todo add failing example and update assertions - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - /* tslint:disable:mocha-no-side-effect-code */ - ['BUG', 'HACK', 'FIXME', 'LATER', 'LATER2', 'TODO'].forEach((suspiciousWord: string) => { - /* tslint:enable:mocha-no-side-effect-code */ - - it(`should fail on upper case ${suspiciousWord} comments without colons`, (): void => { - const script: string = ` - // ${suspiciousWord} you should fix this - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: `Suspicious comment found: ${suspiciousWord}`, - name: Utils.absolutePath('file.ts'), - ruleName: 'no-suspicious-comment', - startPosition: { character: 17, line: 2 } - } - ]); - TestHelper.assertViolationsWithOptions(ruleName, option, script, [ - { - failure: `Suspicious comment found: ${suspiciousWord}. -To disable this warning, the comment should include one of the following regex: /https:\\/\\/example.com\\/*/`, - name: Utils.absolutePath('file.ts'), - ruleName: 'no-suspicious-comment', - startPosition: { character: 17, line: 2 } - } - ]); - }); - - it(`should pass on upper case ${suspiciousWord} comments without colons and with regex option`, (): void => { - const script: string = ` - // ${suspiciousWord} you should fix this https://example.com/article/123 - `; - - TestHelper.assertViolationsWithOptions(ruleName, option, script, []); - }); - - it(`should fail on upper case ${suspiciousWord} comments with colons`, (): void => { - const script: string = ` - // ${suspiciousWord}: you should fix this - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: `Suspicious comment found: ${suspiciousWord}`, - name: Utils.absolutePath('file.ts'), - ruleName: 'no-suspicious-comment', - startPosition: { character: 17, line: 2 } - } - ]); - }); - - it(`should pass on upper case ${suspiciousWord} comments with colons and with regex option`, (): void => { - const script: string = ` - // ${suspiciousWord}: you should fix this (see https://example.com/article/123) - `; - - TestHelper.assertViolationsWithOptions(ruleName, option, script, []); - }); - - it(`should fail on lower case ${suspiciousWord} comments with colons`, (): void => { - const script: string = ` - // ${suspiciousWord}: you should fix this - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: `Suspicious comment found: ${suspiciousWord}`, - name: Utils.absolutePath('file.ts'), - ruleName: 'no-suspicious-comment', - startPosition: { character: 17, line: 2 } - } - ]); - }); - - it(`should pass on lower case ${suspiciousWord} comments with colons and with regex option`, (): void => { - const script: string = ` - // ${suspiciousWord}: you should fix this (see https://example.com/article/123) - `; - - TestHelper.assertViolationsWithOptions(ruleName, option, script, []); - }); - }); -}); -/* tslint:enable:quotemark */ -/* tslint:enable:no-multiline-string */ diff --git a/src/tests/NoTypeofUndefinedRuleTests.ts b/src/tests/NoTypeofUndefinedRuleTests.ts deleted file mode 100644 index c4faf3019..000000000 --- a/src/tests/NoTypeofUndefinedRuleTests.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noTypeofUndefinedRule', (): void => { - const ruleName: string = 'no-typeof-undefined'; - - it('should pass on normal comparisons', (): void => { - const script: string = ` - if(x === undefined) {} - if(x == undefined) {} - if(x === null) {} - if(x == null) {} - - if(x === 'undefined') {} - if(x == 'undefined') {} - - if(typeof x === 'object') {} - if(typeof x == 'object') {} - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should pass on normal comparisons - yoda style', (): void => { - const script: string = ` - if(undefined === x) {} - if(undefined == x) {} - if(null === x) {} - if(null == x) {} - - if('undefined' === x) {} - if('undefined' == x) {} - - if('object' === typeof x) {} - if('object' == typeof) {} - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('should fail on typeof strict comparison', (): void => { - const script: string = ` - if(typeof x === 'undefined') {} - if('undefined' === typeof x) {} - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Avoid typeof x === 'undefined' comparisons. Prefer x == undefined or x === undefined: typeof x === 'undefined'", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-typeof-undefined', - startPosition: { character: 16, line: 2 } - }, - { - failure: "Avoid typeof x === 'undefined' comparisons. Prefer x == undefined or x === undefined: 'undefined' === typeof x", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-typeof-undefined', - startPosition: { character: 16, line: 3 } - } - ]); - }); - - it('should fail on typeof weak comparison', (): void => { - const script: string = ` - if(typeof x == 'undefined') {} - if('undefined' == typeof x) {} - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: "Avoid typeof x === 'undefined' comparisons. Prefer x == undefined or x === undefined: typeof x == 'undefined'", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-typeof-undefined', - startPosition: { character: 16, line: 2 } - }, - { - failure: "Avoid typeof x === 'undefined' comparisons. Prefer x == undefined or x === undefined: 'undefined' == typeof x", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-typeof-undefined', - startPosition: { character: 16, line: 3 } - } - ]); - }); -}); diff --git a/src/tests/NoUnexternalizedStringsRuleTests.ts b/src/tests/NoUnexternalizedStringsRuleTests.ts deleted file mode 100644 index 2c18bcfa1..000000000 --- a/src/tests/NoUnexternalizedStringsRuleTests.ts +++ /dev/null @@ -1,173 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noUnexternalizedStringsRule', (): void => { - const ruleName: string = 'no-unexternalized-strings'; - - it('should pass on single quote', (): void => { - const script: string = ` - let str = 'Hello Worlds'; - `; - TestHelper.assertViolationsWithOptions(ruleName, [{ signatures: ['localize', 'nls.localize'], messageIndex: 1 }], script, []); - }); - - it('should pass on template expression', (): void => { - // tslint:disable-next-line:no-invalid-template-strings - const script: string = 'let str = `Hello ${var} Worlds`;'; - TestHelper.assertViolationsWithOptions(ruleName, [{ signatures: ['localize', 'nls.localize'], messageIndex: 1 }], script, []); - }); - - it('should pass on localize', (): void => { - const script: string = ` - let str = localize("key", "Hello Worlds"); - `; - TestHelper.assertViolationsWithOptions(ruleName, [{ signatures: ['localize', 'nls.localize'], messageIndex: 1 }], script, []); - }); - - it('should pass on nls.localize', (): void => { - const script: string = ` - import nls = require('nls'); - let str = nls.localize("Key", "Hello World"); - `; - TestHelper.assertViolationsWithOptions(ruleName, [{ signatures: ['localize', 'nls.localize'], messageIndex: 1 }], script, []); - }); - - it('should pass on import', (): void => { - const script: string = ` - import { localize } from "nls"; - let str = localize("Key", "Hello World"); - `; - TestHelper.assertViolationsWithOptions(ruleName, [{ signatures: ['localize', 'nls.localize'], messageIndex: 1 }], script, []); - }); - - it('should pass on import equals', (): void => { - const script: string = ` - import nls = require("nls"); - let str = nls.localize("Key", "Hello World"); - `; - TestHelper.assertViolationsWithOptions(ruleName, [{ signatures: ['localize', 'nls.localize'], messageIndex: 1 }], script, []); - }); - - it('should pass on ignores', (): void => { - const script: string = ` - var nls = require("nls"); - let str = nls.localize("Key", "Hello World"); - `; - TestHelper.assertViolationsWithOptions( - ruleName, - [{ signatures: ['localize', 'nls.localize'], messageIndex: 1, ignores: ['require'] }], - script, - [] - ); - }); - - it('should fail on my.localize', (): void => { - const script: string = ` - let str = my.localize('key', "Needs localization"); - `; - TestHelper.assertViolationsWithOptions(ruleName, [{ signatures: ['localize', 'nls.localize'], messageIndex: 1 }], script, [ - { - failure: 'Unexternalized string found: "Needs localization"', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unexternalized-strings', - startPosition: { - character: 42, - line: 2 - } - } - ]); - }); - - it('should fail on function call inside localize', (): void => { - const script: string = ` - let str = localize('key', foo("Needs localization")); - `; - TestHelper.assertViolationsWithOptions(ruleName, [{ signatures: ['localize', 'nls.localize'], messageIndex: 1 }], script, [ - { - failure: 'Unexternalized string found: "Needs localization"', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unexternalized-strings', - startPosition: { - character: 43, - line: 2 - } - } - ]); - }); - - it('should fail on method call inside localize', (): void => { - const script: string = ` - let str = localize('key', this.foo("Needs localization")); - `; - TestHelper.assertViolationsWithOptions(ruleName, [{ signatures: ['localize', 'nls.localize'], messageIndex: 1 }], script, [ - { - failure: 'Unexternalized string found: "Needs localization"', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unexternalized-strings', - startPosition: { - character: 48, - line: 2 - } - } - ]); - }); - - it('should fail on variable declaration', (): void => { - const script: string = ` - let str = "Needs localization"; - `; - TestHelper.assertViolationsWithOptions(ruleName, [{ signatures: ['localize', 'nls.localize'], messageIndex: 1 }], script, [ - { - failure: 'Unexternalized string found: "Needs localization"', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unexternalized-strings', - startPosition: { - character: 23, - line: 2 - } - } - ]); - }); - - it('should fail on function declaration', (): void => { - const script: string = ` - let str: string = undefined; - function foo() { - str = "Hello World"; - } - `; - TestHelper.assertViolationsWithOptions(ruleName, [{ signatures: ['localize', 'nls.localize'], messageIndex: 1 }], script, [ - { - failure: 'Unexternalized string found: "Hello World"', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unexternalized-strings', - startPosition: { - character: 23, - line: 4 - } - } - ]); - }); - - it('should fail on binary expression', (): void => { - const script: string = ` - localize('key', "Hello " + "World"); - `; - TestHelper.assertViolationsWithOptions(ruleName, [{ signatures: ['localize', 'nls.localize'], messageIndex: 1 }], script, [ - { - failure: "Message argument to 'localize' must be a string literal.", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unexternalized-strings', - ruleSeverity: 'ERROR', - startPosition: { character: 29, line: 2 } - }, - { - failure: "Message argument to 'localize' must be a string literal.", - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unexternalized-strings', - ruleSeverity: 'ERROR', - startPosition: { character: 40, line: 2 } - } - ]); - }); -}); diff --git a/src/tests/NoUnsupportedBrowserCodeRuleTests.ts b/src/tests/NoUnsupportedBrowserCodeRuleTests.ts deleted file mode 100644 index f856deeb9..000000000 --- a/src/tests/NoUnsupportedBrowserCodeRuleTests.ts +++ /dev/null @@ -1,184 +0,0 @@ -/* tslint:disable:max-func-body-length */ - -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('noUnsupportedBrowserCodeRule', (): void => { - const ruleName: string = 'no-unsupported-browser-code'; - const options = [true, ['Mobile IE 10', 'IE >= 10', 'Chrome > 45', 'Firefox', 'Mobile Safari < 10']]; - - it('should pass on matching supported browsers', (): void => { - const script: string = ` - class Test { - // Browser Specific: Chrome 49 - sayHey() { - console.log('hey'); - } - - // browser specific: IE 10 - sayHello() { - console.log('hello'); - } - - /** - * Says hi - * - * @browserspecific Firefox 48 - */ - sayHi() { - console.log('hi'); - } - - // Browser specific: firefox - sayBye() { - console.log('bye'); - } - - /** - * goes boom - * - * @browserspecific mobile safari 9 - * @browserspecific IE 10 - */ - goBoom() { - throw new Error('boom'); - } - - /** - * goes vroom - * - * @browserspecific mobile ie 10 - */ - goVroom() { - console.log('vroom'); - } - } - `; - - TestHelper.assertNoViolationWithOptions(ruleName, options, script); - }); - - it('should fail on matching unsupported browsers', (): void => { - const script: string = ` - class Test { - // Browser Specific: Netscape 2 - sayHey() { - console.log('hey'); - } - - // browser specific: Chrome - sayHello() { - console.log('hello'); - } - - /** - * @browserspecific IE 8 - */ - sayHi() { - console.log('hi'); - } - - // Browser specific: aquaman - sayBye() { - console.log('bye'); - } - - /** - * goes boom - * - * @browserspecific mobile safari 10 - * @browserspecific IE 8 - * @browserspecific IE - */ - goBoom() { - throw new Error('boom'); - } - - /** - * goes vroom - * - * @browserspecific mobile ie 9 - */ - goVroom() { - console.log('vroom'); - } - } - `; - - TestHelper.assertViolationsWithOptions(ruleName, options, script, [ - { - failure: 'Unsupported browser: Netscape', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unsupported-browser-code', - startPosition: { - character: 17, - line: 3 - } - }, - { - failure: 'Unsupported browser version: Chrome unspecified version', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unsupported-browser-code', - startPosition: { - character: 17, - line: 8 - } - }, - { - failure: 'Unsupported browser version: IE 8', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unsupported-browser-code', - startPosition: { - character: 17, - line: 13 - } - }, - { - failure: 'Unsupported browser: aquaman', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unsupported-browser-code', - startPosition: { - character: 17, - line: 20 - } - }, - { - failure: 'Unsupported browser version: mobile safari 10', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unsupported-browser-code', - startPosition: { - character: 17, - line: 25 - } - }, - { - failure: 'Unsupported browser version: IE 8', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unsupported-browser-code', - startPosition: { - character: 17, - line: 25 - } - }, - { - failure: 'Unsupported browser version: IE unspecified version', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unsupported-browser-code', - startPosition: { - character: 17, - line: 25 - } - }, - { - failure: 'Unsupported browser version: mobile ie 9', - name: Utils.absolutePath('file.ts'), - ruleName: 'no-unsupported-browser-code', - startPosition: { - character: 17, - line: 36 - } - } - ]); - }); -}); -/* tslint:enable:max-func-body-length */ diff --git a/src/tests/jqueryDeferredMustCompleteRuleTests.ts b/src/tests/jqueryDeferredMustCompleteRuleTests.ts deleted file mode 100644 index ab434d5aa..000000000 --- a/src/tests/jqueryDeferredMustCompleteRuleTests.ts +++ /dev/null @@ -1,420 +0,0 @@ -import { Utils } from '../utils/Utils'; -import { TestHelper } from './TestHelper'; - -describe('jquery-deferred-must-complete', (): void => { - const ruleName: string = 'jquery-deferred-must-complete'; - - describe('should pass', (): void => { - it('when deferred named jquery completes', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - if (something) { - deferred.resolve(); - } else { - if (somethingElse) { - deferred.resolve(); - } else { - deferred.reject(); - } - } - return deferred.promise(); - }`; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('when deferred named jquery completes - let declaration', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - let deferred: JQueryDeferred = jquery.Deferred(); - if (something) { - deferred.resolve(); - } else { - if (somethingElse) { - deferred.resolve(); - } else { - deferred.reject(); - } - } - return deferred.promise(); - }`; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('when deferred named $ completes', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = $.Deferred(); - if (something) { - deferred.resolve(); - } else { - if (somethingElse) { - deferred.resolve(); - } else { - deferred.reject(); - } - } - return deferred.promise(); - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('on resolve', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = $.Deferred(); - deferred.resolve(); - return deferred.promise(); - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('on reject', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = $.Deferred(); - deferred.reject(); - return deferred.promise(); - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('when single branch is completed - with if-statement', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - if (something) { - deferred.resolve(); - } - return deferred.promise(); - } - `; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('when single branch is completed - with if-else-statement', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - if (something) { - deferred.resolve(); - } else { - deferred.resolve(); - } - return deferred.promise(); - }`; - - TestHelper.assertViolations(ruleName, script, []); - }); - - it('when single branch is completed - with if-else-statement', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - if (something) { - if (somethingElse) { - deferred.resolve(); - } else { - deferred.reject(); - } - } else { - if (somethingElse) { - deferred.resolve(); - } else { - deferred.reject(); - } - } - return deferred.promise(); - }`; - TestHelper.assertViolations(ruleName, script, []); - }); - - it('with nested if-else statement', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - if (something) { - if (somethingElse) { - deferred.resolve(); - } else { - deferred.reject(); - } - } else { - if (somethingElse) { - deferred.somethingElse(); - } else { - deferred.reject(); - } - deferred.reject(); // branches are not even analyzed when main thread resolves - } - return deferred.promise(); - }`; - TestHelper.assertViolations(ruleName, script, []); - }); - - it('when resolved within a function', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - someCall(function () { - deferred.resolve(); - }); - return deferred.promise(); - }`; - TestHelper.assertViolations(ruleName, script, []); - }); - - it('when resolved within a lambda', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - someCall(() => { - deferred.resolve(); - }); - return deferred.promise(); - }`; - TestHelper.assertViolations(ruleName, script, []); - }); - - it('when resolved within a function', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - someCall(function (someParm) { - deferred.resolve(); - }); - return deferred.promise(); - }`; - TestHelper.assertViolations(ruleName, script, []); - }); - - it('when resolved within a lambda', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - someCall((someParm) => { // this parameter actually shadows the one in the enclosing scope - deferred.resolve(); - }); - return deferred.promise(); - }`; - TestHelper.assertViolations(ruleName, script, []); - }); - - it('when resolved within a for loop', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - for(var x = 0; x < something.length; x++) { - deferred.resolve(); - } - return deferred.promise(); - }`; - TestHelper.assertViolations(ruleName, script, []); - }); - - it('when resolved within a for in loop', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - for(var x in something) { - deferred.resolve(); - } - return deferred.promise(); - }`; - TestHelper.assertViolations(ruleName, script, []); - }); - - it('when resolved within a while loop', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - while (something) { - deferred.resolve(); - } - return deferred.promise(); - }`; - TestHelper.assertViolations(ruleName, script, []); - }); - - it('when deferred reference escaped into a function call', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - doSomething(deferred); // reference escapes and we assume it resolves - return deferred.promise(); - }`; - TestHelper.assertViolations(ruleName, script, []); - }); - }); - - describe('should fail', (): void => { - it('when has no complete', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = $.Deferred(); - return deferred.promise(); - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'A JQuery deferred was found that appears to not have resolve or reject invoked on all code paths: ' + - "'deferred: JQueryDeferred = $.Deferred()'", - name: Utils.absolutePath('file.ts'), - ruleName: 'jquery-deferred-must-complete', - startPosition: { character: 21, line: 3 } - } - ]); - }); - - it('when has no complete - var declared on two lines', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred; - deferred = $.Deferred(); - return deferred.promise(); - } - `; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'A JQuery deferred was found that appears to not have resolve or reject invoked on all code paths: ' + - "'deferred = $.Deferred()'", - name: Utils.absolutePath('file.ts'), - ruleName: 'jquery-deferred-must-complete', - startPosition: { character: 17, line: 4 } - } - ]); - }); - - it('when single branch is missing complete - with if-statement', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - if (something) { - deferred.someOtherFunction(); - } - return deferred.promise(); - }`; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'A JQuery deferred was found that appears to not have resolve or reject invoked on all code paths: ' + - "'deferred: JQueryDeferred = jquery.Deferred()'", - name: Utils.absolutePath('file.ts'), - ruleName: 'jquery-deferred-must-complete', - startPosition: { character: 21, line: 3 } - } - ]); - }); - - it('when single branch is missing complete - with if-else-statement', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - if (something) { - deferred.resolve(); - } else { - deferred.someOtherFunction() - } - return deferred.promise(); - }`; - - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'A JQuery deferred was found that appears to not have resolve or reject invoked on all code paths: ' + - "'deferred: JQueryDeferred = jquery.Deferred()'", - name: Utils.absolutePath('file.ts'), - ruleName: 'jquery-deferred-must-complete', - startPosition: { character: 21, line: 3 } - } - ]); - }); - - it('with nested if-else statement', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - let deferred: JQueryDeferred = jquery.Deferred(); - if (something) { - if (somethingElse) { - deferred.resolve(); - } else { - deferred.reject(); - } - } else { - if (somethingElse) { - deferred.somethingElse(); - } else { - deferred.reject(); - } - } - return deferred.promise(); - }`; - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'A JQuery deferred was found that appears to not have resolve or reject invoked on all code paths: ' + - "'deferred: JQueryDeferred = jquery.Deferred()'", - name: Utils.absolutePath('file.ts'), - ruleName: 'jquery-deferred-must-complete', - startPosition: { character: 21, line: 3 } - } - ]); - }); - - it('when shadowed parameter resolved within a function', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - someCall(function (deferred) { // this parameter actually shadows the one in the enclosing scope - deferred.resolve(); - }); - return deferred.promise(); - }`; - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'A JQuery deferred was found that appears to not have resolve or reject invoked on all code paths: ' + - "'deferred: JQueryDeferred = jquery.Deferred()'", - name: Utils.absolutePath('file.ts'), - ruleName: 'jquery-deferred-must-complete', - startPosition: { character: 21, line: 3 } - } - ]); - }); - - it('when shadowed parameter resolved within a lambda', (): void => { - const script: string = ` - function myMethod() : JQueryPromise { - var deferred: JQueryDeferred = jquery.Deferred(); - someCall((arg1, deferred) => { // this parameter actually shadows the one in the enclosing scope - deferred.resolve(); - }); - return deferred.promise(); - }`; - TestHelper.assertViolations(ruleName, script, [ - { - failure: - 'A JQuery deferred was found that appears to not have resolve or reject invoked on all code paths: ' + - "'deferred: JQueryDeferred = jquery.Deferred()'", - name: Utils.absolutePath('file.ts'), - ruleName: 'jquery-deferred-must-complete', - startPosition: { character: 21, line: 3 } - } - ]); - }); - }); -}); diff --git a/tests/chai-prefer-contains-to-index-of/test.ts.lint b/tests/chai-prefer-contains-to-index-of/test.ts.lint new file mode 100644 index 000000000..ccffcde6e --- /dev/null +++ b/tests/chai-prefer-contains-to-index-of/test.ts.lint @@ -0,0 +1,24 @@ +import * as chai from "chai"; +const { expect } = chai; + +const targetUrl = "..."; + +expect(targetUrl).to.contain(twitterAuthUrl, '...'); +chai.expect(targetUrl).to.contain(twitterAuthUrl, '...'); + +expect(targetUrl).to.not.contain(twitterAuthUrl,'...'); +chai.expect(targetUrl).to.not.contain(twitterAuthUrl,'...'); + +expect(targetUrl.indexOf(twitterAuthUrl)).to.equal(-1,'...'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +chai.expect(targetUrl.indexOf(twitterAuthUrl)).to.equal(-1,'...'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +expect(targetUrl.indexOf(twitterAuthUrl)).not.to.equal(-1,'...'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +chai.expect(targetUrl.indexOf(twitterAuthUrl)).not.to.equal(-1,'...'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +[0]: Found chai call with indexOf that can be converted to .contain assertion. diff --git a/tests/chai-prefer-contains-to-index-of/tslint.json b/tests/chai-prefer-contains-to-index-of/tslint.json new file mode 100644 index 000000000..7e2fd5d65 --- /dev/null +++ b/tests/chai-prefer-contains-to-index-of/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "chai-prefer-contains-to-index-of": true + } +} diff --git a/tests/chai-vague-errors/test.ts.lint b/tests/chai-vague-errors/test.ts.lint new file mode 100644 index 000000000..d5511875f --- /dev/null +++ b/tests/chai-vague-errors/test.ts.lint @@ -0,0 +1,95 @@ +import * as chai from "chai"; +const { expect } = chai; + +const something: any = ""; + +expect(something).to.equal(true, 'message'); +expect(something).to.be.equal(false, 'message'); +expect(something).to.not.equal(null, 'message'); +expect(something).to.not.be.equal(undefined, 'message'); + +expect(something, 'message').to.be.true; +expect(something, 'message').to.be.false; +expect(something, 'message').to.not.be.null; +expect(something, 'message').to.not.be.undefined; + +expect(something).to.ok; +~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +chai.expect(something).to.ok; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.be.ok; +~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +chai.expect(something).to.not.be.ok; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] + +expect(something).to.true; +~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +chai.expect(something).to.be.true; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.not.be.true; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] + +expect(something).to.false; +~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.be.false; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.not.be.false; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] + +expect(something).to.null; +~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.be.null; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.not.be.null; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] + +expect(something).to.undefined; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.be.undefined; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.not.be.undefined; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] + +expect(something).to.equal(true); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.equals(true); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.be.equal(true); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.be.equals(true); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.not.be.equal(false); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.deep.equal(null); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.not.equal(undefined); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] + +expect(something).to.eql(true); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.be.eql(true); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +chai.expect(something).to.not.be.eql(false); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +expect(something).to.deep.eql(null); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] +chai.expect(something).to.not.eql(undefined); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [explicit] + +expect(something === undefined).to.equal(true, 'something should not have been set'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [equality] +chai.expect(something === undefined).to.equal(true, 'something should not have been set'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [equality] +expect(something !== undefined).to.equal(false, 'something should not have been set'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [inequality] +chai.expect(something !== undefined).to.equal(false, 'something should not have been set'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [inequality] + +expect(something === undefined).to.equal(false, 'something should not have been set'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [equality] +expect(something !== undefined).to.equal(true, 'something should not have been set'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [inequality] + +[explicit]: Found chai call with vague failure message. Please add an explicit failure message +[equality]: Found chai call with vague failure message. Move the strict equality comparison from the expect call into the assertion value +[inequality]: Found chai call with vague failure message. Move the strict inequality comparison from the expect call into the assertion value diff --git a/tests/chai-vague-errors/tslint.json b/tests/chai-vague-errors/tslint.json new file mode 100644 index 000000000..bb20770fd --- /dev/null +++ b/tests/chai-vague-errors/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "chai-vague-errors": true + } +} diff --git a/tests/function-name/default/test.ts.lint b/tests/function-name/default/test.ts.lint new file mode 100644 index 000000000..322f7a5b2 --- /dev/null +++ b/tests/function-name/default/test.ts.lint @@ -0,0 +1,88 @@ +function fooGood() {} +class MyClassGood { + foo() {} + foo1() {} + myFoo() {} + myFoo1() {} + + private bar() {} + private bar1() {} + private myBar() {} + private myBar1() {} +} + +class MyClassGoodStatic { + static FOO() {} + static FOO_BAR() {} + static FOO_2() {} + static FO__O() {} +} + +class MyClassSymbols { + static [Symbol.staticDefault](): any {} + public static [Symbol.staticPublic](): any {} + protected static [Symbol.staticProtected](): any {} + private static [Symbol.staticPrivate](): any {} + + static [Symbol.methodDefault](): any {} + public static [Symbol.methodPublic](): any {} + protected static [Symbol.methodProtected](): any {} + private static [Symbol.methodPrivate](): any {} +} + +const objLiteralSymbols = { + [Symbol.toStringTag](): string => "hello world" +} + +class MyClassPublic { + Foo() {} + ~~~ [public % ('Foo')] + _foo() {} + ~~~~ [public % ('_foo')] + FOO() {} + ~~~ [public % ('FOO')] + _FOO() {} + ~~~~ [public % ('_FOO')] + _foo() {} + ~~~~ [public % ('_foo')] +} + +class MyClassPrivate { + private Foo() {} + ~~~ [private % ('Foo')] + private _foo() {} + ~~~~ [private % ('_foo')] + private FOO() {} + ~~~ [private % ('FOO)] + private _FOO() {} + ~~~~ [private % ('_FOO')] + private _foo() {} + ~~~~ [private % ('_foo')] +} + +class MyClassProtected { + protected Foo() {} + ~~~ [protected % ('Foo')] + protected _foo() {} + ~~~~ [protected % ('_foo')] + protected FOO() {} + ~~~ [protected % ('FOO')] + protected _FOO() {} + ~~~~ [protected % ('_FOO')] + protected _foo() {} + ~~~~ [protected % ('_foo')] +} + +class MyClassBad { + static Foo() {} + ~~~ [static % ('Foo')] + static _foo() {} + ~~~~ [static % ('_foo')] + static _foo2() {} + ~~~~~ [static % ('_foo2')] +} + +[public]: Method name does not match /^[a-z][\w\d]+$/: %s +[private]: Private method name does not match /^[a-z][\w\d]+$/: %s +[protected]: Protected method name does not match /^[a-z][\w\d]+$/: %s +[static]: Static method name does not match /^[A-Z_\d]+$/: %s diff --git a/tests/function-name/default/tslint.json b/tests/function-name/default/tslint.json new file mode 100644 index 000000000..b8f4b317f --- /dev/null +++ b/tests/function-name/default/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "function-name": true + } +} diff --git a/tests/function-name/names/test.ts.lint b/tests/function-name/names/test.ts.lint new file mode 100644 index 000000000..d4532e882 --- /dev/null +++ b/tests/function-name/names/test.ts.lint @@ -0,0 +1,17 @@ +function myFunction() {} +class MyClass { + myMethod() {} + private myPrivateMethod() {} + static myStaticMethod() {} +} + +function notMyFunction() {} + ~~~~~~~~~~~~~ [Function name does not match /^myFunction$/: notMyFunction] +class NotMyClass { + notMyMethod() {} + ~~~~~~~~~~~ [Method name does not match /^myMethod$/: notMyMethod] + private notMyPrivateMethod() {} + ~~~~~~~~~~~~~~~~~~ [Private method name does not match /^myPrivateMethod$/: notMyPrivateMethod] + static notMyStaticMethod() {} + ~~~~~~~~~~~~~~~~~ [Static method name does not match /^myStaticMethod$/: notMyStaticMethod] +} diff --git a/tests/function-name/names/tslint.json b/tests/function-name/names/tslint.json new file mode 100644 index 000000000..6519cfa00 --- /dev/null +++ b/tests/function-name/names/tslint.json @@ -0,0 +1,13 @@ +{ + "rules": { + "function-name": [ + true, + { + "method-regex": "^myMethod$", + "private-method-regex": "^myPrivateMethod$", + "static-method-regex": "^myStaticMethod$", + "function-regex": "^myFunction$" + } + ] + } +} diff --git a/tests/function-name/validate-private-statics-as-either/test.ts.lint b/tests/function-name/validate-private-statics-as-either/test.ts.lint new file mode 100644 index 000000000..9d2196c73 --- /dev/null +++ b/tests/function-name/validate-private-statics-as-either/test.ts.lint @@ -0,0 +1,17 @@ +class MyClass { + private static bar() {} + private static bar1() {} + private static BAR() {} + ~~~ [private % ('BAR')] + private static BAR_1() {} + ~~~~~ [private % ('BAR_1')] + protected static myBar() {} + protected static myBar1() {} + protected static MY_BAR() {} + ~~~~~~ [protected % ('MY_BAR')] + protected static MY_BAR_1() {} + ~~~~~~~~ [protected % ('MY_BAR_1')] +} + +[private]: Private method name does not match /^[a-z][\w\d]+$/: %s +[protected]: Protected method name does not match /^[a-z][\w\d]+$/: %s diff --git a/tests/function-name/validate-private-statics-as-either/tslint.json b/tests/function-name/validate-private-statics-as-either/tslint.json new file mode 100644 index 000000000..6afb4c4f2 --- /dev/null +++ b/tests/function-name/validate-private-statics-as-either/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "function-name": [true, "validate-private-statics-as-either"] + } +} diff --git a/tests/function-name/validate-private-statics-as-private/test.ts.lint b/tests/function-name/validate-private-statics-as-private/test.ts.lint new file mode 100644 index 000000000..6b0abc051 --- /dev/null +++ b/tests/function-name/validate-private-statics-as-private/test.ts.lint @@ -0,0 +1,13 @@ +class MyClass { + private static bar() {} + private static bar1() {} + private static myBar() {} + private static myBar1() {} +} + +class MyClass { + protected static bar() {} + protected static bar1() {} + protected static myBar() {} + protected static myBar1() {} +} diff --git a/tests/function-name/validate-private-statics-as-private/tslint.json b/tests/function-name/validate-private-statics-as-private/tslint.json new file mode 100644 index 000000000..d0ae65500 --- /dev/null +++ b/tests/function-name/validate-private-statics-as-private/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "function-name": [true, "validate-private-statics-as-private"] + } +} diff --git a/tests/function-name/validate-private-statics-as-static/test.ts.lint b/tests/function-name/validate-private-statics-as-static/test.ts.lint new file mode 100644 index 000000000..18f332c6d --- /dev/null +++ b/tests/function-name/validate-private-statics-as-static/test.ts.lint @@ -0,0 +1,24 @@ +class MyClassPrivate { + private static BAR() {} + ~~~ [private % ('BAR')] + private static BAR_1() {} + ~~~~~ [private % ('BAR_1')] + private static MY_BAR() {} + ~~~~~~ [private % ('MY_BAR')] + private static MY_BAR_1() {} + ~~~~~~~~ [private % ('MY_BAR_1')] +} + +class MyClassProtected { + protected static BAR() {} + ~~~ [protected % ('BAR')] + protected static BAR_1() {} + ~~~~~ [protected % ('BAR_1')] + protected static MY_BAR() {} + ~~~~~~ [protected % ('MY_BAR')] + protected static MY_BAR_1() {} + ~~~~~~~~ [protected % ('MY_BAR_1')] +} + +[private]: Private method name does not match /^[a-z][\w\d]+$/: %s +[protected]: Protected method name does not match /^[a-z][\w\d]+$/: %s diff --git a/tests/function-name/validate-private-statics-as-static/tslint.json b/tests/function-name/validate-private-statics-as-static/tslint.json new file mode 100644 index 000000000..43ba333c7 --- /dev/null +++ b/tests/function-name/validate-private-statics-as-static/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "function-name": [true, "validate-private-statics-as-static"] + } +} diff --git a/tests/import-name/default/test.ts.fix b/tests/import-name/default/test.ts.fix new file mode 100644 index 000000000..77be1e4b0 --- /dev/null +++ b/tests/import-name/default/test.ts.fix @@ -0,0 +1,32 @@ +import App = require('App'); +import App = require('x/y/z/App'); + +import App from 'App'; +import App from 'x/y/z/App'; +import graphqlTag from 'graphql-tag' + +import DependencyManager = DM.DependencyManager; + +import App = require('App'); +import App = require('x/y/z/App'); + +import App from 'App'; +import App from 'x/y/z/App'; + +import DependencyManager = DM.DependencyManager; + +import userSettingsDetailView from "./user-settings.detail_view"; + +import AnyName = require('.'); +import AnyName = require('..'); +import AnyName = require('./'); +import AnyName = require('../'); +import AnyName = require('../path/./..'); +import AnyName = require('../../..'); + +import AnyName from '.'; +import AnyName from '..'; +import AnyName from './'; +import AnyName from '../'; +import AnyName from '../path/./..'; +import AnyName from '../../..'; diff --git a/tests/import-name/default/test.ts.lint b/tests/import-name/default/test.ts.lint new file mode 100644 index 000000000..903ebfa63 --- /dev/null +++ b/tests/import-name/default/test.ts.lint @@ -0,0 +1,38 @@ +import App = require('App'); +import App = require('x/y/z/App'); + +import App from 'App'; +import App from 'x/y/z/App'; +import graphqlTag from 'graphql-tag' + +import DependencyManager = DM.DependencyManager; + +import MyCoolApp = require('App'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Misnamed import. Import should be named 'App' but found 'MyCoolApp'] +import MyCoolApp2 = require('x/y/z/App'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Misnamed import. Import should be named 'App' but found 'MyCoolApp2'] + +import MyCoolApp from 'App'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Misnamed import. Import should be named 'App' but found 'MyCoolApp'] +import MyCoolApp2 from 'x/y/z/App'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Misnamed import. Import should be named 'App' but found 'MyCoolApp2'] + +import Service = DM.DependencyManager; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Misnamed import. Import should be named 'DependencyManager' but found 'Service'] + +import UserSettings from "./user-settings.detail_view"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Misnamed import. Import should be named 'userSettingsDetailView' but found 'UserSettings'] + +import AnyName = require('.'); +import AnyName = require('..'); +import AnyName = require('./'); +import AnyName = require('../'); +import AnyName = require('../path/./..'); +import AnyName = require('../../..'); + +import AnyName from '.'; +import AnyName from '..'; +import AnyName from './'; +import AnyName from '../'; +import AnyName from '../path/./..'; +import AnyName from '../../..'; diff --git a/tests/import-name/default/tslint.json b/tests/import-name/default/tslint.json new file mode 100644 index 000000000..76c0298f3 --- /dev/null +++ b/tests/import-name/default/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "import-name": [true] + } +} diff --git a/tests/import-name/ignored-list-fail/test.ts.lint b/tests/import-name/ignored-list-fail/test.ts.lint new file mode 100644 index 000000000..8ec11c20d --- /dev/null +++ b/tests/import-name/ignored-list-fail/test.ts.lint @@ -0,0 +1,7 @@ +import pkg from "fs/package-name"; +import abc from "abc-tag"; +import pqr from "my-module" +import what from "what-module" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Misnamed import. Import should be named 'whatModule' but found 'what'] +import Up from "up-module"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Misnamed import. Import should be named 'upModule' but found 'Up'] diff --git a/tests/import-name/ignored-list-fail/tslint.json b/tests/import-name/ignored-list-fail/tslint.json new file mode 100644 index 000000000..71a1fb5ea --- /dev/null +++ b/tests/import-name/ignored-list-fail/tslint.json @@ -0,0 +1,14 @@ +{ + "rules": { + "import-name": [ + true, + {}, + { + "fs/package-name": "pkg", + "abc-tag": "abc", + "myModule": "pqr" + }, + [123, { "whatever": "object" }] + ] + } +} diff --git a/tests/import-name/ignored-list-pass/test.ts.lint b/tests/import-name/ignored-list-pass/test.ts.lint new file mode 100644 index 000000000..794369200 --- /dev/null +++ b/tests/import-name/ignored-list-pass/test.ts.lint @@ -0,0 +1,5 @@ +import pkg from 'fs/package-name', +import abc from 'abc-tag', +import pqr from 'my-module' +import what from 'what-module' +import Up from 'up-module' diff --git a/tests/import-name/ignored-list-pass/tslint.json b/tests/import-name/ignored-list-pass/tslint.json new file mode 100644 index 000000000..0caa77efe --- /dev/null +++ b/tests/import-name/ignored-list-pass/tslint.json @@ -0,0 +1,14 @@ +{ + "rules": { + "import-name": [ + true, + {}, + { + "fs/package-name": "pkg", + "abc-tag": "abc", + "myModule": "pqr" + }, + ["what-module", "up-module"] + ] + } +} diff --git a/tests/import-name/replacements-es6/test.ts.lint b/tests/import-name/replacements-es6/test.ts.lint new file mode 100644 index 000000000..5ee09e55b --- /dev/null +++ b/tests/import-name/replacements-es6/test.ts.lint @@ -0,0 +1,3 @@ +import pkg from 'fs/package-name'; +import abc from 'abc-tag'; +import pqr from 'my-module'; diff --git a/tests/import-name/replacements-es6/tslint.json b/tests/import-name/replacements-es6/tslint.json new file mode 100644 index 000000000..57e5613dd --- /dev/null +++ b/tests/import-name/replacements-es6/tslint.json @@ -0,0 +1,13 @@ +{ + "rules": { + "import-name": [ + true, + {}, + { + "fs/package-name": "pkg", + "abc-tag": "abc", + "myModule": "pqr" + } + ] + } +} diff --git a/tests/import-name/replacements/test.ts.lint b/tests/import-name/replacements/test.ts.lint new file mode 100644 index 000000000..00cd34aa4 --- /dev/null +++ b/tests/import-name/replacements/test.ts.lint @@ -0,0 +1,4 @@ +import Backbone = require('backbone'); +import React = require('react'); +import isPlainObject from 'is-plain-object'; +import baseChartOptions = require('common/component/chart/options/BaseChartOptions'); diff --git a/tests/import-name/replacements/tslint.json b/tests/import-name/replacements/tslint.json new file mode 100644 index 000000000..7ce2caaf9 --- /dev/null +++ b/tests/import-name/replacements/tslint.json @@ -0,0 +1,14 @@ +{ + "rules": { + "import-name": [ + true, + {}, + { + "backbone": "Backbone", + "react": "React", + "is-plain-object": "isPlainObject", + "BaseChartOptions": "baseChartOptions" + } + ] + } +} diff --git a/tests/informative-docs/aliases/test.ts.lint b/tests/informative-docs/aliases/test.ts.lint new file mode 100644 index 000000000..5fa3db047 --- /dev/null +++ b/tests/informative-docs/aliases/test.ts.lint @@ -0,0 +1,7 @@ +/** + * The FancyFoo. + */ +function foo() {} +~~~~~~~~~~~~~~~~~ [0] + +[0]: This comment is roughly the same as the object's name. Either be more informative or don't include a comment. diff --git a/tests/informative-docs/aliases/tslint.json b/tests/informative-docs/aliases/tslint.json new file mode 100644 index 000000000..8d918b635 --- /dev/null +++ b/tests/informative-docs/aliases/tslint.json @@ -0,0 +1,12 @@ +{ + "rules": { + "informative-docs": [ + true, + { + "aliases": { + "foo": ["FancyFoo"] + } + } + ] + } +} diff --git a/tests/informative-docs/default/test.ts.lint b/tests/informative-docs/default/test.ts.lint new file mode 100644 index 000000000..02a8d06b9 --- /dev/null +++ b/tests/informative-docs/default/test.ts.lint @@ -0,0 +1,86 @@ +/** + * Does X Y Z work. + */ +function foo() { } + +/** + * Transforms the processed data. + */ +function bar() { } + +/** + * Transforms the processed baz data. + */ +function bazProcessor() { } + +function fooNoComments() { } + +/** + * Foo class + */ +class FooClass { +~~~~~~~~~~~~~~~~ + /** +~~~~~~~ + * the foo method declaration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ +~~~~~~~ + fooMethodDeclaration() { } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + /** +~~~~~~~ + * The foo property declaration. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ +~~~~~~~ + public fooPropertyDeclaration; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] +} +~ [0] + +/** + * the Foo enum. + */ +enum FooEnum { } +~~~~~~~~~~~~~~~~ [0] + +/** + * The foo function + */ +function fooFunction() { } +~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +const _ = { + /** + * The foo get accessor. + */ + get fooGetAccessor() { + ~~~~~~~~~~~~~~~~~~~~~~ + return 0; +~~~~~~~~~~~~~~~~~ + } +~~~~~ [0] +}; + +/** + * The foo interface. + */ +interface IFooInterface { } +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +/** + * The foo module. + */ +module FooModule { } +~~~~~~~~~~~~~~~~~~~~ [0] + +/** + * The foo type. + */ +type fooType = {}; +~~~~~~~~~~~~~~~~~~ [0] + +[0]: This comment is roughly the same as the object's name. Either be more informative or don't include a comment. diff --git a/tests/informative-docs/default/tslint.json b/tests/informative-docs/default/tslint.json new file mode 100644 index 000000000..bcb85fffe --- /dev/null +++ b/tests/informative-docs/default/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "informative-docs": true + } +} diff --git a/tests/informative-docs/uesless-words/test.ts.lint b/tests/informative-docs/uesless-words/test.ts.lint new file mode 100644 index 000000000..730c753e8 --- /dev/null +++ b/tests/informative-docs/uesless-words/test.ts.lint @@ -0,0 +1,7 @@ +/** + * Also foo. + */ +function foo() {} +~~~~~~~~~~~~~~~~~ [0] + +[0]: This comment is roughly the same as the object's name. Either be more informative or don't include a comment. diff --git a/tests/informative-docs/uesless-words/tslint.json b/tests/informative-docs/uesless-words/tslint.json new file mode 100644 index 000000000..3d5856dd2 --- /dev/null +++ b/tests/informative-docs/uesless-words/tslint.json @@ -0,0 +1,10 @@ +{ + "rules": { + "informative-docs": [ + true, + { + "uselessWords": ["also"] + } + ] + } +} diff --git a/tests/insecure-random/test.ts.lint b/tests/insecure-random/test.ts.lint new file mode 100644 index 000000000..7f6025fac --- /dev/null +++ b/tests/insecure-random/test.ts.lint @@ -0,0 +1,19 @@ +import crypto = require('crypto') +Math.abs(x) +crypto.randomBytes(2) +window.crypto.getRandomValues() + +Math.random(); +~~~~~~~~~~~ [math] +const x = Math.random; + ~~~~~~~~~~~ [math] + +import crypto = require('crypto') + +crypto.pseudoRandomBytes(0); +~~~~~~~~~~~~~~~~~~~~~~~~ [crypto] +const x = crypto.pseudoRandomBytes; + ~~~~~~~~~~~~~~~~~~~~~~~~ [crypto] + +[crypto]: crypto.pseudoRandomBytes produces insecure random numbers. Use crypto.randomBytes() instead +[math]: Math.random produces insecure random numbers. Use crypto.randomBytes() or window.crypto.getRandomValues() instead diff --git a/tests/insecure-random/tslint.json b/tests/insecure-random/tslint.json new file mode 100644 index 000000000..8e792c66f --- /dev/null +++ b/tests/insecure-random/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "insecure-random": true + } +} diff --git a/tests/jquery-deferred-must-complete/test.ts.lint b/tests/jquery-deferred-must-complete/test.ts.lint new file mode 100644 index 000000000..d51834594 --- /dev/null +++ b/tests/jquery-deferred-must-complete/test.ts.lint @@ -0,0 +1,227 @@ + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + if (something) { + deferred.resolve(); + } else { + if (somethingElse) { + deferred.resolve(); + } else { + deferred.reject(); + } + } + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + let deferred: JQueryDeferred = jquery.Deferred(); + if (something) { + deferred.resolve(); + } else { + if (somethingElse) { + deferred.resolve(); + } else { + deferred.reject(); + } + } + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = $.Deferred(); + if (something) { + deferred.resolve(); + } else { + if (somethingElse) { + deferred.resolve(); + } else { + deferred.reject(); + } + } + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = $.Deferred(); + deferred.resolve(); + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = $.Deferred(); + deferred.reject(); + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + if (something) { + deferred.resolve(); + } + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + if (something) { + deferred.resolve(); + } else { + deferred.resolve(); + } + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + if (something) { + if (somethingElse) { + deferred.resolve(); + } else { + deferred.reject(); + } + } else { + if (somethingElse) { + deferred.resolve(); + } else { + deferred.reject(); + } + } + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + if (something) { + if (somethingElse) { + deferred.resolve(); + } else { + deferred.reject(); + } + } else { + if (somethingElse) { + deferred.somethingElse(); + } else { + deferred.reject(); + } + deferred.reject(); // branches are not even analyzed when main thread resolves + } + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + someCall(function () { + deferred.resolve(); + }); + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + someCall(() => { + deferred.resolve(); + }); + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + someCall(function (someParm) { + deferred.resolve(); + }); + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + someCall((someParm) => { // this parameter actually shadows the one in the enclosing scope + deferred.resolve(); + }); + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + for(var x = 0; x < something.length; x++) { + deferred.resolve(); + } + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + for(var x in something) { + deferred.resolve(); + } + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + while (something) { + deferred.resolve(); + } + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + doSomething(deferred); // reference escapes and we assume it resolves + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = $.Deferred(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('deferred: JQueryDeferred = $.Deferred()')] + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('deferred: JQueryDeferred = jquery.Deferred()')] + if (something) { + deferred.resolve(); + } else { + deferred.someOtherFunction() + } + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + let deferred: JQueryDeferred = jquery.Deferred(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('deferred: JQueryDeferred = jquery.Deferred()')] + if (something) { + if (somethingElse) { + deferred.resolve(); + } else { + deferred.reject(); + } + } else { + if (somethingElse) { + deferred.somethingElse(); + } else { + deferred.reject(); + } + } + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('deferred: JQueryDeferred = jquery.Deferred()')] + someCall(function (deferred) { // this parameter actually shadows the one in the enclosing scope + deferred.resolve(); + }); + return deferred.promise(); +} + +function myMethod() : JQueryPromise { + var deferred: JQueryDeferred = jquery.Deferred(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('deferred: JQueryDeferred = jquery.Deferred()')] + someCall((arg1, deferred) => { // this parameter actually shadows the one in the enclosing scope + deferred.resolve(); + }); + return deferred.promise(); +} + +[0]: A JQuery deferred was found that appears to not have resolve or reject invoked on all code paths: '%s' diff --git a/tests/jquery-deferred-must-complete/tslint.json b/tests/jquery-deferred-must-complete/tslint.json new file mode 100644 index 000000000..2b65887fd --- /dev/null +++ b/tests/jquery-deferred-must-complete/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "jquery-deferred-must-complete": [true] + } +} diff --git a/tests/max-func-body-length/default/test.ts.lint b/tests/max-func-body-length/default/test.ts.lint new file mode 100644 index 000000000..9c1f1bcdd --- /dev/null +++ b/tests/max-func-body-length/default/test.ts.lint @@ -0,0 +1,68 @@ +// https://github.com/Microsoft/tslint-microsoft-contrib/issues/468#issuecomment-407456317 + +// 1-line arrow function +const plusOne: (x: number) => number = (x: number): number => x + 1; // Line 1 + +// 3-line arrow function +const plusTwo: (x: number) => number = (x: number): number => { // Line 1 + return x + 2; // Line 2 +}; // Line 3 + +// 5-line "declared" function +function plusThree(x: number): number { // Line 1 + let retVal: number = x; // Line 2 + retVal += 3; // Line 3 + return retVal; // Line 4 +} // Line 5 + +// 7-line "expressed" function +const plusFour: (x: number) => number = function (x: number): number { // Line 1 + let retVal: number = x; // Line 2 + retVal += 1; // Line 3 + retVal += 1; // Line 4 + retVal += 2; // Line 5 + return retVal; // Line 6 +}; // Line 7 + +class PlusPlus { + public num: number; + + // 4-line constructor + constructor(num: number) { // Line 1 + this.num = num; // Line 2 + this.num *= 1; // Line 3 + } // Line 4 + + // 9-line method + public plusFive(): number { // Line 1 + let ret: number = this.num; // Line 2 + // Line 3 + for (let iter: number = 0; iter < 5; iter += 1) { // Line 4 + ret += 1; // Line 5 + } // Line 6 + // Line 7 + return ret; // Line 8 + } // Line 9 +} + +// 10-line arrow function (with counted comments amd blanks) +const plusSix: (x: number) => number = function (x: number): number { // Line 1 + /* KEEP */ // Line 2 + /* CALM */ // Line 3 + /* AND */ // Line 4 + // MIND // Line 5 + // THE // Line 6 + // GAP // Line 7 + + return x + 6; // Line 9 +}; // Line 10 + +// 11-nameless class +export default class extends PlusPlus {} + +console.log(plusOne(1)); // 2 +console.log(plusTwo(2)); // 4 +console.log(plusThree(3)); // 6 +console.log(plusFour(4)); // 8 +console.log(new PlusPlus(5).plusFive()); // 10 +console.log(plusSix(6)); // 12 diff --git a/tests/max-func-body-length/default/tslint.json b/tests/max-func-body-length/default/tslint.json new file mode 100644 index 000000000..34aa6ab20 --- /dev/null +++ b/tests/max-func-body-length/default/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "max-func-body-length": [true] + } +} diff --git a/tests/max-func-body-length/ignore-comments/test.ts.lint b/tests/max-func-body-length/ignore-comments/test.ts.lint new file mode 100644 index 000000000..41553509d --- /dev/null +++ b/tests/max-func-body-length/ignore-comments/test.ts.lint @@ -0,0 +1,29 @@ +function sum(a,b) { + /** + * add both a and b together + * this is some complex math, + * so it's best we abstract + * it away from the user + */ + return a + b; +} + +function sub(a,b) { + // similarly to sub, this is + // some pretty complex + // arithmetic. + // let's keep this away from + // the user as well. + return a - b; +} + +function sum(a,b) { +~~~~~~~~~~~~~~~~~~~ + let sum = a; // start with a +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + sum += b; // now add b +~~~~~~~~~~~~~~~~~~~~~~~~~~ + return sum; // return the result +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +} +~ [Max function body length exceeded in function sum() - max: 3, actual: 5] diff --git a/tests/max-func-body-length/ignore-comments/tslint.json b/tests/max-func-body-length/ignore-comments/tslint.json new file mode 100644 index 000000000..79eecb198 --- /dev/null +++ b/tests/max-func-body-length/ignore-comments/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "max-func-body-length": [true, 3, { "ignore-comments": true }] + } +} diff --git a/tests/max-func-body-length/ignore-parameters-to-function-regex/test.ts.lint b/tests/max-func-body-length/ignore-parameters-to-function-regex/test.ts.lint new file mode 100644 index 000000000..6ec7f6d60 --- /dev/null +++ b/tests/max-func-body-length/ignore-parameters-to-function-regex/test.ts.lint @@ -0,0 +1,35 @@ +describe('something', (): void => { + // line 2 + // line 3 + // line 4 + // line 5 +}); // line 6 + +describe('something', function name() { + // line 2 + // line 3 + // line 4 + // line 5 + // line 6 +}); // line 7 + +describe('something', function () { + // line 2 + // line 3 + // line 4 + // line 5 + // line 6 +}); // line 7 + +describeThings('something', (): void => { + ~~~~~~~~~~~~~ + // line 2 +~~~~~~~~~~~~~ + // line 3 +~~~~~~~~~~~~~ + // line 4 +~~~~~~~~~~~~~ + // line 5 +~~~~~~~~~~~~~ +}); // line 6 +~ [Max arrow function body length exceeded - max: 5, actual: 6] diff --git a/tests/max-func-body-length/ignore-parameters-to-function-regex/tslint.json b/tests/max-func-body-length/ignore-parameters-to-function-regex/tslint.json new file mode 100644 index 000000000..191ca4037 --- /dev/null +++ b/tests/max-func-body-length/ignore-parameters-to-function-regex/tslint.json @@ -0,0 +1,11 @@ +{ + "rules": { + "max-func-body-length": [ + true, + 5, + { + "ignore-parameters-to-function-regex": "^describe$" + } + ] + } +} diff --git a/tests/max-func-body-length/max-length/test.ts.lint b/tests/max-func-body-length/max-length/test.ts.lint new file mode 100644 index 000000000..e50992332 --- /dev/null +++ b/tests/max-func-body-length/max-length/test.ts.lint @@ -0,0 +1,113 @@ +// https://github.com/Microsoft/tslint-microsoft-contrib/issues/468#issuecomment-407456317 + +// 1-line arrow function +const plusOne: (x: number) => number = (x: number): number => x + 1; // Line 1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [arrow % ('1')] + +// 3-line arrow function +const plusTwo: (x: number) => number = (x: number): number => { // Line 1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + return x + 2; // Line 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +}; // Line 3 +~ [arrow % ('3')] + +// 5-line "declared" function +function plusThree(x: number): number { // Line 1 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + let retVal: number = x; // Line 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + retVal += 3; // Line 3 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + return retVal; // Line 4 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +} // Line 5 +~ [function % ('plusThree', '5')] + +// 7-line "expressed" function +const plusFour: (x: number) => number = function (x: number): number { // Line 1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + let retVal: number = x; // Line 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + retVal += 1; // Line 3 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + retVal += 1; // Line 4 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + retVal += 2; // Line 5 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + return retVal; // Line 6 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +}; // Line 7 +~ [expression % ('7')] + +class PlusPlus { + public num: number; + + // 4-line constructor + constructor(num: number) { // Line 1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + this.num = num; // Line 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + this.num *= 1; // Line 3 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } // Line 4 +~~~~~[constructor % ('PlusPlus', '4')] + + // 9-line method + public plusFive(): number { // Line 1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + let ret: number = this.num; // Line 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Line 3 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + for (let iter: number = 0; iter < 5; iter += 1) { // Line 4 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ret += 1; // Line 5 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } // Line 6 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Line 7 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + return ret; // Line 8 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } // Line 9 +~~~~~ [method % ('plusFive', '9')] +} + +// 10-line arrow function (with counted comments amd blanks) +const plusSix: (x: number) => number = function (x: number): number { // Line 1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + /* KEEP */ // Line 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + /* CALM */ // Line 3 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + /* AND */ // Line 4 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // MIND // Line 5 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // THE // Line 6 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // GAP // Line 7 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +~nil + return x + 6; // Line 9 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +}; // Line 10 +~ [expression % ('10')] + +// 11-nameless class +export default class extends PlusPlus {} + +console.log(plusOne(1)); // 2 +console.log(plusTwo(2)); // 4 +console.log(plusThree(3)); // 6 +console.log(plusFour(4)); // 8 +console.log(new PlusPlus(5).plusFive()); // 10 +console.log(plusSix(6)); // 12 + +[arrow]: Max arrow function body length exceeded - max: 0, actual: %s +[constructor]: Max constructor body length exceeded in class %s - max: 0, actual: %s +[function]: Max function body length exceeded in function %s() - max: 0, actual: %s +[expression]: Max function expression body length exceeded in function expression () - max: 0, actual: %s +[method]: Max method body length exceeded in method %s() - max: 0, actual: %s diff --git a/tests/max-func-body-length/max-length/tslint.json b/tests/max-func-body-length/max-length/tslint.json new file mode 100644 index 000000000..066c16c5e --- /dev/null +++ b/tests/max-func-body-length/max-length/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "max-func-body-length": [true, 0] + } +} diff --git a/tests/max-func-body-length/max-lengths-custom/test.ts.lint b/tests/max-func-body-length/max-lengths-custom/test.ts.lint new file mode 100644 index 000000000..7941d3520 --- /dev/null +++ b/tests/max-func-body-length/max-lengths-custom/test.ts.lint @@ -0,0 +1,105 @@ +// https://github.com/Microsoft/tslint-microsoft-contrib/issues/468#issuecomment-407456317 + +// 1-line arrow function +const plusOne: (x: number) => number = (x: number): number => x + 1; // Line 1 + +// 3-line arrow function +const plusTwo: (x: number) => number = (x: number): number => { // Line 1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + return x + 2; // Line 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +}; // Line 3 +~ [arrow % ('2', '3')] + +// 5-line "declared" function +function plusThree(x: number): number { // Line 1 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + let retVal: number = x; // Line 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + retVal += 3; // Line 3 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + return retVal; // Line 4 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +} // Line 5 +~ [function % ('plusThree', '4', '5')] + +// 7-line "expressed" function +const plusFour: (x: number) => number = function (x: number): number { // Line 1 + let retVal: number = x; // Line 2 + retVal += 1; // Line 3 + retVal += 1; // Line 4 + retVal += 2; // Line 5 + return retVal; // Line 6 +}; // Line 7 + +class PlusPlus { + public num: number; + + // 4-line constructor + constructor(num: number) { // Line 1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + this.num = num; // Line 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + this.num *= 1; // Line 3 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } // Line 4 +~~~~~ [constructor % ('PlusPlus', '3', '4')] + + // 9-line method + public plusFive(): number { // Line 1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + let ret: number = this.num; // Line 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Line 3 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + for (let iter: number = 0; iter < 5; iter += 1) { // Line 4 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ret += 1; // Line 5 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } // Line 6 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Line 7 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + return ret; // Line 8 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } // Line 9 +~~~~~ [method % ('plusFive', '8', '9')] +} + +// 10-line arrow function (with counted comments amd blanks) +const plusSix: (x: number) => number = function (x: number): number { // Line 1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + /* KEEP */ // Line 2 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + /* CALM */ // Line 3 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + /* AND */ // Line 4 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // MIND // Line 5 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // THE // Line 6 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // GAP // Line 7 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +~nil + return x + 6; // Line 9 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +}; // Line 10 +~ [expression % ('7', '10')] + +// 11-nameless class +export default class extends PlusPlus {} + +console.log(plusOne(1)); // 2 +console.log(plusTwo(2)); // 4 +console.log(plusThree(3)); // 6 +console.log(plusFour(4)); // 8 +console.log(new PlusPlus(5).plusFive()); // 10 +console.log(plusSix(6)); // 12 + +[arrow]: Max arrow function body length exceeded - max: %s, actual: %s +[constructor]: Max constructor body length exceeded in class %s - max: %s, actual: %s +[function]: Max function body length exceeded in function %s() - max: %s, actual: %s +[expression]: Max function expression body length exceeded in function expression () - max: %s, actual: %s +[method]: Max method body length exceeded in method %s() - max: %s, actual: %s diff --git a/tests/max-func-body-length/max-lengths-custom/tslint.json b/tests/max-func-body-length/max-lengths-custom/tslint.json new file mode 100644 index 000000000..3b4ffe140 --- /dev/null +++ b/tests/max-func-body-length/max-lengths-custom/tslint.json @@ -0,0 +1,14 @@ +{ + "rules": { + "max-func-body-length": [ + true, + { + "arrow-body-length": 2, + "ctor-body-length": 3, + "func-body-length": 4, + "func-express-body-length": 7, + "method-body-length": 8 + } + ] + } +} diff --git a/tests/missing-jsdoc/leading-spaces/test.ts.lint b/tests/missing-jsdoc/leading-spaces/test.ts.lint new file mode 100644 index 000000000..41f66bb65 --- /dev/null +++ b/tests/missing-jsdoc/leading-spaces/test.ts.lint @@ -0,0 +1,5 @@ + /** +~nil [File missing JSDoc comment at the top-level.] + * whatever + */ + function whatever() { } diff --git a/tests/missing-jsdoc/leading-spaces/tslint.json b/tests/missing-jsdoc/leading-spaces/tslint.json new file mode 100644 index 000000000..540122a2c --- /dev/null +++ b/tests/missing-jsdoc/leading-spaces/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "missing-jsdoc": [true] + } +} diff --git a/tests/missing-jsdoc/missing-comment/test.ts.lint b/tests/missing-jsdoc/missing-comment/test.ts.lint new file mode 100644 index 000000000..ddc5d5103 --- /dev/null +++ b/tests/missing-jsdoc/missing-comment/test.ts.lint @@ -0,0 +1,2 @@ +function whatever() +~nil [File missing JSDoc comment at the top-level.] diff --git a/tests/missing-jsdoc/missing-comment/tslint.json b/tests/missing-jsdoc/missing-comment/tslint.json new file mode 100644 index 000000000..540122a2c --- /dev/null +++ b/tests/missing-jsdoc/missing-comment/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "missing-jsdoc": [true] + } +} diff --git a/tests/missing-jsdoc/one-star-comment/test.ts.lint b/tests/missing-jsdoc/one-star-comment/test.ts.lint new file mode 100644 index 000000000..a92b8d907 --- /dev/null +++ b/tests/missing-jsdoc/one-star-comment/test.ts.lint @@ -0,0 +1,5 @@ +/* +~nil [File missing JSDoc comment at the top-level.] + * + */ +function whatever() { } diff --git a/tests/missing-jsdoc/one-star-comment/tslint.json b/tests/missing-jsdoc/one-star-comment/tslint.json new file mode 100644 index 000000000..540122a2c --- /dev/null +++ b/tests/missing-jsdoc/one-star-comment/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "missing-jsdoc": [true] + } +} diff --git a/tests/missing-jsdoc/three-star-comment - Copy/test.ts.lint b/tests/missing-jsdoc/three-star-comment - Copy/test.ts.lint new file mode 100644 index 000000000..63eaffc96 --- /dev/null +++ b/tests/missing-jsdoc/three-star-comment - Copy/test.ts.lint @@ -0,0 +1,5 @@ +/*** +~nil [File missing JSDoc comment at the top-level.] + * whatever + */ +function whatever() { } diff --git a/tests/missing-jsdoc/three-star-comment - Copy/tslint.json b/tests/missing-jsdoc/three-star-comment - Copy/tslint.json new file mode 100644 index 000000000..540122a2c --- /dev/null +++ b/tests/missing-jsdoc/three-star-comment - Copy/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "missing-jsdoc": [true] + } +} diff --git a/tests/missing-jsdoc/three-star-comment/test.ts.lint b/tests/missing-jsdoc/three-star-comment/test.ts.lint new file mode 100644 index 000000000..63eaffc96 --- /dev/null +++ b/tests/missing-jsdoc/three-star-comment/test.ts.lint @@ -0,0 +1,5 @@ +/*** +~nil [File missing JSDoc comment at the top-level.] + * whatever + */ +function whatever() { } diff --git a/tests/missing-jsdoc/three-star-comment/tslint.json b/tests/missing-jsdoc/three-star-comment/tslint.json new file mode 100644 index 000000000..540122a2c --- /dev/null +++ b/tests/missing-jsdoc/three-star-comment/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "missing-jsdoc": [true] + } +} diff --git a/tests/missing-jsdoc/top-level-comment/test.ts.lint b/tests/missing-jsdoc/top-level-comment/test.ts.lint new file mode 100644 index 000000000..1427f6b9a --- /dev/null +++ b/tests/missing-jsdoc/top-level-comment/test.ts.lint @@ -0,0 +1,4 @@ +/** + * whatever + */ +function whatever() { } diff --git a/tests/missing-jsdoc/top-level-comment/tslint.json b/tests/missing-jsdoc/top-level-comment/tslint.json new file mode 100644 index 000000000..540122a2c --- /dev/null +++ b/tests/missing-jsdoc/top-level-comment/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "missing-jsdoc": [true] + } +} diff --git a/tests/missing-jsdoc/trailing-chars/test.ts.lint b/tests/missing-jsdoc/trailing-chars/test.ts.lint new file mode 100644 index 000000000..206366e2a --- /dev/null +++ b/tests/missing-jsdoc/trailing-chars/test.ts.lint @@ -0,0 +1,5 @@ +/** bad format +~nil [File missing JSDoc comment at the top-level.] + * whatever + */ +function whatever() { } diff --git a/tests/missing-jsdoc/trailing-chars/tslint.json b/tests/missing-jsdoc/trailing-chars/tslint.json new file mode 100644 index 000000000..540122a2c --- /dev/null +++ b/tests/missing-jsdoc/trailing-chars/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "missing-jsdoc": [true] + } +} diff --git a/tests/missing-optional-annotation/test.ts.lint b/tests/missing-optional-annotation/test.ts.lint new file mode 100644 index 000000000..a6d31c8a7 --- /dev/null +++ b/tests/missing-optional-annotation/test.ts.lint @@ -0,0 +1,63 @@ +class MissingOptionalAnnotationPassingTestInput { + + constructor() {} + constructor(arg1?) {} + constructor(arg1, arg2?) {} + constructor(arg1, arg2?, arg3?) {} + + voidMethod() {} + unaryMethod(arg1) {} + bindaryMethod(arg1, arg2?) {} + ternaryMethod(arg1, arg2?, arg3?) {} + + private arrow0 = () => {}; + private arrow1 = (arg?) => {}; + private arrow2 = (arg1, arg2?) => {}; + private arrow3 = (arg1, arg2?, arg3?) => {}; + + private literalFunction0 = function() {}; + private literalFunction1 = function(arg?) {}; + private literalFunction2 = function(arg1, arg2?) {}; + private literalFunction3 = function(arg1, arg2?, arg3?) {}; + +} + +// these declarations need to be made outside of a class +function function0() {} +function function1(arg) {} +function function2(arg1, arg2?) {} +function function3(arg1, arg2?, arg3?) {} + +function something(data : Object = {}, others: any) { } + ~~~~~~ [0 % ('others: any')] + +class MissingOptionalAnnotationPassingTestInput { + + constructor(optionalArg1?, requiredArg2) {} + ~~~~~~~~~~~~ [0 % ('requiredArg2')] + constructor(requiredArg1, optionalArg2?, requiredArg3) {} + ~~~~~~~~~~~~ [0 % ('requiredArg3')] + + bindaryMethod(optionalArg1?, requiredArg2) {} + ~~~~~~~~~~~~ [0 % ('requiredArg2')] + ternaryMethod(requiredArg1, optionalArg2?, requiredArg3) {} + ~~~~~~~~~~~~ [0 % ('requiredArg3')] + + private arrow2 = (optionalArg1?, requiredArg2) => {}; + ~~~~~~~~~~~~ [0 % ('requiredArg2')] + private arrow3 = (requiredArg1, optionalArg2?, requiredArg3) => {}; + ~~~~~~~~~~~~ [0 % ('requiredArg3')] + + private literalFunction2 = function(optionalArg1?, requiredArg2) {}; + ~~~~~~~~~~~~ [0 % ('requiredArg2')] + private literalFunction3 = function(requiredArg1, optionalArg2?, requiredArg3) {}; + ~~~~~~~~~~~~ [0 % ('requiredArg3')] + +} + +// these declarations need to be made outside of a class +function function2(optionalArg1?, requiredArg2) {} + ~~~~~~~~~~~~ [0 % ('requiredArg2')] +function function3(requiredArg1, optionalArg2?, requiredArg3) {} + ~~~~~~~~~~~~ [0 % ('requiredArg3')] +[0]: Argument following optional argument missing optional annotation: %s diff --git a/tests/missing-optional-annotation/tslint.json b/tests/missing-optional-annotation/tslint.json new file mode 100644 index 000000000..97f30e6b3 --- /dev/null +++ b/tests/missing-optional-annotation/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "missing-optional-annotation": [true] + } +} diff --git a/tests/mocha-avoid-only/test.ts.lint b/tests/mocha-avoid-only/test.ts.lint new file mode 100644 index 000000000..7c41984f3 --- /dev/null +++ b/tests/mocha-avoid-only/test.ts.lint @@ -0,0 +1,72 @@ +describe('some unit test', () => { + it('some test', () => { + // some test code + }); + + // these are not calls to mocha's it.only + it.only(); + it.only(''); + it.only(() => {}); + it.only(something, () => {}); + it.only('', something); + it.only(something, somethingElse); + + // these are not calls to mocha's describe.only + describe.only(); + describe.only(''); + describe.only(() => {}); + describe.only(something, () => {}); + describe.only('', something); + describe.only(something, somethingElse); + + // these are not calls to mocha's context.only + context.only(); + context.only(''); + context.only(() => {}); + context.only(something, () => {}); + context.only('', something); + context.only(something, somethingElse); +}); + +describe('some unit test', () => { + it.only('some test', () => { + ~~~~~~~ [0 % ('it')] + // some test code + }); +}); + +context('some unit test', () => { + specify.only('some test', () => { + ~~~~~~~~~~~~ [0 % ('specify')] + // some test code + }); +}); + +describe('some unit test', () => { + it.only('some test', function() { + ~~~~~~~ [0 % ('it')] + // some test code + }); +}); + +describe.only('some unit test', () => { +~~~~~~~~~~~~~ [0 % ('describe')] + // some test code +}); + +describe.only('some unit test', function() { +~~~~~~~~~~~~~ [0 % ('describe')] + // some test code +}); + +context.only('some unit test', () => { +~~~~~~~~~~~~ [0 % ('context')] + // some test code +}); + +context.only('some unit test', function() { +~~~~~~~~~~~~ [0 % ('context')] + // some test code +}); + +[0]: Do not commit Mocha %s.only function call \ No newline at end of file diff --git a/tests/mocha-avoid-only/tslint.json b/tests/mocha-avoid-only/tslint.json new file mode 100644 index 000000000..92bf954ba --- /dev/null +++ b/tests/mocha-avoid-only/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-avoid-only": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/complex-arrays/test.ts.lint b/tests/mocha-no-side-effect-code/complex-arrays/test.ts.lint new file mode 100644 index 000000000..21644f016 --- /dev/null +++ b/tests/mocha-no-side-effect-code/complex-arrays/test.ts.lint @@ -0,0 +1,4 @@ +describe('someTest', (): void => { + const VIOLATION = [ someCall() ]; + ~~~~~~~~~~~~~~~~~~~~~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): VIOLATION = [ someCall() ]] +}); diff --git a/tests/mocha-no-side-effect-code/complex-arrays/tslint.json b/tests/mocha-no-side-effect-code/complex-arrays/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/complex-arrays/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/complex-cast/test.ts.lint b/tests/mocha-no-side-effect-code/complex-cast/test.ts.lint new file mode 100644 index 000000000..acb45a7e5 --- /dev/null +++ b/tests/mocha-no-side-effect-code/complex-cast/test.ts.lint @@ -0,0 +1,4 @@ +describe('someTest', (): void => { + const publisher: DTO.Publisher = doSomething(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): publisher: DTO.Publisher = <...] +}); diff --git a/tests/mocha-no-side-effect-code/complex-cast/tslint.json b/tests/mocha-no-side-effect-code/complex-cast/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/complex-cast/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/complex-json-structures/test.ts.lint b/tests/mocha-no-side-effect-code/complex-json-structures/test.ts.lint new file mode 100644 index 000000000..7e661bdbc --- /dev/null +++ b/tests/mocha-no-side-effect-code/complex-json-structures/test.ts.lint @@ -0,0 +1,11 @@ +let searchItems: DTO.SearchItem[] = [ + {'id': '4', 'name': 'All Search Topics', owner: undefined, ownerName: '', createdDate: undefined}, + {'id': '66', 'name': 'Products', 'parentId': '4', owner: undefined, ownerName: '', createdDate: undefined}, + {'id': '314012', 'name': 'Honey', 'parentId': '66', owner: undefined, ownerName: '', createdDate: undefined}, + {'id': '314072', 'name': 'Bonny', 'parentId': '66', owner: undefined, ownerName: '', createdDate: undefined}, + {'id': '65', 'name': 'Uncategorized', 'parentId': '4', owner: undefined, ownerName: '', createdDate: undefined}, + {'id': '216102', 'name': 'Blub', 'parentId': '65', owner: undefined, ownerName: '', createdDate: undefined}, + {'id': '314022', 'name': 'Bnutsch', 'parentId': '65', owner: undefined, ownerName: '', createdDate: undefined} +]; +describe('someTest', (): void => { +}); diff --git a/tests/mocha-no-side-effect-code/complex-json-structures/tslint.json b/tests/mocha-no-side-effect-code/complex-json-structures/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/complex-json-structures/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/configured-factory-methods/test.ts.lint b/tests/mocha-no-side-effect-code/configured-factory-methods/test.ts.lint new file mode 100644 index 000000000..e842fdfa3 --- /dev/null +++ b/tests/mocha-no-side-effect-code/configured-factory-methods/test.ts.lint @@ -0,0 +1,7 @@ +const x = RestDataFactory.createSocialProfile() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): x = RestDataFactory.createSo...] + +describe('someTest', (): void => { + const y = RestDataFactory.createSocialProfileToken() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): y = RestDataFactory.createSo...] +}); diff --git a/tests/mocha-no-side-effect-code/configured-factory-methods/tslint.json b/tests/mocha-no-side-effect-code/configured-factory-methods/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/configured-factory-methods/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/context/test.ts.lint b/tests/mocha-no-side-effect-code/context/test.ts.lint new file mode 100644 index 000000000..e9a8e44c7 --- /dev/null +++ b/tests/mocha-no-side-effect-code/context/test.ts.lint @@ -0,0 +1,4 @@ +context('someTest', (): void => { + expect(convertedTags).to.deep.equal(tags); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): expect(convertedTags).to.dee...] +}); diff --git a/tests/mocha-no-side-effect-code/context/tslint.json b/tests/mocha-no-side-effect-code/context/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/context/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/correct-scoping/test.ts.lint b/tests/mocha-no-side-effect-code/correct-scoping/test.ts.lint new file mode 100644 index 000000000..950d713d3 --- /dev/null +++ b/tests/mocha-no-side-effect-code/correct-scoping/test.ts.lint @@ -0,0 +1,34 @@ +describe('someTest', (): void => { + const CONST1 = 'one'; + const CONST2 = 2; + const CONST3 = true; + const CONST4 = false; + + before((): void => { + const foo = someValue(); + }); + beforeEach((): void => { + const foo = someValue(); + }); + beforeAll((): void => { + const foo = someValue(); + }); + after((): void => { + const foo = someValue(); + }); + afterEach((): void => { + const foo = someValue(); + }); + afterAll((): void => { + const foo = someValue(); + }); + it((): void => { + const foo = someValue(); + }); + describe((): void => { + const CONST4 = false; + it((): void => { + const foo = someValue(); + }); + }); +}); diff --git a/tests/mocha-no-side-effect-code/correct-scoping/tslint.json b/tests/mocha-no-side-effect-code/correct-scoping/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/correct-scoping/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/date-creation/test.ts.lint b/tests/mocha-no-side-effect-code/date-creation/test.ts.lint new file mode 100644 index 000000000..5949f1b05 --- /dev/null +++ b/tests/mocha-no-side-effect-code/date-creation/test.ts.lint @@ -0,0 +1,5 @@ +let date = moment(); +let firstActiveDay: Moment = moment().subtract(2, 'years'); +let date2 = new Date(123123123); +describe('someTest', (): void => { +}); diff --git a/tests/mocha-no-side-effect-code/date-creation/tslint.json b/tests/mocha-no-side-effect-code/date-creation/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/date-creation/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/describe-skip/test.ts.lint b/tests/mocha-no-side-effect-code/describe-skip/test.ts.lint new file mode 100644 index 000000000..23e941ab7 --- /dev/null +++ b/tests/mocha-no-side-effect-code/describe-skip/test.ts.lint @@ -0,0 +1,7 @@ +const VIOLATION1 = new MyClass(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): VIOLATION1 = new MyClass()] + +describe('someTest', (): void => { + it((): void => { + }); +}); diff --git a/tests/mocha-no-side-effect-code/describe-skip/tslint.json b/tests/mocha-no-side-effect-code/describe-skip/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/describe-skip/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/describe/test.ts.lint b/tests/mocha-no-side-effect-code/describe/test.ts.lint new file mode 100644 index 000000000..e369d1289 --- /dev/null +++ b/tests/mocha-no-side-effect-code/describe/test.ts.lint @@ -0,0 +1,21 @@ +describe('someTest', (): void => { + const VIOLATION1 = this.myMethod(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): VIOLATION1 = this.myMethod()] + const VIOLATION2 = new MyClass(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): VIOLATION2 = new MyClass()] + + it((): void => { + const foo = someValue(); // OK + }); + + describe('someTest', (): void => { + const VIOLATION3 = true ? false : true; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): VIOLATION3 = true ? false : ...] + const VIOLATION4 = x || 'some value'; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): VIOLATION4 = x || 'some value'] + + it((): void => { + const foo = someValue(); // OK + }); + }); +}); diff --git a/tests/mocha-no-side-effect-code/describe/tslint.json b/tests/mocha-no-side-effect-code/describe/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/describe/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/empty-simple-arrays/test.ts.lint b/tests/mocha-no-side-effect-code/empty-simple-arrays/test.ts.lint new file mode 100644 index 000000000..b1daf9221 --- /dev/null +++ b/tests/mocha-no-side-effect-code/empty-simple-arrays/test.ts.lint @@ -0,0 +1,4 @@ +describe('someTest', (): void => { + const CONST1 = []; + const CONST2 = [ true, false, 1, 0, 'value', null]; +}); diff --git a/tests/mocha-no-side-effect-code/empty-simple-arrays/tslint.json b/tests/mocha-no-side-effect-code/empty-simple-arrays/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/empty-simple-arrays/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/foreach-complex/test.ts.lint b/tests/mocha-no-side-effect-code/foreach-complex/test.ts.lint new file mode 100644 index 000000000..3f84f5848 --- /dev/null +++ b/tests/mocha-no-side-effect-code/foreach-complex/test.ts.lint @@ -0,0 +1,10 @@ +describe('something', (): void => { + [ someCall() ].forEach((): void => { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + it('test', (): void => { +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + }); +~~~~~~~~~~~ + }); +~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): [ someCall() ].forEach((): v...] +}); diff --git a/tests/mocha-no-side-effect-code/foreach-complex/tslint.json b/tests/mocha-no-side-effect-code/foreach-complex/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/foreach-complex/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/foreach-empty/test.ts.lint b/tests/mocha-no-side-effect-code/foreach-empty/test.ts.lint new file mode 100644 index 000000000..83e54b136 --- /dev/null +++ b/tests/mocha-no-side-effect-code/foreach-empty/test.ts.lint @@ -0,0 +1,6 @@ +describe('something', (): void => { + [].forEach((): void => { + it('test', (): void => { + }); + }); +}); diff --git a/tests/mocha-no-side-effect-code/foreach-empty/tslint.json b/tests/mocha-no-side-effect-code/foreach-empty/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/foreach-empty/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/foreach-function-call/test.ts.lint b/tests/mocha-no-side-effect-code/foreach-function-call/test.ts.lint new file mode 100644 index 000000000..6e81f2adc --- /dev/null +++ b/tests/mocha-no-side-effect-code/foreach-function-call/test.ts.lint @@ -0,0 +1,10 @@ +describe('something', (): void => { + someCall().forEach((): void => { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + it('test', (): void => { +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + }); +~~~~~~~~~~~ + }); +~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): someCall().forEach((): void ...] +}); diff --git a/tests/mocha-no-side-effect-code/foreach-function-call/tslint.json b/tests/mocha-no-side-effect-code/foreach-function-call/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/foreach-function-call/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/foreach-function-side-effects/test.ts.lint b/tests/mocha-no-side-effect-code/foreach-function-side-effects/test.ts.lint new file mode 100644 index 000000000..e31298f9c --- /dev/null +++ b/tests/mocha-no-side-effect-code/foreach-function-side-effects/test.ts.lint @@ -0,0 +1,8 @@ +describe('something', (): void => { + [1, 2, 3].forEach((): void => { + const VIOLATION = new MyClass(); + ~~~~~~~~~~~~~~~~~~~~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): VIOLATION = new MyClass()] + it('test', (): void => { + }); + }); +}); diff --git a/tests/mocha-no-side-effect-code/foreach-function-side-effects/tslint.json b/tests/mocha-no-side-effect-code/foreach-function-side-effects/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/foreach-function-side-effects/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/foreach-simple-object/test.ts.lint b/tests/mocha-no-side-effect-code/foreach-simple-object/test.ts.lint new file mode 100644 index 000000000..34157beb5 --- /dev/null +++ b/tests/mocha-no-side-effect-code/foreach-simple-object/test.ts.lint @@ -0,0 +1,10 @@ +describe('something', (): void => { + [ + { name: 'alpha', value: 1 }, + { name: 'beta', value: 2 }, + { name: 'gamma', value: 3 } + ].forEach((): void => { + it('test', (): void => { + }); + }); +}); diff --git a/tests/mocha-no-side-effect-code/foreach-simple-object/tslint.json b/tests/mocha-no-side-effect-code/foreach-simple-object/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/foreach-simple-object/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/foreach-simple/test.ts.lint b/tests/mocha-no-side-effect-code/foreach-simple/test.ts.lint new file mode 100644 index 000000000..51b6c46b9 --- /dev/null +++ b/tests/mocha-no-side-effect-code/foreach-simple/test.ts.lint @@ -0,0 +1,6 @@ +describe('something', (): void => { + [ true, false, 1, 0, 'value', null].forEach((): void => { + it('test', (): void => { + }); + }); +}); diff --git a/tests/mocha-no-side-effect-code/foreach-simple/tslint.json b/tests/mocha-no-side-effect-code/foreach-simple/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/foreach-simple/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/function-calls/test.ts.lint b/tests/mocha-no-side-effect-code/function-calls/test.ts.lint new file mode 100644 index 000000000..d68b311ac --- /dev/null +++ b/tests/mocha-no-side-effect-code/function-calls/test.ts.lint @@ -0,0 +1,4 @@ +describe('someTest', (): void => { + expect(convertedTags).to.deep.equal(tags); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): expect(convertedTags).to.dee...] +}); diff --git a/tests/mocha-no-side-effect-code/function-calls/tslint.json b/tests/mocha-no-side-effect-code/function-calls/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/function-calls/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/function-declaration/test.ts.lint b/tests/mocha-no-side-effect-code/function-declaration/test.ts.lint new file mode 100644 index 000000000..50324d82c --- /dev/null +++ b/tests/mocha-no-side-effect-code/function-declaration/test.ts.lint @@ -0,0 +1,6 @@ +describe('someTest', (): void => { + + function doSomething() { + const x = doSomethingElse(); + } +}); diff --git a/tests/mocha-no-side-effect-code/function-declaration/tslint.json b/tests/mocha-no-side-effect-code/function-declaration/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/function-declaration/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/global-scope/test.ts.lint b/tests/mocha-no-side-effect-code/global-scope/test.ts.lint new file mode 100644 index 000000000..23e941ab7 --- /dev/null +++ b/tests/mocha-no-side-effect-code/global-scope/test.ts.lint @@ -0,0 +1,7 @@ +const VIOLATION1 = new MyClass(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~ [Mocha test contains dangerous variable initialization. Move to before()/beforeEach(): VIOLATION1 = new MyClass()] + +describe('someTest', (): void => { + it((): void => { + }); +}); diff --git a/tests/mocha-no-side-effect-code/global-scope/tslint.json b/tests/mocha-no-side-effect-code/global-scope/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/global-scope/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/mocha-api/test.ts.lint b/tests/mocha-no-side-effect-code/mocha-api/test.ts.lint new file mode 100644 index 000000000..a21f5249d --- /dev/null +++ b/tests/mocha-no-side-effect-code/mocha-api/test.ts.lint @@ -0,0 +1,11 @@ +describe('retries', (): void => { + this.retries(42); + + describe('slow', (): void => { + this.slow(2500); + + describe('timeout', (): void => { + this.timeout(5000); + }); + }); +}); diff --git a/tests/mocha-no-side-effect-code/mocha-api/tslint.json b/tests/mocha-no-side-effect-code/mocha-api/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/mocha-api/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/multiline-string/test.ts.lint b/tests/mocha-no-side-effect-code/multiline-string/test.ts.lint new file mode 100644 index 000000000..e7e3c3c81 --- /dev/null +++ b/tests/mocha-no-side-effect-code/multiline-string/test.ts.lint @@ -0,0 +1,7 @@ +describe('someTest', (): void => { + + const CONST1 = \`some + multi-line + string\`; + +}); diff --git a/tests/mocha-no-side-effect-code/multiline-string/tslint.json b/tests/mocha-no-side-effect-code/multiline-string/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/multiline-string/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/nested-simple-arrays/test.ts.lint b/tests/mocha-no-side-effect-code/nested-simple-arrays/test.ts.lint new file mode 100644 index 000000000..27e2caa81 --- /dev/null +++ b/tests/mocha-no-side-effect-code/nested-simple-arrays/test.ts.lint @@ -0,0 +1,9 @@ +describe('someTest', (): void => { + const options = [true, [ + 'Mobile IE 10', + 'IE >= 10', + 'Chrome > 45', + 'Firefox', + 'Mobile Safari < 10' + ]]; +}); diff --git a/tests/mocha-no-side-effect-code/nested-simple-arrays/tslint.json b/tests/mocha-no-side-effect-code/nested-simple-arrays/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/nested-simple-arrays/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/newly-declared-classes/test.ts.lint b/tests/mocha-no-side-effect-code/newly-declared-classes/test.ts.lint new file mode 100644 index 000000000..df856b762 --- /dev/null +++ b/tests/mocha-no-side-effect-code/newly-declared-classes/test.ts.lint @@ -0,0 +1,16 @@ +describe('someTest', (): void => { + + class MockModel extends Backbone.Model { + + public fetch(options?: Backbone.ModelFetchOptions): JQueryXHR { + let request: JQueryXHR = super.fetch(options); + return request; + } + + public save(attributes?: any, options?: Backbone.ModelSaveOptions): JQueryXHR { + let request: JQueryXHR = super.save(attributes, options); + return request; + } + + } +}); diff --git a/tests/mocha-no-side-effect-code/newly-declared-classes/tslint.json b/tests/mocha-no-side-effect-code/newly-declared-classes/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/newly-declared-classes/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/not-a-test/test.ts.lint b/tests/mocha-no-side-effect-code/not-a-test/test.ts.lint new file mode 100644 index 000000000..7acf2ce7e --- /dev/null +++ b/tests/mocha-no-side-effect-code/not-a-test/test.ts.lint @@ -0,0 +1 @@ +var blah = foo; diff --git a/tests/mocha-no-side-effect-code/not-a-test/tslint.json b/tests/mocha-no-side-effect-code/not-a-test/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/not-a-test/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/simple-cases/test.ts.lint b/tests/mocha-no-side-effect-code/simple-cases/test.ts.lint new file mode 100644 index 000000000..67ee65e6e --- /dev/null +++ b/tests/mocha-no-side-effect-code/simple-cases/test.ts.lint @@ -0,0 +1,40 @@ +describe('someTest', (): void => { + const CONST1 = 'one'; + const CONST2 = 2; + const CONST3 = true; + const CONST4 = false; + + before((): void => { + const foo = someValue(); + }); + beforeEach((): void => { + const foo = someValue(); + }); + beforeAll((): void => { + const foo = someValue(); + }); + after((): void => { + const foo = someValue(); + }); + afterEach((): void => { + const foo = someValue(); + }); + afterAll((): void => { + const foo = someValue(); + }); + it((): void => { + const foo = someValue(); + }); + describe((): void => { + const CONST4 = false; + it((): void => { + const foo = someValue(); + }); + }); + context((): void => { + const CONST4 = false; + specify((): void => { + const foo = someValue(); + }); + }); +}); diff --git a/tests/mocha-no-side-effect-code/simple-cases/tslint.json b/tests/mocha-no-side-effect-code/simple-cases/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/simple-cases/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/simple-cast/test.ts.lint b/tests/mocha-no-side-effect-code/simple-cast/test.ts.lint new file mode 100644 index 000000000..5239fbef6 --- /dev/null +++ b/tests/mocha-no-side-effect-code/simple-cast/test.ts.lint @@ -0,0 +1,3 @@ +describe('someTest', (): void => { + const publisher: DTO.Publisher = { '@class': 'Publisher' }; +}); diff --git a/tests/mocha-no-side-effect-code/simple-cast/tslint.json b/tests/mocha-no-side-effect-code/simple-cast/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/simple-cast/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/simple-json-structures/test.ts.lint b/tests/mocha-no-side-effect-code/simple-json-structures/test.ts.lint new file mode 100644 index 000000000..f1fd36573 --- /dev/null +++ b/tests/mocha-no-side-effect-code/simple-json-structures/test.ts.lint @@ -0,0 +1,10 @@ +let onDaySelected: (newDate: Moment) => void = (newDate: Moment) => { + return; +}; +let inputProps: DatePicker.Props = { + selectedDate: moment(), + onDaySelected: onDaySelected, + componentName: 'test' +}; +describe('someTest', (): void => { +}); diff --git a/tests/mocha-no-side-effect-code/simple-json-structures/tslint.json b/tests/mocha-no-side-effect-code/simple-json-structures/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/simple-json-structures/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/skip-only/test.ts.lint b/tests/mocha-no-side-effect-code/skip-only/test.ts.lint new file mode 100644 index 000000000..37e41016f --- /dev/null +++ b/tests/mocha-no-side-effect-code/skip-only/test.ts.lint @@ -0,0 +1,17 @@ +describe('someTest', (): void => { + + it.skip((): void => { + }); + + describe.skip((): void => { + it.skip((): void => { + }); + }); + + it.only((): void => { + }); + describe.only((): void => { + it.only((): void => { + }); + }); +}); diff --git a/tests/mocha-no-side-effect-code/skip-only/tslint.json b/tests/mocha-no-side-effect-code/skip-only/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/skip-only/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/string-concatenation/test.ts.lint b/tests/mocha-no-side-effect-code/string-concatenation/test.ts.lint new file mode 100644 index 000000000..619a2338e --- /dev/null +++ b/tests/mocha-no-side-effect-code/string-concatenation/test.ts.lint @@ -0,0 +1,7 @@ +const SMALL_IMAGE: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+' + + 'AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAASdAAAEnQB3mYfeAAAAE9JREFUCB0BRAC7/wAAAAAAAAAAAAAAAAAAA' + + 'AAAAAAAAAD/H1f/AAAA/wAAAAAAAAAAAAAAAP///Vf/AAAAAAAAAAAAAAAAAAAAAAAAAAAA/GsHxbcKPckAAAAASUVORK5CYII='; + +const HOUR: number = 60 * 60; + +describe('someTest', (): void => { }); diff --git a/tests/mocha-no-side-effect-code/string-concatenation/tslint.json b/tests/mocha-no-side-effect-code/string-concatenation/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/string-concatenation/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-no-side-effect-code/variable-aliasing/test.ts.lint b/tests/mocha-no-side-effect-code/variable-aliasing/test.ts.lint new file mode 100644 index 000000000..3bb2c135f --- /dev/null +++ b/tests/mocha-no-side-effect-code/variable-aliasing/test.ts.lint @@ -0,0 +1,5 @@ +let expect: Chai.ExpectStatic = chai.expect; + +describe('someTest', (): void => { + let expect2: Chai.ExpectStatic = chai.expect; +}); diff --git a/tests/mocha-no-side-effect-code/variable-aliasing/tslint.json b/tests/mocha-no-side-effect-code/variable-aliasing/tslint.json new file mode 100644 index 000000000..20115fcff --- /dev/null +++ b/tests/mocha-no-side-effect-code/variable-aliasing/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-no-side-effect-code": [true] + } +} diff --git a/tests/mocha-unneeded-done/test.ts.lint b/tests/mocha-unneeded-done/test.ts.lint new file mode 100644 index 000000000..efcf18475 --- /dev/null +++ b/tests/mocha-unneeded-done/test.ts.lint @@ -0,0 +1,114 @@ +describe('...', (): void => { + before((done: MochaDone): void => { + something(done); + }); + after((done: MochaDone): void => { + something(done); + }); + beforeEach((done: MochaDone): void => { + something(done); + }); + afterEach((done: MochaDone): void => { + something(done); + }); + it('...', (done: MochaDone): void => { + something(done); + }); +}); + +describe('...', function(): void { + before(function(done: MochaDone): void { + something(done); + }); + after(function(done: MochaDone): void { + something(done); + }); + beforeEach(function(done: MochaDone): void { + something(done); + }); + afterEach(function(done: MochaDone): void { + something(done); + }); + it('...', function(done: MochaDone): void { + something(done); + }); +}); + +context('...', function(): void { + specify('...', function(done: MochaDone): void { + something(done); + }); +}); + +describe('something...', (): void => { + it('...', (done): void => { + var x = done; + done(); + }); +}); + +describe('...', (): void => { + before((done): void => { + ~~~~ [0 % ('done')] + doSomething(); + done(); + }); + after((done: MochaDone): void => { + ~~~~ [0 % ('done')] + done(); // it doesn't matter what order done() comes in. + doSomething(); + }); + beforeEach((aliasedDone: MochaDone): void => { + ~~~~~~~~~~~ [0 % ('aliasedDone')] + doSomething(); + aliasedDone(); + }); + afterEach((done: MochaDone): void => { + ~~~~ [0 % ('done')] + doSomething(); + done(); + }); + it('...', (done: MochaDone): void => { + ~~~~ [0 % ('done')] + doSomething(); + done(); + }); +}); + +context('...', (): void => { + specify('...', (done: MochaDone): void => { + ~~~~ [0 % ('done')] + doSomething(); + done(); + }); +}); + +describe('...', function(): void { + before(function(done): void { + ~~~~ [0 % ('done')] + something(); + done() + }); + after(function(myDone: MochaDone): void { + ~~~~~~ [0 % ('myDone')] + myDone(); // it doesn't matter what order it comes in + something(); + }); + beforeEach(function(done: MochaDone): void { + ~~~~ [0 % ('done')] + something(); + done() + }); + afterEach(function(done: MochaDone): void { + ~~~~ [0 % ('done')] + something(); + done() + }); + it('...', function(done: MochaDone): void { + ~~~~ [0 % ('done')] + something(); + done() + }); +}); + +[0]: Unneeded Mocha Done. Parameter can be safely removed: %s diff --git a/tests/mocha-unneeded-done/tslint.json b/tests/mocha-unneeded-done/tslint.json new file mode 100644 index 000000000..26b23f650 --- /dev/null +++ b/tests/mocha-unneeded-done/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "mocha-unneeded-done": [true] + } +} diff --git a/tests/no-backbone-get-set-outside-model/test.ts.lint b/tests/no-backbone-get-set-outside-model/test.ts.lint new file mode 100644 index 000000000..f7520a045 --- /dev/null +++ b/tests/no-backbone-get-set-outside-model/test.ts.lint @@ -0,0 +1,16 @@ +var datetime = this.get('timestamp'); +this.set('modificationdate', datetime); + +model.get(); +model.get(someIdentifier); +model.get('timestamp', 'someOtherValue'); + +model.set(); +model.set('modificationdate'); +model.set('modificationdate', value1, value2); + +var datetime = model.get('timestamp'); + ~~~~~~~~~~~~~~~~~~~~~~ [Backbone get() called outside of owning model: model.get('timestamp')] + +model.set('modificationdate', datetime); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Backbone set() called outside of owning model: model.set('modificationdate', datetime)] diff --git a/tests/no-backbone-get-set-outside-model/tslint.json b/tests/no-backbone-get-set-outside-model/tslint.json new file mode 100644 index 000000000..3f5f4ae40 --- /dev/null +++ b/tests/no-backbone-get-set-outside-model/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-backbone-get-set-outside-model": true + } +} diff --git a/tests/no-banned-terms/test.ts.lint b/tests/no-banned-terms/test.ts.lint new file mode 100644 index 000000000..3000b555c --- /dev/null +++ b/tests/no-banned-terms/test.ts.lint @@ -0,0 +1,223 @@ +module Sample { + var caller; + ~~~~~~ [0 % ('caller')] +} + +module Sample { + var callee; + ~~~~~~ [0 % ('callee')] +} + +module Sample { + var arguments; + ~~~~~~~~~ [0 % ('arguments')] +} + +module Sample { + var eval; + ~~~~ [0 % ('eval')] +} + +module Sample { + function caller() {} + ~~~~~~~~~~~~~~~~~~~~ [0 % ('caller')] +} + +module Sample { + function callee() {} + ~~~~~~~~~~~~~~~~~~~~ [0 % ('callee')] +} + +module Sample { + function arguments() {} + ~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('arguments')] +} + +module Sample { + function eval() {} + ~~~~~~~~~~~~~~~~~~ [0 % ('eval')] +} + +class Sample { + private caller; + ~~~~~~~~~~~~~~~ [0 % ('caller')] +} + +class Sample { + private callee; + ~~~~~~~~~~~~~~~ [0 % ('callee')] +} + +class Sample { + private arguments; + ~~~~~~~~~~~~~~~~~~ [0 % ('arguments')] +} + +class Sample { + private eval; + ~~~~~~~~~~~~~ [0 % ('eval')] +} + +class Sample { + private caller; + ~~~~~~~~~~~~~~~ [0 % ('caller')] +} + +class Sample { + private var; + set caller(value) {} + ~~~~~~~~~~~~~~~~~~~~ [0 % ('caller')] + get caller() { return var;} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('caller')] +} + +class Sample { + private var; + set callee(value) {} + ~~~~~~~~~~~~~~~~~~~~ [0 % ('callee')] + get callee() { return var;} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('callee')] +} + +class Sample { + private var; + set arguments(value) {} + ~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('arguments')] + get arguments() { return var;} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('arguments')] +} + +class Sample { + private var; + set eval(value) {} + ~~~~~~~~~~~~~~~~~~ [0 % ('eval')] + get eval() { return var;} + ~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('eval')] +} + +class Sample { + private var; + set caller(value) {} + ~~~~~~~~~~~~~~~~~~~~ [0 % ('caller')] + get caller() { return var;} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('caller')] +} + +class Sample { + private var; + set caller(value) {} + ~~~~~~~~~~~~~~~~~~~~ [0 % ('caller')] + get caller() { return var;} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('caller')] +} + +class Sample { + caller() {} + ~~~~~~~~~~~ [0 % ('caller')] +} + +class Sample { + callee() {} + ~~~~~~~~~~~ [0 % ('callee')] +} + +class Sample { + arguments() {} + ~~~~~~~~~~~~~~ [0 % ('arguments')] +} + +class Sample { + eval() {} + ~~~~~~~~~ [0 % ('eval')] +} + +class Sample { + method(caller) {} + ~~~~~~ [0 % ('caller')] +} + +class Sample { + method(callee) {} + ~~~~~~ [0 % ('callee')] +} + +class Sample { + method(arguments) {} + ~~~~~~~~~ [0 % ('arguments')] +} + +class Sample { + method(eval) {} + ~~~~ [0 % ('eval')] +} + +module Sample { + function method(caller) {} + ~~~~~~ [0 % ('caller')] +} + +module Sample { + function method(callee) {} + ~~~~~~ [0 % ('callee')] +} + +module Sample { + function method(arguments) {} + ~~~~~~~~~ [0 % ('arguments')] +} + +module Sample { + function method(eval) {} + ~~~~ [0 % ('eval')] +} + +module Sample { + var func = (caller) => {}; + ~~~~~~ [0 % ('caller')] +} + +module Sample { + var func = (callee) => {}; + ~~~~~~ [0 % ('callee')] +} + +module Sample { + var func = (arguments) => {}; + ~~~~~~~~~ [0 % ('arguments')] +} + +module Sample { + var func = (eval) => {}; + ~~~~ [0 % ('eval')] +} + +var caller; + ~~~~~~ [0 % ('caller')] +var callee; + ~~~~~~ [0 % ('callee')] +var arguments; + ~~~~~~~~~ [0 % ('arguments')] +var eval; + ~~~~ [0 % ('eval')] + +interface Sample { + caller: any; + ~~~~~~~~~~~~ [0 % ('caller')] +} + +interface Sample { + callee: any; + ~~~~~~~~~~~~ [0 % ('callee')] +} + +interface Sample { + arguments: any; + ~~~~~~~~~~~~~~~ [0 % ('arguments')] +} + +interface Sample { + eval: any; + ~~~~~~~~~~ [0 % ('eval')] +} + +[0]: Forbidden reference to banned term: %s \ No newline at end of file diff --git a/tests/no-banned-terms/tslint.json b/tests/no-banned-terms/tslint.json new file mode 100644 index 000000000..e99159ca1 --- /dev/null +++ b/tests/no-banned-terms/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-banned-terms": true + } +} diff --git a/tests/no-constant-condition/test.ts.lint b/tests/no-constant-condition/test.ts.lint new file mode 100644 index 000000000..4cc1940b7 --- /dev/null +++ b/tests/no-constant-condition/test.ts.lint @@ -0,0 +1,131 @@ +if (something === false) {} +if (something === true) {} +if (something > 1) {} +if (1 > something) {} +if (0 < 9 < 4 > something) {} +if (something < 9 < 4 > 2) {} +if (0 && 9 || 4 && !something) {} + +while (true) { +~~~~~~~~~~~~~~ + doSomething(); +~~~~~~~~~~~~~~~~~~ + }; +~~~ [0 % ('while (true)')] + +for (;true;) { +~~~~~~~~~~~~~~ + doSomething(); +~~~~~~~~~~~~~~~~~~ + }; +~~~ [0 % (';true;')] + +do { +~~~~ + doSomething(); +~~~~~~~~~~~~~~~~~~ + } while (true) +~~~~~~~~~~~~~~~~ [0 % ('while (true)')] + + +if (false) {} +~~~~~~~~~~~~~ [0 % ('if (false)')] +if (true) {} +~~~~~~~~~~~~ [0 % ('if (true)')] + +if (0 < 9) {} +~~~~~~~~~~~~~ [0 % ('if (0 < 9)')] +if (0 > 9) {} +~~~~~~~~~~~~~ [0 % ('if (0 > 9)')] +if (0 <= 9) {} +~~~~~~~~~~~~~~ [0 % ('if (0 <= 9)')] +if (0 >= 9) {} +~~~~~~~~~~~~~~ [0 % ('if (0 >= 9)')] +if (0 == 9) {} +~~~~~~~~~~~~~~ [0 % ('if (0 == 9)')] +if (0 != 9) {} +~~~~~~~~~~~~~~ [0 % ('if (0 != 9)')] +if (0 === 9) {} +~~~~~~~~~~~~~~~ [0 % ('if (0 === 9)')] +if (0 !== 9) {} +~~~~~~~~~~~~~~~ [0 % ('if (0 !== 9)')] +if (0 >= 9) {} +~~~~~~~~~~~~~~ [0 % ('if (0 >= 9)')] + +if (0 < 9 < 4 > 2) {} +~~~~~~~~~~~~~~~~~~~~~ [0 % ('if (0 < 9 < 4 > 2)')] + +if (0 + 9) {} +~~~~~~~~~~~~~ [0 % ('if (0 + 9)')] +if (0 9) {} +~~~~~~~ [0 % ('if (0)')] +if (0 * 9) {} +~~~~~~~~~~~~~ [0 % ('if (0 * 9)')] +if (0 / 9) {} +~~~~~~~~~~~~~ [0 % ('if (0 / 9)')] +if (0 % 9) {} +~~~~~~~~~~~~~ [0 % ('if (0 % 9)')] + +if (0++) {} +~~~~~~~~~~~ [0 % ('if (0++)')] +if (0--) {} +~~~~~~~~~~~ [0 % ('if (0--)')] + +if (++0) {} +~~~~~~~~~~~ [0 % ('if (++0)')] +if (--0) {} +~~~~~~~~~~~ [0 % ('if (--0)')] +if (!true) {} +~~~~~~~~~~~~~ [0 % ('if (!true)')] + +if (0 && 2) {} +~~~~~~~~~~~~~~ [0 % ('if (0 && 2)')] +if (3 || 9) {} +~~~~~~~~~~~~~~ [0 % ('if (3 || 9)')] + +if (0) {} +~~~~~~~~~ [0 % ('if (0)')] +if (1) {} +~~~~~~~~~ [0 % ('if (1)')] + +var x = true ? 1 : 0; + ~~~~~~~~~~~~ [0 % ('true ?')] +var y = false ? 1 : 0; + ~~~~~~~~~~~~~ [0 % ('false ?')] + +var x = 1 ? 1 : 0; + ~~~~~~~~~ [0 % ('1 ?')] +var y = 0 ? 1 : 0; + ~~~~~~~~~ [0 % ('0 ?')] + +while (false) {} +~~~~~~~~~~~~~~~~ [0 % ('while (false)')] +while (true) {} +~~~~~~~~~~~~~~~ [0 % ('while (true)')] + +while (0) {} +~~~~~~~~~~~~ [0 % ('while (0)')] +while (1) {} +~~~~~~~~~~~~ [0 % ('while (1)')] + +do {} while (true) +~~~~~~~~~~~~~~~~~~ [0 % ('while (true)')] +do {} while (false) +~~~~~~~~~~~~~~~~~~~ [0 % ('while (false)')] + +do {} while (1) +~~~~~~~~~~~~~~~ [0 % ('while (1)')] +do {} while (0) +~~~~~~~~~~~~~~~ [0 % ('while (0)')] + +for (;true;) { } +~~~~~~~~~~~~~~~~ [0 % (';true;')] +for (;false;) { } +~~~~~~~~~~~~~~~~~ [0 % (';false;')] + +for (;1;) { } +~~~~~~~~~~~~~ [0 % (';1;')] +for (;0;) { } +~~~~~~~~~~~~~ [0 % (';0;')] + +[0]: Found constant conditional: %s diff --git a/tests/no-constant-condition/tslint.json b/tests/no-constant-condition/tslint.json new file mode 100644 index 000000000..bec46c6cb --- /dev/null +++ b/tests/no-constant-condition/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-constant-condition": true + } +} diff --git a/tests/no-control-regex/test.ts.lint b/tests/no-control-regex/test.ts.lint new file mode 100644 index 000000000..b8d9d2f4b --- /dev/null +++ b/tests/no-control-regex/test.ts.lint @@ -0,0 +1,18 @@ +var pattern1 = /\\x20/; +var pattern2 = /\\x21/; +var pattern3 = /\\x30/; +var pattern4 = /\\x31/; +var pattern5 = /\\x20/; +var pattern6 = new RegExp("\\x20"); + +var pattern1 = /\\x1f/; + ~~~~~~~ [0] +var pattern2 = new RegExp("something \\x1f something else"); +var pattern3 = RegExp("\\x1f trailing text"); + +var pattern1 = /\\x00/; + ~~~~~~~ [0] +var pattern2 = new RegExp("\\x00"); +var pattern3 = RegExp("\\x00"); + +[0]: Unexpected control character in regular expression diff --git a/tests/no-control-regex/tslint.json b/tests/no-control-regex/tslint.json new file mode 100644 index 000000000..83cc64c4c --- /dev/null +++ b/tests/no-control-regex/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-control-regex": true + } +} diff --git a/tests/no-delete-expression/test.ts.lint b/tests/no-delete-expression/test.ts.lint new file mode 100644 index 000000000..f488baed6 --- /dev/null +++ b/tests/no-delete-expression/test.ts.lint @@ -0,0 +1,19 @@ +var x = { + myProperty: 'sometext' +}; +delete x.myProperty; +delete x[myProperty] + +delete this.router.routes[routeName]; + +delete this.router.routes.moreRoutes[routeName]; + +delete rights[name]; + +var something: int = 22; + +if (something) { + var variableForDeletion = 10; + delete variableForDeletion; + ~~~~~~~~~~~~~~~~~~~ [Variables should not be deleted: variableForDeletion] +} diff --git a/tests/no-delete-expression/tslint.json b/tests/no-delete-expression/tslint.json new file mode 100644 index 000000000..b8af56d46 --- /dev/null +++ b/tests/no-delete-expression/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-delete-expression": true + } +} diff --git a/tests/no-disable-auto-sanitization/test.ts.lint b/tests/no-disable-auto-sanitization/test.ts.lint new file mode 100644 index 000000000..2382c762e --- /dev/null +++ b/tests/no-disable-auto-sanitization/test.ts.lint @@ -0,0 +1,7 @@ +var retVal = MSApp.execUnsafeLocalFunction(() => {}); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('execUnsafeLocalFunction')] + +WinJS.Utilities.setInnerHTMLUnsafe(element, text); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('setInnerHTMLUnsafe')] + +[0]: Forbidden call to %s diff --git a/tests/no-disable-auto-sanitization/tslint.json b/tests/no-disable-auto-sanitization/tslint.json new file mode 100644 index 000000000..7e191643c --- /dev/null +++ b/tests/no-disable-auto-sanitization/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-disable-auto-sanitization": true + } +} diff --git a/tests/no-document-domain/test.ts.lint b/tests/no-document-domain/test.ts.lint new file mode 100644 index 000000000..e80751225 --- /dev/null +++ b/tests/no-document-domain/test.ts.lint @@ -0,0 +1,21 @@ +console.log(document.domain); +console.log(document.domain.value); +let x = document.domain; +let y = document.domain.value; + +document.domain.value = 'some value'; +model.domain = 'some model value'; + +document.domain = 'some value'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ("document.domain = 'some value'")] + +document.domain = someValue; +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('document.domain = someValue')] + +window.document.domain = someValue; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('window.document.domain = someValue')] + +let doc: Document = document; +doc.domain = 'some value'; + +[0]: Forbidden write to document.domain: %s \ No newline at end of file diff --git a/tests/no-document-domain/tslint.json b/tests/no-document-domain/tslint.json new file mode 100644 index 000000000..ff8852d70 --- /dev/null +++ b/tests/no-document-domain/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-document-domain": true + } +} diff --git a/tests/no-document-write/test.ts.lint b/tests/no-document-write/test.ts.lint new file mode 100644 index 000000000..9488edca2 --- /dev/null +++ b/tests/no-document-write/test.ts.lint @@ -0,0 +1,52 @@ +interface DocumentLikeAPI { + write: ((arg : string) => void); + writeln: ((arg : string) => void); +} + +function documentLikeAPIFunction() : DocumentLikeAPI { + return { + write: () => {}, + writeln: () => {}, + }; +} + +// These usages are OK because they are not on the DOM document +var documentAPI : DocumentLikeAPI = documentLikeAPIFunction(); +documentAPI.write('...'); +documentAPI.writeln('...'); +documentLikeAPIFunction().write('...'); +documentLikeAPIFunction().writeln('...'); + +// wrong # of args +document.write(); +document.write('', ''); +document.writeln(); +document.writeln('', ''); + +// type system has no idea what 'doc' is +var doc = document; +doc.write('...'); +doc.writeln('...'); + +// type system has no idea what 'documentFunction' returns +function documentFunction() : Document { + return window.document; +} +documentFunction().write('...'); +documentFunction().writeln('...'); + +// this is not the window presumably +this.document.write('...'); +this.document.writeln('...'); + +document.write('...'); +~~~~~~~~~~~~~~~~~~~~~ [write] +document.writeln('...'); +~~~~~~~~~~~~~~~~~~~~~~~ [writeln] +window.document.write('...'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [write] +window.document.writeln('...'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [writeln] + +[write]: Forbidden call to document.write +[writeln]: Forbidden call to document.writeln diff --git a/tests/no-document-write/tslint.json b/tests/no-document-write/tslint.json new file mode 100644 index 000000000..4fe534f8d --- /dev/null +++ b/tests/no-document-write/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-document-write": true + } +} diff --git a/tests/no-duplicate-case/test.ts.lint b/tests/no-duplicate-case/test.ts.lint new file mode 100644 index 000000000..0fcb8c3e0 --- /dev/null +++ b/tests/no-duplicate-case/test.ts.lint @@ -0,0 +1,51 @@ +var a = 1; + +switch (a) { + case 1: + break; + case 2: + break; + default: + break; +} + +switch (a) { + case 1: + break; + case 1: + ~~~~~~~ + break; +~~~~~~~~~~~~~~ [0 % ('1')] + case 2: + break; + default: + break; +} + +switch (a) { + case "1": + break; + case "1": + ~~~~~~~~~ + break; +~~~~~~~~~~~~~~ [0 % ('"1"')] + case "2": + break; + default: + break; +} + +switch (a) { + case one: + break; + case one: + ~~~~~~~~~ + break; +~~~~~~~~~~~~~~ [0 % ('one')] + case two: + break; + default: + break; +} + +[0]: Duplicate case found in switch statement: %s \ No newline at end of file diff --git a/tests/no-duplicate-case/tslint.json b/tests/no-duplicate-case/tslint.json new file mode 100644 index 000000000..97469718c --- /dev/null +++ b/tests/no-duplicate-case/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-duplicate-case": true + } +} diff --git a/tests/no-duplicate-parameter-names/test.ts.lint b/tests/no-duplicate-parameter-names/test.ts.lint new file mode 100644 index 000000000..bb03c5397 --- /dev/null +++ b/tests/no-duplicate-parameter-names/test.ts.lint @@ -0,0 +1,44 @@ +class NoDuplicateParameterNamesTestInput { + + /** + * The following code should have no errors: + */ + constructor() {} + + constructor(arg1) {} + + constructor(arg1, arg2) {} + + voidMethod() {} + unaryMethod(arg1) {} + bindaryMethod(arg1, arg2) {} + + private arrow0 = () => {}; + private arrow1 = (arg) => {}; + private arrow2 = (arg1, arg2) => {}; + + private arrowFunction0 = function() {}; + private arrowFunction1 = function(arg) {}; + private arrowFunction2 = function(arg1, arg2) {}; + + /** + * The following code should have errors: + */ + constructor(arg1, duplicateConstructorParameter, duplicateConstructorParameter) {} // triggers visitConstructorDeclaration + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('duplicateConstructorParameter')] + binaryMethod2(duplicateMethodParameter, duplicateMethodParameter?) {} // triggers visitMethodDeclaration + ~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('duplicateMethodParameter')] + private arrowFunction3 = (duplicateArrowFunctionParameter, duplicateArrowFunctionParameter) => {}; // triggers visitArrowFunction + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('duplicateArrowFunctionParameter')] + private function3 = function(duplicateFunctionExpParameter, duplicateFunctionExpParameter) {}; // triggers visitFunctionExpression + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('duplicateFunctionExpParameter')] +} + +// these declarations need to be made outside of a class +function function0() {} +function function1(arg) {} +function function2(arg1, arg2) {} +function function3(duplicateFunctionParameter, duplicateFunctionParameter) {} // triggers visitFunctionDeclaration + ~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('duplicateFunctionParameter')] + +[0]: Duplicate parameter name: '%s' diff --git a/tests/no-duplicate-parameter-names/tslint.json b/tests/no-duplicate-parameter-names/tslint.json new file mode 100644 index 000000000..433178568 --- /dev/null +++ b/tests/no-duplicate-parameter-names/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-duplicate-parameter-names": true + } +} diff --git a/tests/no-empty-interfaces/test.ts.lint b/tests/no-empty-interfaces/test.ts.lint new file mode 100644 index 000000000..3bdfb8cc0 --- /dev/null +++ b/tests/no-empty-interfaces/test.ts.lint @@ -0,0 +1,20 @@ +interface MyInterface { + attribute: string; +} + +interface MyInterface extends First, Second { +} + +interface MyInterface extends First { +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +} +~ [0 % ('MyInterface')] + +interface MyInterface { +~~~~~~~~~~~~~~~~~~~~~~~ + // adding comments will not help you. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +} +~ [0 % ('MyInterface')] + +[0]: Do not declare empty interfaces: '%s' diff --git a/tests/no-empty-interfaces/tslint.json b/tests/no-empty-interfaces/tslint.json new file mode 100644 index 000000000..825c32380 --- /dev/null +++ b/tests/no-empty-interfaces/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-empty-interfaces": true + } +} diff --git a/tests/no-empty-line-after-opening-brace/test.ts.lint b/tests/no-empty-line-after-opening-brace/test.ts.lint new file mode 100644 index 000000000..8a035d6ca --- /dev/null +++ b/tests/no-empty-line-after-opening-brace/test.ts.lint @@ -0,0 +1,10 @@ +function () { } + +function () { +} + +function () { + +~ [Opening brace cannot be followed by empty line] +} + diff --git a/tests/no-empty-line-after-opening-brace/tslint.json b/tests/no-empty-line-after-opening-brace/tslint.json new file mode 100644 index 000000000..25ffff827 --- /dev/null +++ b/tests/no-empty-line-after-opening-brace/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-empty-line-after-opening-brace": true + } +} diff --git a/tests/no-exec-script/test.ts.lint b/tests/no-exec-script/test.ts.lint new file mode 100644 index 000000000..914a96863 --- /dev/null +++ b/tests/no-exec-script/test.ts.lint @@ -0,0 +1,19 @@ +execScript('alert("hello world")'); +~~~~~~~~~~ [0 % ('execScript')] +this.execScript('alert("hello world")'); +~~~~~~~~~~~~~~~ [0 % ('this.execScript')] +window.execScript('alert("hello world")'); +~~~~~~~~~~~~~~~~~ [0 % ('window.execScript')] +(window).execScript('alert("hello world")'); +~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('(window).execScript')] + +var a = execScript('alert("hello world")'); + ~~~~~~~~~~ [0 % ('execScript')] +var b = this.execScript('alert("hello world")'); + ~~~~~~~~~~~~~~~ [0 % ('this.execScript')] +var c = window.execScript('alert("hello world")'); + ~~~~~~~~~~~~~~~~~ [0 % ('window.execScript')] +var d = (window).execScript('alert("hello world")'); + ~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('(window).execScript')] + +[0]: forbidden execScript: %s diff --git a/tests/no-exec-script/tslint.json b/tests/no-exec-script/tslint.json new file mode 100644 index 000000000..338db4b8f --- /dev/null +++ b/tests/no-exec-script/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-exec-script": true + } +} diff --git a/tests/no-for-in/test.ts.lint b/tests/no-for-in/test.ts.lint new file mode 100644 index 000000000..6dea3376b --- /dev/null +++ b/tests/no-for-in/test.ts.lint @@ -0,0 +1,6 @@ +for (var i = 0; i < 100; i++) {} + +for (const item of array) {} + +for (name in object) {} +~~~~~~~~~~~~~~~~~~~~~~~ [Do not use the 'for in' statement: 'for (name in object)'. If this is an object, use 'Object.keys' instead. If this is an array use a standard 'for' loop instead.] diff --git a/tests/no-for-in/tslint.json b/tests/no-for-in/tslint.json new file mode 100644 index 000000000..f706d3988 --- /dev/null +++ b/tests/no-for-in/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-for-in": true + } +} diff --git a/tests/no-http-string/default/test.ts.lint b/tests/no-http-string/default/test.ts.lint new file mode 100644 index 000000000..4cc6585b8 --- /dev/null +++ b/tests/no-http-string/default/test.ts.lint @@ -0,0 +1,13 @@ +var x = 'http://www.examples.com' + ~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('http://www.examples.com')] +var x = `http://www.examples.com` + ~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('http://www.examples.com')] +var x = `http://www.${example}.com` + ~~~~~~~~~~~~~~ [0 % ('http://www.')] +function f(x : string = 'http://www.example.com/whatever') {} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('http://www.example.com/whatever')] +var x = 'https://www.microsoft.com' +var x = 'The prototcol may be http:// or https://' +function f(x : string = 'https://www.microsoft.com') {} + +[0]: Forbidden http url in string: '%s' diff --git a/tests/no-http-string/default/tslint.json b/tests/no-http-string/default/tslint.json new file mode 100644 index 000000000..ad2d8d353 --- /dev/null +++ b/tests/no-http-string/default/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-http-string": true + } +} diff --git a/tests/no-http-string/exclude/test.ts.lint b/tests/no-http-string/exclude/test.ts.lint new file mode 100644 index 000000000..dd2b8a54d --- /dev/null +++ b/tests/no-http-string/exclude/test.ts.lint @@ -0,0 +1,5 @@ +var x = "http://www.allowed.com" +var x = "http://www.notallowed.com" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('http://www.notallowed.com')] + +[0]: Forbidden http url in string: '%s' diff --git a/tests/no-http-string/exclude/tslint.json b/tests/no-http-string/exclude/tslint.json new file mode 100644 index 000000000..f383f9d31 --- /dev/null +++ b/tests/no-http-string/exclude/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-http-string": [true, "http://www.allowed.com"] + } +} diff --git a/tests/no-increment-decrement/allow-for-loops/test.ts.lint b/tests/no-increment-decrement/allow-for-loops/test.ts.lint new file mode 100644 index 000000000..66e1e868b --- /dev/null +++ b/tests/no-increment-decrement/allow-for-loops/test.ts.lint @@ -0,0 +1,15 @@ +for(let x=0; x<10; x++) {} +for(let y=10; y>=0; y--) {} + +for(let x=0; x<10; x+=1) { + x++; + ~~~ [0 % ('++')] + x--; + ~~~ [0 % ('--')] +} + +for(let x=++y; x<--y; x+=1) {} + ~~~ [0 % ('++')] + ~~~ [0 % ('--')] + +[0]: Forbidden %s operator diff --git a/tests/no-increment-decrement/allow-for-loops/tslint.json b/tests/no-increment-decrement/allow-for-loops/tslint.json new file mode 100644 index 000000000..d66806113 --- /dev/null +++ b/tests/no-increment-decrement/allow-for-loops/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-increment-decrement": [true, "allow-for-loops"] + } +} diff --git a/tests/no-increment-decrement/default/test.ts.lint b/tests/no-increment-decrement/default/test.ts.lint new file mode 100644 index 000000000..213985f5e --- /dev/null +++ b/tests/no-increment-decrement/default/test.ts.lint @@ -0,0 +1,12 @@ +var x; + +x++; +~~~ [0 % ('++')] +x--; +~~~ [0 % ('--')] +++x; +~~~ [0 % ('++')] +--x; +~~~ [0 % ('--')] + +[0]: Forbidden %s operator diff --git a/tests/no-increment-decrement/default/tslint.json b/tests/no-increment-decrement/default/tslint.json new file mode 100644 index 000000000..2c9596fd6 --- /dev/null +++ b/tests/no-increment-decrement/default/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-increment-decrement": true + } +} diff --git a/tests/no-inner-html/default/test.ts.lint b/tests/no-inner-html/default/test.ts.lint new file mode 100644 index 000000000..683221058 --- /dev/null +++ b/tests/no-inner-html/default/test.ts.lint @@ -0,0 +1,28 @@ +var foo = element.innerHTML; +var bar = element.outerHTML; +var baz = $(element).html(); +var quxFunction = $(element).html; + +element.innerHTML = '
'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [innerHTML % ("element.innerHTML = '
'")] +parent.child.innerHTML = '
'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [innerHTML % ("parent.child.innerHTML = '
'")] + +element.outerHTML = '
'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [outerHTML % ("element.outerHTML = '
'")] +parent.child.outerHTML = someVariable; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [outerHTML % ("parent.child.outerHTML = someVariable")] + +$(element).html('whatever'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [html % ("$(element).html('whatever')")] + +var myCustomObject = { + html: function (text) { + console.log('Called html with ' + text); + }, +}; +myCustomObject.html('here I am'); + +[innerHTML]: Writing a string to the innerHTML property is insecure: %s +[outerHTML]: Writing a string to the outerHTML property is insecure: %s +[html]: Using the html() function to write a string to innerHTML is insecure: %s diff --git a/tests/no-inner-html/default/tslint.json b/tests/no-inner-html/default/tslint.json new file mode 100644 index 000000000..d79008aaa --- /dev/null +++ b/tests/no-inner-html/default/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-inner-html": true + } +} diff --git a/tests/no-inner-html/html-lib-matcher/test.ts.lint b/tests/no-inner-html/html-lib-matcher/test.ts.lint new file mode 100644 index 000000000..f62e9f577 --- /dev/null +++ b/tests/no-inner-html/html-lib-matcher/test.ts.lint @@ -0,0 +1,8 @@ +cheerio(element).html('whatever'); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Using the html() function to write a string to innerHTML is insecure: cheerio(element).html('whatever')] +var myCustomObject = { + html: function (text) { + console.log('Called html with ' + text); + }, +}; +myCustomObject.html('here I am'); diff --git a/tests/no-inner-html/html-lib-matcher/tslint.json b/tests/no-inner-html/html-lib-matcher/tslint.json new file mode 100644 index 000000000..7743ee271 --- /dev/null +++ b/tests/no-inner-html/html-lib-matcher/tslint.json @@ -0,0 +1,11 @@ +{ + "rules": { + "no-inner-html": [ + true, + {}, + { + "html-lib-matcher": "cheerio|[j|J][q|Q]uery" + } + ] + } +} diff --git a/tests/no-invalid-regexp/test.ts.lint b/tests/no-invalid-regexp/test.ts.lint new file mode 100644 index 000000000..03f9eb87f --- /dev/null +++ b/tests/no-invalid-regexp/test.ts.lint @@ -0,0 +1,12 @@ +var a = new RegExp('.'); // valid constructor +var b = RegExp('.'); // this is the constructor as well +var c = this.RegExp('['); // clearly not the typescript RegExp object +var d = new RegExp(whatever); // non-string literal parameter + +new RegExp('\\') /*error Invalid regular expression: /\/: \ at end of pattern*/ + ~~~~ [0 % ('/\\/', '\\ at end of pattern')] + +RegExp('[') + ~~~ [0 % ('/[/', 'Unterminated character class')] + +[0]: Invalid regular expression: %s: %s diff --git a/tests/no-invalid-regexp/tslint.json b/tests/no-invalid-regexp/tslint.json new file mode 100644 index 000000000..c0bff59e5 --- /dev/null +++ b/tests/no-invalid-regexp/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-invalid-regexp": true + } +} diff --git a/tests/no-jquery-raw-elements/test.ts.lint b/tests/no-jquery-raw-elements/test.ts.lint new file mode 100644 index 000000000..bdeca542b --- /dev/null +++ b/tests/no-jquery-raw-elements/test.ts.lint @@ -0,0 +1,36 @@ +$("div"); + +const x = { + html: "
" + $("
").text(message).html() + "
" +} + +$("
"); + +$("
some simple content
"); + +$("
"); +$("
"); + +$("

"); // nested elements are better expressed in JQuery API +~~~~~~~~~~~~~~~~~~~~~ [complex % ('$("

")')] + +$(""); // attributes are better expressed in JQuery API +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [complex % ('$("")')] + +$(""); // default attributes are better expressed in JQuery API +~~~~~~~~~~~~~~~~~~~~~~ [complex % ('$("")')] + +$("<" + tagName + " />"); +~~~~~~~~~~~~~~~~~~~~~~~~ [string % ('$("<" + tagName + " />")')] + +$("
"); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [string % ('$("
")')] + +$(someTagOpening + content + ">"); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [string % ('$(someTagOpening + content + ">")')] + +jquery("<" + tagName + closingBits); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [string % ('jquery("<" + tagName + closingBits)')] + +[complex]: Replace complex HTML strings with jQuery API: %s +[string]: Replace HTML string manipulation with jQuery API: %s diff --git a/tests/no-jquery-raw-elements/tslint.json b/tests/no-jquery-raw-elements/tslint.json new file mode 100644 index 000000000..e82892cc7 --- /dev/null +++ b/tests/no-jquery-raw-elements/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-jquery-raw-elements": true + } +} diff --git a/tests/no-missing-visibility-modifiers/test.ts.lint b/tests/no-missing-visibility-modifiers/test.ts.lint new file mode 100644 index 000000000..84692e559 --- /dev/null +++ b/tests/no-missing-visibility-modifiers/test.ts.lint @@ -0,0 +1,36 @@ +class Class1 { + private myField1; + protected myField2; + public myField3; + private static myField4; + protected static myField5; + public static myField6; +} + +class Class2 { + private myMethod1() {}; + protected myMethod2() {}; + public myMethod3() {}; + private static myMethod4() {}; + protected static myMethod5() {}; + public static myMethod6() {}; +} + +class Class3 { + myField1; + ~~~~~~~~~ [field % ('myField1;')] + static myField2; + ~~~~~~~~~~~~~~~~ [field % ('static myField2;')] +} + +class Class4 { + myMethod1() { + ~~~~~~~~~~~~~ + }; +~~~~~ [method % ('myMethod1() {)] + static myMethod2() {}; + ~~~~~~~~~~~~~~~~~~~~~ [method % ('static myMethod2() {}')] +} + +[field]: Field missing visibility modifier: %s +[method]: Method missing visibility modifier: %s diff --git a/tests/no-missing-visibility-modifiers/tslint.json b/tests/no-missing-visibility-modifiers/tslint.json new file mode 100644 index 000000000..af9d31f49 --- /dev/null +++ b/tests/no-missing-visibility-modifiers/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-missing-visibility-modifiers": true + } +} diff --git a/tests/no-multiline-string/test.ts.lint b/tests/no-multiline-string/test.ts.lint new file mode 100644 index 000000000..021f37ce7 --- /dev/null +++ b/tests/no-multiline-string/test.ts.lint @@ -0,0 +1,6 @@ +var x = `some + ~~~~~ + multiline +~~~~~~~~~~~~~~~~~ + string`; +~~~~~~~~~~~~~~~ [Forbidden Multiline string: `some...] diff --git a/tests/no-multiline-string/tslint.json b/tests/no-multiline-string/tslint.json new file mode 100644 index 000000000..6036fbfb4 --- /dev/null +++ b/tests/no-multiline-string/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-multiline-string": true + } +} diff --git a/tests/no-multiple-var-decl/test.ts.lint b/tests/no-multiple-var-decl/test.ts.lint new file mode 100644 index 000000000..11bba6db0 --- /dev/null +++ b/tests/no-multiple-var-decl/test.ts.lint @@ -0,0 +1,13 @@ +var x = 1; +var y: number = 2; +var z = [3, 4]; +for (var i = x, j = y; i < j; i++) {} + +var x = 1, +~~~~~~~~~~ + y = 2; +~~~~~~~~~~ [0 % ('x = 1,')] +var x, y = 2, z; +~~~~~~~~~~~~~~~~ [0 % ('x,')] + +[0]: Do not use comma separated variable declarations: %s \ No newline at end of file diff --git a/tests/no-multiple-var-decl/tslint.json b/tests/no-multiple-var-decl/tslint.json new file mode 100644 index 000000000..49c1e1e6a --- /dev/null +++ b/tests/no-multiple-var-decl/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-multiple-var-decl": true + } +} diff --git a/tests/no-regex-spaces/test.ts.lint b/tests/no-regex-spaces/test.ts.lint new file mode 100644 index 000000000..191494074 --- /dev/null +++ b/tests/no-regex-spaces/test.ts.lint @@ -0,0 +1,13 @@ +var re = /foo {3}bar/; + +var re = new RegExp("foo bar"); + +var re = /foobar/; + +var re = / bar/; + ~~~~~~~ [0 % ('2')] + +var re = /bar /; + ~~~~~~~~~ [0 % ('4')] + +[0]: Spaces in regular expressions are hard to count. Use {%s} \ No newline at end of file diff --git a/tests/no-regex-spaces/tslint.json b/tests/no-regex-spaces/tslint.json new file mode 100644 index 000000000..d3975d6fe --- /dev/null +++ b/tests/no-regex-spaces/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-regex-spaces": true + } +} diff --git a/tests/no-stateless-class/test.ts.lint b/tests/no-stateless-class/test.ts.lint new file mode 100644 index 000000000..986672a79 --- /dev/null +++ b/tests/no-stateless-class/test.ts.lint @@ -0,0 +1,72 @@ +// classes with instance fields have state +class ClassWithField { + private field; +} + +// classes with instance methods have state +class ClassWithMethod { + private someMethod() { + } +} + +class ClassWithParent extends MyOtherClass { +} + +// classes that extend others have state from parent +class ClassWithParentAndInterface implements MyInterface extends MyOtherClass { +} + +class Point { + constructor(public x: number, public y: number) { } +} + +class Point { + constructor(protected x: number, protected y: number) { } +} + +class Point { + constructor(private x: number, private y: number) { } +} + +class Point { + constructor(readonly x: number, readonly y: number) { } +} + +// empty class can be a module instead +class MyClass { +~~~~~~~~~~~~~~~ +} +~ [0 % ('MyClass')] + +// empty class can be a module instead +class MyClass { +~~~~~~~~~~~~~~~ + constructor() { +~~~~~~~~~~~~~~~~~~~ + } +~~~~~ +} +~ [0 % ('MyClass')] + +class MyClass implements MyInterface { +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +} +~ [0 % ('MyClass')] + +class MyClass { +~~~~~~~~~~~~~~~ + private static field; +~~~~~~~~~~~~~~~~~~~~~~~~~ +} +~ [0 % ('MyClass')] + +class MyClass { +~~~~~~~~~~~~~~~ + private static myMethod() { +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } +~~~~~ +} +~ [0 % ('MyClass')] + +[0]: A stateless class was found. This indicates a failure in the object model: %s diff --git a/tests/no-stateless-class/tslint.json b/tests/no-stateless-class/tslint.json new file mode 100644 index 000000000..9cbd87f76 --- /dev/null +++ b/tests/no-stateless-class/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-stateless-class": true + } +} diff --git a/tests/no-suspicious-comment/default/test.ts.lint b/tests/no-suspicious-comment/default/test.ts.lint new file mode 100644 index 000000000..bcdf8695f --- /dev/null +++ b/tests/no-suspicious-comment/default/test.ts.lint @@ -0,0 +1,109 @@ +// this comment is not suspicious + +/** + * This comment + * is not suspicious. + */ + +/** + * This comment + * is not suspicious, even if it contains the word TODOlike. + */ + +/** +~~~ + * TODO: add failing example and update assertions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ +~~~ [0 % ('TODO')] + +/** +~~~ + * TODO: add failing example and update assertions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * See https://example.com/article/123 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ +~~~ [0 % ('TODO')] + +// todo add failing example and update assertions + +// BUG you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('BUG')] +// HACK you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('HACK')] +// FIXME you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('FIXME')] +// LATER you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER')] +// LATER2 you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER2')] +// TODO you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('TODO')] + +// BUG you should fix this https://example.com/article/123 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('BUG')] +// HACK you should fix this https://example.com/article/123 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('HACK')] +// FIXME you should fix this https://example.com/article/123 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('FIXME')] +// LATER you should fix this https://example.com/article/123 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER')] +// LATER2 you should fix this https://example.com/article/123 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER2')] +// TODO you should fix this https://example.com/article/123 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('TODO')] + +// BUG: you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('BUG')] +// HACK: you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('HACK')] +// FIXME: you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('FIXME')] +// LATER: you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER')] +// LATER2: you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER2')] +// TODO: you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('TODO')] + +// BUG: you should fix this https://example.com/article/123 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('BUG')] +// HACK: you should fix this https://example.com/article/123 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('HACK')] +// FIXME: you should fix this https://example.com/article/123 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('FIXME')] +// LATER: you should fix this https://example.com/article/123 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER')] +// LATER2: you should fix this https://example.com/article/123 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER2')] +// TODO: you should fix this https://example.com/article/123 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('TODO')] + +// BUG: you should fix this (see https://example.com/article/123) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('BUG')] +// HACK: you should fix this (see https://example.com/article/123) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('HACK')] +// FIXME: you should fix this (see https://example.com/article/123) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('FIXME')] +// LATER: you should fix this (see https://example.com/article/123) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER')] +// LATER2: you should fix this (see https://example.com/article/123) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER2')] +// TODO: you should fix this (see https://example.com/article/123) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('TODO')] + +// bug: you should fix this (see https://example.com/article/123) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('BUG')] +// hack: you should fix this (see https://example.com/article/123) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('HACK')] +// fixme: you should fix this (see https://example.com/article/123) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('FIXME')] +// later: you should fix this (see https://example.com/article/123) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER')] +// later2: you should fix this (see https://example.com/article/123) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER2')] +// todo: you should fix this (see https://example.com/article/123) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('TODO')] + +[0]: Suspicious comment found: %s diff --git a/tests/no-suspicious-comment/default/tslint.json b/tests/no-suspicious-comment/default/tslint.json new file mode 100644 index 000000000..467abb5b3 --- /dev/null +++ b/tests/no-suspicious-comment/default/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-suspicious-comment": true + } +} diff --git a/tests/no-suspicious-comment/exceptions/test.ts.lint b/tests/no-suspicious-comment/exceptions/test.ts.lint new file mode 100644 index 000000000..cbdb253da --- /dev/null +++ b/tests/no-suspicious-comment/exceptions/test.ts.lint @@ -0,0 +1,81 @@ +// this comment is not suspicious + +/** + * This comment + * is not suspicious. + */ + +/** + * This comment + * is not suspicious, even if it contains the word TODOlike. + */ + +/** +~~~ + * TODO: add failing example and update assertions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ +~~~ [0 % ('TODO')] + +/** + * TODO: add failing example and update assertions + * See https://example.com/article/123 + */ + +// todo add failing example and update assertions + +// BUG you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('BUG')] +// HACK you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('HACK')] +// FIXME you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('FIXME')] +// LATER you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER')] +// LATER2 you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER2')] +// TODO you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('TODO')] + +// BUG you should fix this https://example.com/article/123 +// HACK you should fix this https://example.com/article/123 +// FIXME you should fix this https://example.com/article/123 +// LATER you should fix this https://example.com/article/123 +// LATER2 you should fix this https://example.com/article/123 +// TODO you should fix this https://example.com/article/123 + +// BUG: you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('BUG')] +// HACK: you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('HACK')] +// FIXME: you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('FIXME')] +// LATER: you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER')] +// LATER2: you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('LATER2')] +// TODO: you should fix this +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ('TODO')] + +// BUG: you should fix this https://example.com/article/123 +// HACK: you should fix this https://example.com/article/123 +// FIXME: you should fix this https://example.com/article/123 +// LATER: you should fix this https://example.com/article/123 +// LATER2: you should fix this https://example.com/article/123 +// TODO: you should fix this https://example.com/article/123 + +// BUG: you should fix this (see https://example.com/article/123) +// HACK: you should fix this (see https://example.com/article/123) +// FIXME: you should fix this (see https://example.com/article/123) +// LATER: you should fix this (see https://example.com/article/123)) +// LATER2: you should fix this (see https://example.com/article/123) +// TODO: you should fix this (see https://example.com/article/123) + +// bug: you should fix this (see https://example.com/article/123) +// hack: you should fix this (see https://example.com/article/123) +// fixme: you should fix this (see https://example.com/article/123) +// later: you should fix this (see https://example.com/article/123)) +// later2: you should fix this (see https://example.com/article/123) +// todo: you should fix this (see https://example.com/article/123) + +[0]: Suspicious comment found: %s. To disable this warning, the comment should include one of the following regex: /https:\/\/example.com\/*/ diff --git a/tests/no-suspicious-comment/exceptions/tslint.json b/tests/no-suspicious-comment/exceptions/tslint.json new file mode 100644 index 000000000..dfcb2f334 --- /dev/null +++ b/tests/no-suspicious-comment/exceptions/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-suspicious-comment": [true, ["https://example.com/*"]] + } +} diff --git a/tests/no-typeof-undefined/test.ts.lint b/tests/no-typeof-undefined/test.ts.lint new file mode 100644 index 000000000..fc7c1fc8f --- /dev/null +++ b/tests/no-typeof-undefined/test.ts.lint @@ -0,0 +1,33 @@ +if(x === undefined) {} +if(x == undefined) {} +if(x === null) {} +if(x == null) {} + +if(x === 'undefined') {} +if(x == 'undefined') {} + +if(typeof x === 'object') {} +if(typeof x == 'object') {} + +if(undefined === x) {} +if(undefined == x) {} +if(null === x) {} +if(null == x) {} + +if('undefined' === x) {} +if('undefined' == x) {} + +if('object' === typeof x) {} +if('object' == typeof) {} + +if(typeof x === 'undefined') {} + ~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ("typeof x === 'undefined'")] +if('undefined' === typeof x) {} + ~~~~~~~~~~~~~~~~~~~~~~~~ [0 % ("'undefined' === typeof x")] + +if(typeof x == 'undefined') {} + ~~~~~~~~~~~~~~~~~~~~~~~ [0 % ("typeof x == 'undefined'")] +if('undefined' == typeof x) {} + ~~~~~~~~~~~~~~~~~~~~~~~ [0 % ("'undefined' == typeof x")] + +[0]: Avoid typeof x === 'undefined' comparisons. Prefer x == undefined or x === undefined: %s diff --git a/tests/no-typeof-undefined/tslint.json b/tests/no-typeof-undefined/tslint.json new file mode 100644 index 000000000..22d4d3103 --- /dev/null +++ b/tests/no-typeof-undefined/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-typeof-undefined": true + } +} diff --git a/tests/no-unexternalized-strings/signatures/test.ts.lint b/tests/no-unexternalized-strings/signatures/test.ts.lint new file mode 100644 index 000000000..2a7f48195 --- /dev/null +++ b/tests/no-unexternalized-strings/signatures/test.ts.lint @@ -0,0 +1,43 @@ +let str = 'Hello Worlds'; + +const script: string = 'let str = `Hello ${var} Worlds`;'; + +let str = localize("key", "Hello Worlds"); + +import nls = require('nls'); +let str = nls.localize("Key", "Hello World"); + +import { localize } from "nls"; +let str = localize("Key", "Hello World"); + +import nls = require("nls"); +let str = nls.localize("Key", "Hello World"); + +var nls = require("nls"); + ~~~~~ [unexternalized % ('"nls"')] +let str = nls.localize("Key", "Hello World"); + +let str = my.localize('key', "Needs localization"); + ~~~~~~~~~~~~~~~~~~~~ [unexternalized % ('"Needs localization"')] + +let str = localize('key', foo("Needs localization")); + ~~~~~~~~~~~~~~~~~~~~ [unexternalized % ('"Needs localization"')] + +let str = localize('key', this.foo("Needs localization")); + ~~~~~~~~~~~~~~~~~~~~ [unexternalized % ('"Needs localization"')] + +let str = "Needs localization"; + ~~~~~~~~~~~~~~~~~~~~ [unexternalized % ('"Needs localization"')] + +let str: string = undefined; +function foo() { + str = "Hello World"; + ~~~~~~~~~~~~~ [unexternalized % ('"Hello World"')] +} + +localize('key', "Hello " + "World"); + ~~~~~~~~ [argument] + ~~~~~~~ [argument] + +[argument]: Message argument to 'localize' must be a string literal. +[unexternalized]: Unexternalized string found: %s diff --git a/tests/no-unexternalized-strings/signatures/tslint.json b/tests/no-unexternalized-strings/signatures/tslint.json new file mode 100644 index 000000000..a77b80781 --- /dev/null +++ b/tests/no-unexternalized-strings/signatures/tslint.json @@ -0,0 +1,11 @@ +{ + "rules": { + "no-unexternalized-strings": [ + true, + { + "signatures": ["localize", "nls.localize"], + "messageIndex": 1 + } + ] + } +} From 734f485b25c1b1371fcf1035ffb3157e14a0e2f8 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 3 Dec 2018 16:43:49 -0800 Subject: [PATCH 2/2] Undid some unnecessary changes --- src/chaiPreferContainsToIndexOfRule.ts | 2 +- src/chaiVagueErrorsRule.ts | 2 +- tests/chai-prefer-contains-to-index-of/test.ts.lint | 2 +- tests/chai-vague-errors/test.ts.lint | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/chaiPreferContainsToIndexOfRule.ts b/src/chaiPreferContainsToIndexOfRule.ts index 655bcbecd..31e92dad9 100644 --- a/src/chaiPreferContainsToIndexOfRule.ts +++ b/src/chaiPreferContainsToIndexOfRule.ts @@ -5,7 +5,7 @@ import { AstUtils } from './utils/AstUtils'; import { ChaiUtils } from './utils/ChaiUtils'; import { ExtendedMetadata } from './utils/ExtendedMetadata'; -const FAILURE_STRING: string = 'Found chai call with indexOf that can be converted to .contain assertion.'; +const FAILURE_STRING: string = 'Found chai call with indexOf that can be converted to .contain assertion:'; export class Rule extends Lint.Rules.AbstractRule { public static metadata: ExtendedMetadata = { diff --git a/src/chaiVagueErrorsRule.ts b/src/chaiVagueErrorsRule.ts index 0bcf885a5..0bc9a4d89 100644 --- a/src/chaiVagueErrorsRule.ts +++ b/src/chaiVagueErrorsRule.ts @@ -7,7 +7,7 @@ import { ExtendedMetadata } from './utils/ExtendedMetadata'; const BASE_ERROR: string = 'Found chai call with vague failure message. '; const FAILURE_STRING: string = BASE_ERROR + 'Please add an explicit failure message'; const FAILURE_STRING_COMPARE_TRUE: string = - BASE_ERROR + 'Move the strict equality comparison from the expect call into the assertion value'; + BASE_ERROR + 'Move the strict equality comparison from the expect call into the assertion value.'; const FAILURE_STRING_COMPARE_FALSE: string = BASE_ERROR + 'Move the strict inequality comparison from the expect call into the assertion value'; diff --git a/tests/chai-prefer-contains-to-index-of/test.ts.lint b/tests/chai-prefer-contains-to-index-of/test.ts.lint index ccffcde6e..18e674033 100644 --- a/tests/chai-prefer-contains-to-index-of/test.ts.lint +++ b/tests/chai-prefer-contains-to-index-of/test.ts.lint @@ -21,4 +21,4 @@ expect(targetUrl.indexOf(twitterAuthUrl)).not.to.equal(-1,'...'); chai.expect(targetUrl.indexOf(twitterAuthUrl)).not.to.equal(-1,'...'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] -[0]: Found chai call with indexOf that can be converted to .contain assertion. +[0]: Found chai call with indexOf that can be converted to .contain assertion: diff --git a/tests/chai-vague-errors/test.ts.lint b/tests/chai-vague-errors/test.ts.lint index d5511875f..a5ceec98c 100644 --- a/tests/chai-vague-errors/test.ts.lint +++ b/tests/chai-vague-errors/test.ts.lint @@ -91,5 +91,5 @@ expect(something !== undefined).to.equal(true, 'something should not have been s ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [inequality] [explicit]: Found chai call with vague failure message. Please add an explicit failure message -[equality]: Found chai call with vague failure message. Move the strict equality comparison from the expect call into the assertion value +[equality]: Found chai call with vague failure message. Move the strict equality comparison from the expect call into the assertion value. [inequality]: Found chai call with vague failure message. Move the strict inequality comparison from the expect call into the assertion value