From 423bc25f2ebfa51cadf45718a4ccfb919927b3da Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Fri, 6 Mar 2020 19:51:49 +0800 Subject: [PATCH] Standard (#16) * - Linting: Apply "standard" config * - Linting (ESLint): Add `no-var` rule * - Linting: Add `prefer-destructuring` rule * - Linting: Add `object-shorthand` rule * - Use exisitng pattern in config of 2 for error * - Use `includes` over `indexOf` where possible (`prefer-includes` from unicorn config without its config) * - npm: Add `standard` to devDeps --- .eslintrc.json | 8 +- lib/index.js | 17 +- lib/rules/asserts-limit.js | 70 +-- lib/rules/complexity-it.js | 93 ++- lib/rules/disallow-stub-spy-restore-in-it.js | 59 +- lib/rules/disallow-stub-window.js | 35 +- lib/rules/disallowed-usage.js | 175 +++--- lib/rules/invalid-assertions.js | 74 +-- lib/rules/no-assertions-in-loop.js | 78 +-- lib/rules/no-assertions-outside-it.js | 63 +- lib/rules/no-empty-body.js | 36 +- lib/rules/no-empty-title.js | 42 +- lib/rules/no-eql-primitives.js | 73 ++- lib/rules/no-expressions-in-assertions.js | 196 +++--- lib/rules/no-nested-it.js | 34 +- lib/rules/no-outside-declaration.js | 39 +- lib/rules/no-same-titles.js | 89 ++- lib/utils/mocha-specs.js | 34 +- lib/utils/node.js | 193 +++--- lib/utils/obj.js | 36 +- lib/utils/options.js | 8 +- lib/utils/tests.js | 46 +- package-lock.json | 594 +++++++++++++++++- package.json | 7 +- tests/lib/rules/asserts-limit.js | 330 +++++----- tests/lib/rules/complexity-it.js | 86 +-- .../rules/disallow-stub-spy-restore-in-it.js | 97 ++- tests/lib/rules/disallow-stub-window.js | 105 ++-- tests/lib/rules/disallowed-usage.js | 98 +-- tests/lib/rules/invalid-assertions.js | 66 +- tests/lib/rules/no-assertions-in-loop.js | 90 +-- tests/lib/rules/no-assertions-outside-it.js | 93 ++- tests/lib/rules/no-empty-body.js | 93 ++- tests/lib/rules/no-empty-title.js | 59 +- tests/lib/rules/no-eql-primitives.js | 134 ++-- .../lib/rules/no-expressions-in-assertions.js | 259 ++++---- tests/lib/rules/no-nested-it.js | 62 +- tests/lib/rules/no-outside-declaration.js | 60 +- tests/lib/rules/no-same-titles.js | 75 ++- tests/lib/utils/node.js | 22 +- tests/lib/utils/obj.js | 20 +- 41 files changed, 2189 insertions(+), 1659 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index f9af7f1..4b73ee1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,9 @@ { - "extends": "eslint:recommended", + "extends": "standard", "rules": { + "no-var": [2], + "prefer-destructuring": [2], + "object-shorthand": [2], "quotes": [2, "double"] }, "overrides": [{ @@ -9,6 +12,7 @@ }], "env": { "browser": true, - "node": true + "node": true, + "es6": true } } diff --git a/lib/index.js b/lib/index.js index d351e8b..36aee18 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,18 +4,17 @@ * @copyright 2015 onechiporenko. All rights reserved. * See LICENSE file in root directory for full license. */ -"use strict"; +"use strict" -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ // Requirements -//------------------------------------------------------------------------------ -var path = require("path"); -var requireIndex = require("requireindex"); +// ------------------------------------------------------------------------------ +const path = require("path") +const requireIndex = require("requireindex") -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ // Plugin Definition -//------------------------------------------------------------------------------ - +// ------------------------------------------------------------------------------ // import all rules in lib/rules module.exports = { @@ -58,4 +57,4 @@ module.exports = { } } } -}; +} diff --git a/lib/rules/asserts-limit.js b/lib/rules/asserts-limit.js index 8cae6a3..dcb6673 100644 --- a/lib/rules/asserts-limit.js +++ b/lib/rules/asserts-limit.js @@ -4,73 +4,73 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var n = require("../utils/node.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; +const n = require("../utils/node.js") +const { isSkipSkipped } = require("../utils/options.js") -var hasOwnProperty = Object.prototype.hasOwnProperty; +const { hasOwnProperty } = Object.prototype -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { - var insideIt = false; - var assertsCounter = 0; - var options = context.options[0] || {}; - var assertsLimit = options.assertsLimit >= 1 ? options.assertsLimit : 3; - var skipSkipped = isSkipSkipped(options, context); - var ignoreZeroAssertionsIfDoneExists = hasOwnProperty.call(options, "ignoreZeroAssertionsIfDoneExists") ? options.ignoreZeroAssertionsIfDoneExists : true; - var nodeSkipped; - var doneExists; + create (context) { + let insideIt = false + let assertsCounter = 0 + const options = context.options[0] || {} + const assertsLimit = options.assertsLimit >= 1 ? options.assertsLimit : 3 + const skipSkipped = isSkipSkipped(options, context) + const ignoreZeroAssertionsIfDoneExists = hasOwnProperty.call(options, "ignoreZeroAssertionsIfDoneExists") ? options.ignoreZeroAssertionsIfDoneExists : true + let nodeSkipped + let doneExists - function check(node) { + function check (node) { if (!insideIt || nodeSkipped) { - return; + return } if (n.isAssertion(node)) { - return assertsCounter++; + return assertsCounter++ } } - function fEnter(node) { + function fEnter (node) { if (n.isTestBody(node)) { if (skipSkipped) { - nodeSkipped = n.tryDetectSkipInParent(node); + nodeSkipped = n.tryDetectSkipInParent(node) } - doneExists = node.params.length > 0; - insideIt = true; + doneExists = node.params.length > 0 + insideIt = true } } - function fExit(node) { + function fExit (node) { if (n.isTestBody(node)) { if (assertsCounter > assertsLimit) { context.report(node.parent, "Too many assertions ({{num}}). Maximum allowed is {{max}}.", { max: assertsLimit, num: assertsCounter - }); + }) } if (assertsCounter === 0 && !nodeSkipped && !(ignoreZeroAssertionsIfDoneExists && doneExists)) { - context.report(node.parent, "Test without assertions is not allowed."); + context.report(node.parent, "Test without assertions is not allowed.") } - insideIt = false; - nodeSkipped = false; - doneExists = false; - assertsCounter = 0; + insideIt = false + nodeSkipped = false + doneExists = false + assertsCounter = 0 } } return { - "FunctionExpression": fEnter, - "ArrowFunctionExpression": fEnter, + FunctionExpression: fEnter, + ArrowFunctionExpression: fEnter, "FunctionExpression:exit": fExit, "ArrowFunctionExpression:exit": fExit, - "MemberExpression": check, - "CallExpression": check - }; + MemberExpression: check, + CallExpression: check + } }, meta: { @@ -93,4 +93,4 @@ module.exports = { } ] } -}; +} diff --git a/lib/rules/complexity-it.js b/lib/rules/complexity-it.js index 01a6e6a..3cbf19d 100644 --- a/lib/rules/complexity-it.js +++ b/lib/rules/complexity-it.js @@ -5,42 +5,41 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var n = require("../utils/node.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; -var hasOwnProperty = Object.prototype.hasOwnProperty; +const n = require("../utils/node.js") +const { isSkipSkipped } = require("../utils/options.js") +const { hasOwnProperty } = Object.prototype -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { + create (context) { + let insideIt = false + let currentComplexityCount = 0 + const options = context.options[0] || {} + const maxAllowedComplexity = hasOwnProperty.call(options, "maxAllowedComplexity") ? options.maxAllowedComplexity : 40 + const skipSkipped = isSkipSkipped(options, context) + let nodeSkipped - var insideIt = false; - var currentComplexityCount = 0; - var options = context.options[0] || {}; - var maxAllowedComplexity = hasOwnProperty.call(options, "maxAllowedComplexity") ? options.maxAllowedComplexity : 40; - var skipSkipped = isSkipSkipped(options, context); - var nodeSkipped; - - function increaseComplexity() { + function increaseComplexity () { if (!insideIt) { - return; + return } if (nodeSkipped) { - return; + return } - currentComplexityCount++; + currentComplexityCount++ } function fEnter (node) { if (n.isTestBody(node)) { if (skipSkipped) { - nodeSkipped = n.tryDetectSkipInParent(node); + nodeSkipped = n.tryDetectSkipInParent(node) } - insideIt = true; + insideIt = true } } @@ -51,51 +50,51 @@ module.exports = { max: maxAllowedComplexity, num: currentComplexityCount, name: n.getCaller(node.parent) - }); + }) } - insideIt = false; - nodeSkipped = false; - currentComplexityCount = 0; + insideIt = false + nodeSkipped = false + currentComplexityCount = 0 } } return { - "FunctionExpression": fEnter, - "ArrowFunctionExpression": fEnter, + FunctionExpression: fEnter, + ArrowFunctionExpression: fEnter, "FunctionExpression:exit": fExit, "ArrowFunctionExpression:exit": fExit, - "MemberExpression": function (node) { + MemberExpression (node) { if (n.isSinonAssert(node) || n.isChaiAssert(node) || n.isChaiShould(node) || n.isChaiChainable(node)) { - return; + return } if (node.parent.type === "MemberExpression") { - return; + return } - increaseComplexity(); + increaseComplexity() }, - "CallExpression": function (node) { + CallExpression (node) { if (n.isChaiExpect(node)) { - return; + return } - increaseComplexity(); + increaseComplexity() }, - "FunctionDeclaration": increaseComplexity, - "ExpressionStatement": increaseComplexity, - "CatchClause": increaseComplexity, - "ConditionalExpression": increaseComplexity, - "LogicalExpression": increaseComplexity, - "ForStatement": increaseComplexity, - "ForInStatement": increaseComplexity, - "ForOfStatement": increaseComplexity, - "IfStatement": increaseComplexity, - "SwitchCase": increaseComplexity, - "WhileStatement": increaseComplexity, - "DoWhileStatement": increaseComplexity + FunctionDeclaration: increaseComplexity, + ExpressionStatement: increaseComplexity, + CatchClause: increaseComplexity, + ConditionalExpression: increaseComplexity, + LogicalExpression: increaseComplexity, + ForStatement: increaseComplexity, + ForInStatement: increaseComplexity, + ForOfStatement: increaseComplexity, + IfStatement: increaseComplexity, + SwitchCase: increaseComplexity, + WhileStatement: increaseComplexity, + DoWhileStatement: increaseComplexity - }; + } }, meta: { @@ -115,4 +114,4 @@ module.exports = { } ] } -}; +} diff --git a/lib/rules/disallow-stub-spy-restore-in-it.js b/lib/rules/disallow-stub-spy-restore-in-it.js index da7645a..e33ebbe 100644 --- a/lib/rules/disallow-stub-spy-restore-in-it.js +++ b/lib/rules/disallow-stub-spy-restore-in-it.js @@ -4,58 +4,57 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var obj = require("../utils/obj.js"); -var n = require("../utils/node.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; -//------------------------------------------------------------------------------ +const obj = require("../utils/obj.js") +const n = require("../utils/node.js") +const { isSkipSkipped } = require("../utils/options.js") +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { - - var disallowed = ["stub", "spy", "restore"]; - var insideTest = false; - var options = context.options[0] || {}; - var skipSkipped = isSkipSkipped(options, context); - var nodeSkipped = false; - var caller = ""; + create (context) { + const disallowed = ["stub", "spy", "restore"] + let insideTest = false + const options = context.options[0] || {} + const skipSkipped = isSkipSkipped(options, context) + let nodeSkipped = false + let caller = "" function fEnter (node) { if (n.isTestBody(node)) { if (skipSkipped) { - nodeSkipped = n.tryDetectSkipInParent(node); + nodeSkipped = n.tryDetectSkipInParent(node) } - insideTest = true; - caller = n.getCaller(node.parent); + insideTest = true + caller = n.getCaller(node.parent) } } - function fExit(node) { + function fExit (node) { if (n.isTestBody(node)) { - insideTest = false; - nodeSkipped = false; - caller = ""; + insideTest = false + nodeSkipped = false + caller = "" } } return { - "FunctionExpression": fEnter, - "ArrowFunctionExpression": fEnter, + FunctionExpression: fEnter, + ArrowFunctionExpression: fEnter, "FunctionExpression:exit": fExit, "ArrowFunctionExpression:exit": fExit, - "CallExpression[callee]": function (node) { - var callee = obj.get(node, "callee"); - var _c = n.cleanCaller(n.getCaller(callee)).split(".").pop(); - if (insideTest && disallowed.indexOf(_c) !== -1 && !nodeSkipped) { - context.report(node, "`{{name}}` is not allowed to use inside `{{caller}}`.", {name: _c, caller: caller}); + "CallExpression[callee]" (node) { + const callee = obj.get(node, "callee") + const _c = n.cleanCaller(n.getCaller(callee)).split(".").pop() + if (insideTest && disallowed.includes(_c) && !nodeSkipped) { + context.report(node, "`{{name}}` is not allowed to use inside `{{caller}}`.", { name: _c, caller }) } } - }; + } }, meta: { @@ -72,4 +71,4 @@ module.exports = { } ] } -}; +} diff --git a/lib/rules/disallow-stub-window.js b/lib/rules/disallow-stub-window.js index 60a1b75..b8b8b27 100644 --- a/lib/rules/disallow-stub-window.js +++ b/lib/rules/disallow-stub-window.js @@ -4,38 +4,37 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var n = require("../utils/node.js"); -var obj = require("../utils/obj.js"); +const n = require("../utils/node.js") +const obj = require("../utils/obj.js") -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { + create (context) { + const m = "`sinon.stub` should not be used for `window.{{methodName}}`" - var m = "`sinon.stub` should not be used for `window.{{methodName}}`"; - - var options = context.options[0] || {}; - var methods = options.methods; + const options = context.options[0] || {} + const { methods } = options return { - "CallExpression": function (node) { + CallExpression (node) { if (!n.isSinonStub(node)) { - return; + return } if (obj.get(node, "arguments.0.name") !== "window") { - return; + return } - var methodName = obj.get(node, "arguments.1.value"); - if (methods.indexOf(methodName) !== -1) { - context.report(node, m, {methodName: methodName}); + const methodName = obj.get(node, "arguments.1.value") + if (methods.includes(methodName)) { + context.report(node, m, { methodName }) } } - }; + } }, meta: { @@ -58,4 +57,4 @@ module.exports = { } ] } -}; +} diff --git a/lib/rules/disallowed-usage.js b/lib/rules/disallowed-usage.js index 00a46b1..d469d95 100644 --- a/lib/rules/disallowed-usage.js +++ b/lib/rules/disallowed-usage.js @@ -4,125 +4,124 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var n = require("../utils/node.js"); -var obj = require("../utils/obj.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; -var hasOwnProperty = Object.prototype.hasOwnProperty; -//------------------------------------------------------------------------------ +const n = require("../utils/node.js") +const obj = require("../utils/obj.js") +const { isSkipSkipped } = require("../utils/options.js") +const { hasOwnProperty } = Object.prototype +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ -function prepareCallers(parts) { - var ret = []; +function prepareCallers (parts) { + const ret = [] parts.forEach(function (c) { if (hasOwnProperty.call(c, "f")) { - return ret.push(c.f); + return ret.push(c.f) } if (hasOwnProperty.call(c, "m") && hasOwnProperty.call(c, "o")) { c.m.forEach(function (_m) { - return ret.push(c.o + "." + _m); - }); + return ret.push(c.o + "." + _m) + }) } if (hasOwnProperty.call(c, "p") && hasOwnProperty.call(c, "o")) { c.p.forEach(function (_p) { - ret.push(c.o + "." + _p); - }); + ret.push(c.o + "." + _p) + }) } - }); - return ret; + }) + return ret } -function prepareProperties(parts) { - var ret = []; +function prepareProperties (parts) { + const ret = [] parts.forEach(function (c) { if (hasOwnProperty.call(c, "p") && hasOwnProperty.call(c, "o")) { c.p.forEach(function (_p) { - ret.push(c.o + "." + _p); - }); + ret.push(c.o + "." + _p) + }) } - }); - return ret; + }) + return ret } module.exports = { - create: function (context) { - - var insideTest = false; - var insideHook = false; - var options = context.options[0]; + create (context) { + let insideTest = false + let insideHook = false + const [options] = context.options if (!options) { - return {}; + return {} } - var skipSkipped = isSkipSkipped(options, context); - var disallowedMethodsInTests = hasOwnProperty.call(options, "test") ? prepareCallers(options.test) : []; - var disallowedPropertiesInTests = hasOwnProperty.call(options, "test") ? prepareProperties(options.test) : []; - var disallowedMethodsInHooks = hasOwnProperty.call(options, "hook") ? prepareCallers(options.hook) : []; - var disallowedPropertiesInHooks = hasOwnProperty.call(options, "hook") ? prepareProperties(options.hook) : []; + const skipSkipped = isSkipSkipped(options, context) + const disallowedMethodsInTests = hasOwnProperty.call(options, "test") ? prepareCallers(options.test) : [] + const disallowedPropertiesInTests = hasOwnProperty.call(options, "test") ? prepareProperties(options.test) : [] + const disallowedMethodsInHooks = hasOwnProperty.call(options, "hook") ? prepareCallers(options.hook) : [] + const disallowedPropertiesInHooks = hasOwnProperty.call(options, "hook") ? prepareProperties(options.hook) : [] - function detect(flag, disallowed, caller, node) { - return flag && disallowed.indexOf(caller) !== -1 && !(skipSkipped && n.tryDetectSkipInParent(node)); + function detect (flag, disallowed, caller, node) { + return flag && disallowed.includes(caller) && !(skipSkipped && n.tryDetectSkipInParent(node)) } - function fEnter(node) { + function fEnter (node) { if (n.isTestBody(node)) { - insideTest = true; + insideTest = true } if (n.isHookBody(node)) { - insideHook = true; + insideHook = true } } - function fExit(node) { + function fExit (node) { if (n.isTestBody(node)) { - insideTest = false; + insideTest = false } if (n.isHookBody(node)) { - insideHook = false; + insideHook = false } } return { - "FunctionExpression": fEnter, - "ArrowFunctionExpression": fEnter, + FunctionExpression: fEnter, + ArrowFunctionExpression: fEnter, "FunctionExpression:exit": fExit, "ArrowFunctionExpression:exit": fExit, - "CallExpression": function (node) { - var parent = obj.get(node, "parent"); + CallExpression (node) { + const parent = obj.get(node, "parent") /* istanbul ignore if */ if (!parent) { - return; + return } - var caller = n.cleanCaller(n.getCaller(node)); + const caller = n.cleanCaller(n.getCaller(node)) /* istanbul ignore if */ if (!caller) { - return; + return } if (detect(insideTest, disallowedMethodsInTests, caller, node)) { - context.report(node, "`{{caller}}` is not allowed here.", {caller: caller}); + context.report(node, "`{{caller}}` is not allowed here.", { caller }) } if (detect(insideHook, disallowedMethodsInHooks, caller, node)) { - context.report(node, "`{{caller}}` is not allowed here.", {caller: caller}); + context.report(node, "`{{caller}}` is not allowed here.", { caller }) } }, - "MemberExpression": function (node) { - var parent = obj.get(node, "parent"); + MemberExpression (node) { + const parent = obj.get(node, "parent") /* istanbul ignore if */ if (!parent) { - return; + return } - if (parent.type === "CallExpression" && parent.arguments.indexOf(node) === -1) { - return; + if (parent.type === "CallExpression" && !parent.arguments.includes(node)) { + return } - var caller = n.cleanCaller(n.getCaller(node)); + const caller = n.cleanCaller(n.getCaller(node)) if (detect(insideTest, disallowedPropertiesInTests, caller, node)) { - context.report(node, "`{{caller}}` is not allowed here.", {caller: caller}); + context.report(node, "`{{caller}}` is not allowed here.", { caller }) } if (detect(insideHook, disallowedPropertiesInHooks, caller, node)) { - context.report(node, "`{{caller}}` is not allowed here.", {caller: caller}); + context.report(node, "`{{caller}}` is not allowed here.", { caller }) } } - }; + } }, meta: { @@ -136,27 +135,27 @@ module.exports = { item: { type: "object", properties: { - "o": { + o: { type: "string" }, - "m": { - "type": "array", - "items": { - "type": "string" + m: { + type: "array", + items: { + type: "string" }, - "minItems": 1, - "uniqueItems": true + minItems: 1, + uniqueItems: true }, - "f": { + f: { type: "string" }, - "p": { - "type": "array", - "items": { - "type": "string" + p: { + type: "array", + items: { + type: "string" }, - "minItems": 1, - "uniqueItems": true + minItems: 1, + uniqueItems: true } } } @@ -165,27 +164,27 @@ module.exports = { type: "array", item: { properties: { - "o": { + o: { type: "string" }, - "m": { - "type": "array", - "items": { - "type": "string" + m: { + type: "array", + items: { + type: "string" }, - "minItems": 1, - "uniqueItems": true + minItems: 1, + uniqueItems: true }, - "f": { + f: { type: "string" }, - "p": { - "type": "array", - "items": { - "type": "string" + p: { + type: "array", + items: { + type: "string" }, - "minItems": 1, - "uniqueItems": true + minItems: 1, + uniqueItems: true } } } @@ -198,4 +197,4 @@ module.exports = { } ] } -}; +} diff --git a/lib/rules/invalid-assertions.js b/lib/rules/invalid-assertions.js index 7fc8663..a2e17f6 100644 --- a/lib/rules/invalid-assertions.js +++ b/lib/rules/invalid-assertions.js @@ -4,75 +4,75 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var n = require("../utils/node.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; -//------------------------------------------------------------------------------ +const n = require("../utils/node.js") +const { isSkipSkipped } = require("../utils/options.js") +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { - var m = "Invalid assertion usage."; - var insideIt = false; - var options = context.options[0] || {}; - var skipSkipped = isSkipSkipped(options, context); - var nodeSkipped; + create (context) { + const m = "Invalid assertion usage." + let insideIt = false + const options = context.options[0] || {} + const skipSkipped = isSkipSkipped(options, context) + let nodeSkipped - function check(node) { + function check (node) { if (!insideIt || nodeSkipped) { - return; + return } if (n.isAssertion(node)) { - var parentExpression = n.getParentExpression(node); + const parentExpression = n.getParentExpression(node) /* istanbul ignore if */ if (!parentExpression) { - return; + return } - var caller = n.getCaller(parentExpression.expression) || + const caller = n.getCaller(parentExpression.expression) || /* istanbul ignore next */ - ""; - if (["expect", "chai.expect"].indexOf(caller) !== -1) { - return context.report(node, m); + "" + if (["expect", "chai.expect"].includes(caller)) { + return context.report(node, m) } - var should = "should"; - if (caller.indexOf(should, caller.length - should.length) !== -1) { - return context.report(node, m); + const should = "should" + if (caller.includes(should, caller.length - should.length)) { + return context.report(node, m) } n.chaiChainable.forEach(function (c) { - var _c = "." + c; - if (caller.indexOf(_c, caller.length - _c.length) !== -1) { - context.report(node, m); + const _c = "." + c + if (caller.includes(_c, caller.length - _c.length)) { + context.report(node, m) } - }); + }) } } - function fEnter(node) { + function fEnter (node) { if (n.isTestBody(node)) { if (skipSkipped) { - nodeSkipped = n.tryDetectSkipInParent(node); + nodeSkipped = n.tryDetectSkipInParent(node) } - insideIt = true; + insideIt = true } } - function fExit(node) { + function fExit (node) { if (n.isTestBody(node)) { - insideIt = false; - nodeSkipped = false; + insideIt = false + nodeSkipped = false } } return { - "FunctionExpression": fEnter, - "ArrowFunctionExpression": fEnter, + FunctionExpression: fEnter, + ArrowFunctionExpression: fEnter, "FunctionExpression:exit": fExit, "ArrowFunctionExpression:exit": fExit, - "CallExpression": check, - "MemberExpression": check - }; + CallExpression: check, + MemberExpression: check + } }, meta: { diff --git a/lib/rules/no-assertions-in-loop.js b/lib/rules/no-assertions-in-loop.js index db4f532..ffa7e27 100644 --- a/lib/rules/no-assertions-in-loop.js +++ b/lib/rules/no-assertions-in-loop.js @@ -4,92 +4,92 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var n = require("../utils/node.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; -var hasOwnProperty = Object.prototype.hasOwnProperty; -//------------------------------------------------------------------------------ +const n = require("../utils/node.js") +const { isSkipSkipped } = require("../utils/options.js") +const { hasOwnProperty } = Object.prototype +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { - var loopStatements = ["WhileStatement", "DoWhileStatement", "ForStatement", "ForInStatement", "ForOfStatement"]; - var insideIt = false; - var options = context.options[0] || {}; - var skipSkipped = isSkipSkipped(options, context); - var extraMemberExpression = hasOwnProperty.call(options, "extraMemberExpression") ? options.extraMemberExpression : []; - var nodeSkipped; + create (context) { + const loopStatements = ["WhileStatement", "DoWhileStatement", "ForStatement", "ForInStatement", "ForOfStatement"] + let insideIt = false + const options = context.options[0] || {} + const skipSkipped = isSkipSkipped(options, context) + const extraMemberExpression = hasOwnProperty.call(options, "extraMemberExpression") ? options.extraMemberExpression : [] + let nodeSkipped - function detectParentLoopInTest(node) { + function detectParentLoopInTest (node) { /* istanbul ignore if */ if (!node) { - return false; + return false } if (n.isTestBody(node)) { - return false; + return false } - var caller = "" + n.getCaller(node); - var isExtra = false; + const caller = "" + n.getCaller(node) + let isExtra = false extraMemberExpression.forEach(function (str) { - if (caller.indexOf(str, caller.length - str.length) !== -1) { - isExtra = true; + if (caller.includes(str, caller.length - str.length)) { + isExtra = true } - }); - if (isExtra || loopStatements.indexOf(node.type) !== -1) { - return true; + }) + if (isExtra || loopStatements.includes(node.type)) { + return true } - return detectParentLoopInTest(node.parent); + return detectParentLoopInTest(node.parent) } - function fEnter(node) { + function fEnter (node) { if (n.isTestBody(node)) { if (skipSkipped) { - nodeSkipped = n.tryDetectSkipInParent(node); + nodeSkipped = n.tryDetectSkipInParent(node) } - insideIt = true; + insideIt = true } } - function fExit(node) { + function fExit (node) { if (n.isTestBody(node)) { - insideIt = false; - nodeSkipped = false; + insideIt = false + nodeSkipped = false } } return { - "FunctionExpression": fEnter, - "ArrowFunctionExpression": fEnter, + FunctionExpression: fEnter, + ArrowFunctionExpression: fEnter, "FunctionExpression:exit": fExit, "ArrowFunctionExpression:exit": fExit, - "MemberExpression": function (node) { + MemberExpression (node) { if (!insideIt || nodeSkipped) { - return; + return } if (n.isSinonAssert(node) || n.isChaiAssert(node) || n.isChaiShould(node)) { if (detectParentLoopInTest(node.parent)) { - context.report(node, "Assertions should not be used in loops."); + context.report(node, "Assertions should not be used in loops.") } } }, - "CallExpression": function (node) { + CallExpression (node) { if (!insideIt || nodeSkipped) { - return; + return } if (n.isChaiExpect(node) || n.isChaiAssert(node)) { if (detectParentLoopInTest(node.parent)) { - context.report(node, "Assertions should not be used in loops."); + context.report(node, "Assertions should not be used in loops.") } } } - }; + } }, meta: { diff --git a/lib/rules/no-assertions-outside-it.js b/lib/rules/no-assertions-outside-it.js index fdb0d16..a6fc449 100644 --- a/lib/rules/no-assertions-outside-it.js +++ b/lib/rules/no-assertions-outside-it.js @@ -4,70 +4,69 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var n = require("../utils/node.js"); -var m = require("../utils/mocha-specs.js"); -var obj = require("../utils/obj.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; -//------------------------------------------------------------------------------ +const n = require("../utils/node.js") +const m = require("../utils/mocha-specs.js") +const obj = require("../utils/obj.js") +const { isSkipSkipped } = require("../utils/options.js") +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { + create (context) { + let insideIt = false + const options = context.options[0] || {} + const skipSkipped = isSkipSkipped(options, context) - var insideIt = false; - var options = context.options[0] || {}; - var skipSkipped = isSkipSkipped(options, context); + const message = "Assertion outside tests is not allowed." - var message = "Assertion outside tests is not allowed."; - - function check(node) { + function check (node) { if (!insideIt && n.isAssertion(node) && !(skipSkipped && n.tryDetectSkipInParent(node))) { - var parentNode = node.parent; - var types = ["FunctionExpression", "ArrowFunctionExpression"]; + let parentNode = node.parent + const types = ["FunctionExpression", "ArrowFunctionExpression"] while (parentNode) { - var type = parentNode.type; + const { type } = parentNode if (type === "FunctionDeclaration") { - return; + return } - if (types.indexOf(type) !== -1) { - var caller = n.getCaller(parentNode.parent); + if (types.includes(type)) { + const caller = n.getCaller(parentNode.parent) if (!caller) { - return; + return } - if (m.allSuites.indexOf(caller) !== -1 || obj.get(parentNode, "parent.arguments.1") === parentNode) { - return context.report(node.parent, message); + if (m.allSuites.includes(caller) || obj.get(parentNode, "parent.arguments.1") === parentNode) { + return context.report(node.parent, message) } } - parentNode = parentNode.parent; + parentNode = parentNode.parent } - return context.report(node.parent, message); + return context.report(node.parent, message) } } function fEnter (node) { if (n.isTestBody(node)) { - insideIt = true; + insideIt = true } } function fExit (node) { if (n.isTestBody(node)) { - insideIt = false; + insideIt = false } } return { - "FunctionExpression": fEnter, - "ArrowFunctionExpression": fEnter, + FunctionExpression: fEnter, + ArrowFunctionExpression: fEnter, "FunctionExpression:exit": fExit, "ArrowFunctionExpression:exit": fExit, - "MemberExpression": check, - "CallExpression": check - }; + MemberExpression: check, + CallExpression: check + } }, meta: { diff --git a/lib/rules/no-empty-body.js b/lib/rules/no-empty-body.js index 3f9f2af..1a8a70b 100644 --- a/lib/rules/no-empty-body.js +++ b/lib/rules/no-empty-body.js @@ -4,39 +4,39 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var n = require("../utils/node.js"); -var obj = require("../utils/obj.js"); -var mocha = require("../utils/mocha-specs.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; -var toCheck = mocha.all.concat(mocha.hooks); +const n = require("../utils/node.js") +const obj = require("../utils/obj.js") +const mocha = require("../utils/mocha-specs.js") +const { isSkipSkipped } = require("../utils/options.js") +const toCheck = mocha.all.concat(mocha.hooks) -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { - var options = context.options[0] || {}; - var skipSkipped = isSkipSkipped(options, context); + create (context) { + const options = context.options[0] || {} + const skipSkipped = isSkipSkipped(options, context) function fEnter (node) { if (skipSkipped && n.tryDetectSkipInParent(node)) { - return; + return } - var caller = n.getCaller(node.parent); - if (toCheck.indexOf(caller) !== -1) { + const caller = n.getCaller(node.parent) + if (toCheck.includes(caller)) { if (!obj.get(node, "body.body.length")) { - context.report(node, "Empty function is not allowed here."); + context.report(node, "Empty function is not allowed here.") } } } return { - "FunctionExpression": fEnter, - "ArrowFunctionExpression": fEnter - }; + FunctionExpression: fEnter, + ArrowFunctionExpression: fEnter + } }, meta: { diff --git a/lib/rules/no-empty-title.js b/lib/rules/no-empty-title.js index 1b22b23..23d82f7 100644 --- a/lib/rules/no-empty-title.js +++ b/lib/rules/no-empty-title.js @@ -4,43 +4,41 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var obj = require("../utils/obj.js"); -var n = require("../utils/node.js"); -var mocha = require("../utils/mocha-specs.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; -//------------------------------------------------------------------------------ +const obj = require("../utils/obj.js") +const n = require("../utils/node.js") +const mocha = require("../utils/mocha-specs.js") +const { isSkipSkipped } = require("../utils/options.js") +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { - - var options = context.options[0] || {}; - var skipSkipped = isSkipSkipped(options, context); + create (context) { + const options = context.options[0] || {} + const skipSkipped = isSkipSkipped(options, context) return { - "CallExpression": function (node) { - var caller = n.getCaller(node); - if (!caller || mocha.all.indexOf(caller) === -1) { - return; + CallExpression (node) { + const caller = n.getCaller(node) + if (!caller || !mocha.all.includes(caller)) { + return } - if (skipSkipped && (mocha.allSkipped.indexOf(caller) !== -1 || n.tryDetectSkipInParent(node))) { - return; + if (skipSkipped && (mocha.allSkipped.includes(caller) || n.tryDetectSkipInParent(node))) { + return } - var firstArgType = obj.get(node, "arguments.0.type"); + const firstArgType = obj.get(node, "arguments.0.type") if (firstArgType === "Literal") { - var title = "" + obj.get(node, "arguments.0.value") || ""; + const title = "" + obj.get(node, "arguments.0.value") || "" if (!title.trim()) { - context.report(node, "Empty title is not allowed for `{{name}}`.", {name: caller}); + context.report(node, "Empty title is not allowed for `{{name}}`.", { name: caller }) } } - } - }; + } }, meta: { diff --git a/lib/rules/no-eql-primitives.js b/lib/rules/no-eql-primitives.js index f4db4c4..5094116 100644 --- a/lib/rules/no-eql-primitives.js +++ b/lib/rules/no-eql-primitives.js @@ -4,87 +4,86 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var n = require("../utils/node.js"); -var obj = require("../utils/obj.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; -//------------------------------------------------------------------------------ +const n = require("../utils/node.js") +const obj = require("../utils/obj.js") +const { isSkipSkipped } = require("../utils/options.js") +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { + create (context) { + const options = context.options[0] || {} + const skipSkipped = isSkipSkipped(options, context) + const strictCheck = ["assert.deepEqual", "assert.notDeepEqual"] + const notStrictCheck = [".eql", ".deep.equal"] + let insideTest = false - var options = context.options[0] || {}; - var skipSkipped = isSkipSkipped(options, context); - var strictCheck = ["assert.deepEqual", "assert.notDeepEqual"]; - var notStrictCheck = [".eql", ".deep.equal"]; - var insideTest = false; - - function isPrimitive(arg) { - var type = obj.getType(arg.value); - return ["string", "number", "boolean", "null"].indexOf(type) !== -1; + function isPrimitive (arg) { + const type = obj.getType(arg.value) + return ["string", "number", "boolean", "null"].includes(type) } function fEnter (node) { if (n.isTestBody(node)) { - insideTest = true; + insideTest = true } } function fExit (node) { if (n.isTestBody(node)) { - insideTest = false; + insideTest = false } } return { - "FunctionExpression": fEnter, - "ArrowFunctionExpression": fEnter, + FunctionExpression: fEnter, + ArrowFunctionExpression: fEnter, "FunctionExpression:exit": fExit, "ArrowFunctionExpression:exit": fExit, - "MemberExpression": function (node) { + MemberExpression (node) { if (insideTest && !(skipSkipped && n.tryDetectSkipInParent(node))) { - var caller = n.getCaller(node); + const caller = n.getCaller(node) /* istanbul ignore if */ if (!caller) { - return; + return } - var args; + let args // check as assert.* - if (strictCheck.indexOf(caller) !== -1) { - args = obj.get(node, "parent.arguments"); + if (strictCheck.includes(caller)) { + args = obj.get(node, "parent.arguments") if (args.length > 1 && args[1].type === "Literal") { if (isPrimitive(args[1])) { - context.report(node, "`{{caller}}` should not be used with primitives.", {caller: caller}); + context.report(node, "`{{caller}}` should not be used with primitives.", { caller }) } } - return; + return } // check as *.eql // Because of chai expect/should logic, MemberExpression may be pretty long. // So, there is not no sense to get it full. We just can check if it ends with needed substring - var toCheck = false; - var _caller = ""; // used in the report-message + let toCheck = false + let _caller = "" // used in the report-message notStrictCheck.forEach(function (str) { - if (caller.indexOf(str, caller.length - str.length) !== -1) { // endWith -> `some.eql` ends with `.eql` - _caller = str; - toCheck = true; + if (caller.includes(str, caller.length - str.length)) { // endWith -> `some.eql` ends with `.eql` + _caller = str + toCheck = true } - }); + }) if (toCheck) { - args = obj.get(node, "parent.arguments"); + args = obj.get(node, "parent.arguments") if (args.length > 0 && args[0].type === "Literal") { if (isPrimitive(args[0])) { - context.report(node, "`{{caller}}` should not be used with primitives.", {caller: _caller}); + context.report(node, "`{{caller}}` should not be used with primitives.", { caller: _caller }) } } } } } - }; + } }, meta: { diff --git a/lib/rules/no-expressions-in-assertions.js b/lib/rules/no-expressions-in-assertions.js index e88a75d..f104d53 100644 --- a/lib/rules/no-expressions-in-assertions.js +++ b/lib/rules/no-expressions-in-assertions.js @@ -4,30 +4,30 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var n = require("../utils/node.js"); -var obj = require("../utils/obj.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; -//------------------------------------------------------------------------------ +const n = require("../utils/node.js") +const obj = require("../utils/obj.js") +const { isSkipSkipped } = require("../utils/options.js") +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { - var insideIt = false; - var options = context.options[0] || {}; - var skipSkipped = isSkipSkipped(options, context); - var nodeSkipped; - var replacementsOnly = options.replacementsOnly; + create (context) { + let insideIt = false + const options = context.options[0] || {} + const skipSkipped = isSkipSkipped(options, context) + let nodeSkipped + const { replacementsOnly } = options - var defaultMessage = "Expression should not be used here."; - var detailedMessage = "`{{shouldUse}}` should be used."; - var emptyArgMessage = "Empty assertion is not allowed."; + const defaultMessage = "Expression should not be used here." + const detailedMessage = "`{{shouldUse}}` should be used." + const emptyArgMessage = "Empty assertion is not allowed." - var typesToReportAsDefault = ["ConditionalExpression", "UnaryExpression", "LogicalExpression", "UpdateExpression"]; + const typesToReportAsDefault = ["ConditionalExpression", "UnaryExpression", "LogicalExpression", "UpdateExpression"] - var binaryMapForExpect = { + const binaryMapForExpect = { "===": ".to.be.equal", "!==": ".to.be.not.equal", "==": ".to.be.equal", @@ -36,10 +36,10 @@ module.exports = { ">": ".to.be.above", "<=": ".to.be.most", "<": ".to.be.below", - "instanceof": ".to.be.instanceof" - }; + instanceof: ".to.be.instanceof" + } - var binaryMapForAssert = { + const binaryMapForAssert = { "===": ".strictEqual", "!==": ".notStrictEqual", "==": ".equal", @@ -48,7 +48,7 @@ module.exports = { ">": ".isAbove", "<=": ".isAtMost", "<": ".isBelow" - }; + } /** * @@ -56,28 +56,28 @@ module.exports = { * @param {ASTNode} node * @returns {*} */ - function checkBinaryInExpect(binaryExpression, node) { - var eqls = ["===", "==", "!==", "!="]; - var op = binaryExpression.operator; - var shouldUse = binaryMapForExpect[op]; + function checkBinaryInExpect (binaryExpression, node) { + const eqls = ["===", "==", "!==", "!="] + const op = binaryExpression.operator + const shouldUse = binaryMapForExpect[op] if (shouldUse) { - if (eqls.indexOf(op) === -1) { - return context.report(node, detailedMessage, {shouldUse: shouldUse}); + if (!eqls.includes(op)) { + return context.report(node, detailedMessage, { shouldUse }) } - var primitives = [null, true, false]; - for (var i = 0; i < primitives.length; i++) { + const primitives = [null, true, false] + for (let i = 0; i < primitives.length; i++) { if (checkForValueInExpect(binaryExpression, op, node, primitives[i])) { - return; + return } } if (checkForUndefinedInExpect(binaryExpression, op, node)) { - return; + return } - return context.report(node, detailedMessage, {shouldUse: shouldUse}); + return context.report(node, detailedMessage, { shouldUse }) } if (!replacementsOnly) { - return context.report(node, defaultMessage); + return context.report(node, defaultMessage) } } @@ -89,13 +89,13 @@ module.exports = { * @param {*} value * @returns {boolean} */ - function checkForValueInExpect(binaryExpression, op, node, value) { - var shouldUse = ".to." + (op[0] === "!" ? "not." : "") + "be." + value; + function checkForValueInExpect (binaryExpression, op, node, value) { + const shouldUse = ".to." + (op[0] === "!" ? "not." : "") + "be." + value if (obj.get(binaryExpression, "left.value") === value || obj.get(binaryExpression, "right.value") === value) { - context.report(node, detailedMessage, {shouldUse: shouldUse}); - return true; + context.report(node, detailedMessage, { shouldUse }) + return true } - return false; + return false } /** @@ -105,13 +105,13 @@ module.exports = { * @param {ASTNode} node * @returns {boolean} */ - function checkForUndefinedInExpect(binaryExpression, op, node) { - var shouldUse = ".to." + (op[0] === "!" ? "not." : "") + "be.undefined"; + function checkForUndefinedInExpect (binaryExpression, op, node) { + const shouldUse = ".to." + (op[0] === "!" ? "not." : "") + "be.undefined" if (obj.get(binaryExpression, "left.name") === "undefined" || obj.get(binaryExpression, "right.name") === "undefined") { - context.report(node, detailedMessage, {shouldUse: shouldUse}); - return true; + context.report(node, detailedMessage, { shouldUse }) + return true } - return false; + return false } /** @@ -119,28 +119,28 @@ module.exports = { * @param {ASTNode} binaryExpression * @param {ASTNode} node */ - function checkBinaryInAssert(binaryExpression, node) { - var eqls = ["===", "==", "!==", "!="]; - var op = binaryExpression.operator; - var shouldUse = binaryMapForAssert[op]; + function checkBinaryInAssert (binaryExpression, node) { + const eqls = ["===", "==", "!==", "!="] + const op = binaryExpression.operator + const shouldUse = binaryMapForAssert[op] if (shouldUse) { - if (eqls.indexOf(op) === -1) { - return context.report(node, detailedMessage, {shouldUse: shouldUse}); + if (!eqls.includes(op)) { + return context.report(node, detailedMessage, { shouldUse }) } - var primitives = [null, true, false]; - for (var i = 0; i < primitives.length; i++) { + const primitives = [null, true, false] + for (let i = 0; i < primitives.length; i++) { if (checkForValueAssert(binaryExpression, op, node, primitives[i])) { - return; + return } } if (checkForUndefinedAssert(binaryExpression, op, node)) { - return; + return } - return context.report(node, detailedMessage, {shouldUse: shouldUse}); + return context.report(node, detailedMessage, { shouldUse }) } if (!replacementsOnly) { - return context.report(node, defaultMessage); + return context.report(node, defaultMessage) } } @@ -152,14 +152,14 @@ module.exports = { * @param {*} value * @returns {boolean} */ - function checkForValueAssert(binaryExpression, op, node, value) { - var _value = "" + value; - var shouldUse = ".is" + (op[0] === "!" ? "Not" : "") + _value.charAt(0).toUpperCase() + _value.slice(1); + function checkForValueAssert (binaryExpression, op, node, value) { + const _value = "" + value + const shouldUse = ".is" + (op[0] === "!" ? "Not" : "") + _value.charAt(0).toUpperCase() + _value.slice(1) if (obj.get(binaryExpression, "left.value") === value || obj.get(binaryExpression, "right.value") === value) { - context.report(node, detailedMessage, {shouldUse: shouldUse}); - return true; + context.report(node, detailedMessage, { shouldUse }) + return true } - return false; + return false } /** @@ -169,91 +169,91 @@ module.exports = { * @param {ASTNode} node * @returns {boolean} */ - function checkForUndefinedAssert(binaryExpression, op, node) { - var shouldUse = op[0] === "!" ? ".isDefined" : ".isUndefined"; + function checkForUndefinedAssert (binaryExpression, op, node) { + const shouldUse = op[0] === "!" ? ".isDefined" : ".isUndefined" if (obj.get(binaryExpression, "left.name") === "undefined" || obj.get(binaryExpression, "right.name") === "undefined") { - context.report(node, detailedMessage, {shouldUse: shouldUse}); - return true; + context.report(node, detailedMessage, { shouldUse }) + return true } - return false; + return false } function fEnter (node) { if (n.isTestBody(node)) { if (skipSkipped) { - nodeSkipped = n.tryDetectSkipInParent(node); + nodeSkipped = n.tryDetectSkipInParent(node) } - insideIt = true; + insideIt = true } } function fExit (node) { if (n.isTestBody(node)) { - insideIt = false; - nodeSkipped = false; + insideIt = false + nodeSkipped = false } } - function dontReport(arg) { - return replacementsOnly || arg.operator === "typeof"; + function dontReport (arg) { + return replacementsOnly || arg.operator === "typeof" } return { - "FunctionExpression": fEnter, - "ArrowFunctionExpression": fEnter, + FunctionExpression: fEnter, + ArrowFunctionExpression: fEnter, "FunctionExpression:exit": fExit, "ArrowFunctionExpression:exit": fExit, - "CallExpression": function (node) { + CallExpression (node) { if (!insideIt || nodeSkipped) { - return; + return } - var arg; - var isChaiExpect = n.isChaiExpect(node); - var isChaiAssert = n.isChaiAssert(node); + let arg + const isChaiExpect = n.isChaiExpect(node) + const isChaiAssert = n.isChaiAssert(node) if (isChaiAssert) { - arg = obj.get(node, "arguments.0"); + arg = obj.get(node, "arguments.0") if (!arg) { - return context.report(node, emptyArgMessage); + return context.report(node, emptyArgMessage) } if (arg.type === "BinaryExpression") { - return checkBinaryInAssert(arg, node); + return checkBinaryInAssert(arg, node) } - if (typesToReportAsDefault.indexOf(arg.type) !== -1 && !dontReport(arg)) { - return context.report(node, defaultMessage); + if (typesToReportAsDefault.includes(arg.type) && !dontReport(arg)) { + return context.report(node, defaultMessage) } } if (isChaiExpect) { - arg = obj.get(node, "arguments.0"); + arg = obj.get(node, "arguments.0") if (!arg) { - return context.report(node, emptyArgMessage); + return context.report(node, emptyArgMessage) } if (arg.type === "BinaryExpression") { - return checkBinaryInExpect(arg, node); + return checkBinaryInExpect(arg, node) } - if (typesToReportAsDefault.indexOf(arg.type) !== -1 && !dontReport(arg)) { - return context.report(node, defaultMessage); + if (typesToReportAsDefault.includes(arg.type) && !dontReport(arg)) { + return context.report(node, defaultMessage) } } }, - "MemberExpression": function (node) { + MemberExpression (node) { if (!insideIt || nodeSkipped) { - return; + return } - var arg; + let arg if (n.isChaiAssert(node)) { - arg = obj.get(node, "parent.arguments.0"); + arg = obj.get(node, "parent.arguments.0") if (!arg) { - return context.report(node, emptyArgMessage); + return context.report(node, emptyArgMessage) } if (arg.type === "BinaryExpression") { - return checkBinaryInAssert(arg, node); + return checkBinaryInAssert(arg, node) } - if (typesToReportAsDefault.indexOf(arg.type) !== -1 && !dontReport(arg)) { - return context.report(node, defaultMessage); + if (typesToReportAsDefault.includes(arg.type) && !dontReport(arg)) { + return context.report(node, defaultMessage) } } } - }; + } }, meta: { diff --git a/lib/rules/no-nested-it.js b/lib/rules/no-nested-it.js index 79f8ea4..fd752f5 100644 --- a/lib/rules/no-nested-it.js +++ b/lib/rules/no-nested-it.js @@ -4,44 +4,42 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var n = require("../utils/node.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; -//------------------------------------------------------------------------------ +const n = require("../utils/node.js") +const { isSkipSkipped } = require("../utils/options.js") +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { - - var insideIt = false; - var options = context.options[0] || {}; - var skipSkipped = isSkipSkipped(options, context); + create (context) { + let insideIt = false + const options = context.options[0] || {} + const skipSkipped = isSkipSkipped(options, context) function fEnter (node) { if (n.isTestBody(node)) { if (insideIt && !(skipSkipped && n.tryDetectSkipInParent(node))) { - context.report(node.parent, "Nested tests are not allowed. Only nested suites are allowed."); - } - else { - insideIt = true; + context.report(node.parent, "Nested tests are not allowed. Only nested suites are allowed.") + } else { + insideIt = true } } } function fExit (node) { if (n.isTestBody(node)) { - insideIt = false; + insideIt = false } } return { - "FunctionExpression": fEnter, - "ArrowFunctionExpression": fEnter, + FunctionExpression: fEnter, + ArrowFunctionExpression: fEnter, "FunctionExpression:exit": fExit, "ArrowFunctionExpression:exit": fExit - }; + } }, meta: { diff --git a/lib/rules/no-outside-declaration.js b/lib/rules/no-outside-declaration.js index 143198b..73b1bfd 100644 --- a/lib/rules/no-outside-declaration.js +++ b/lib/rules/no-outside-declaration.js @@ -4,49 +4,48 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var n = require("../utils/node.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; -//------------------------------------------------------------------------------ +const n = require("../utils/node.js") +const { isSkipSkipped } = require("../utils/options.js") +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { - - var insideSuite = false; - var insideHookOrTest = false; - var options = context.options[0] || {}; - var skipSkipped = isSkipSkipped(options, context); - var m = "Variable declaration is not allowed outside tests and hooks."; + create (context) { + let insideSuite = false + let insideHookOrTest = false + const options = context.options[0] || {} + const skipSkipped = isSkipSkipped(options, context) + const m = "Variable declaration is not allowed outside tests and hooks." function fEnter (node) { if (n.isSuiteBody(node) && !insideSuite) { - insideSuite = true; + insideSuite = true } if (n.isTestBody(node) || n.isHookBody(node)) { - insideHookOrTest = true; + insideHookOrTest = true } } function fExit (node) { if (n.isTestBody(node) || n.isHookBody(node)) { - insideHookOrTest = false; + insideHookOrTest = false } } return { - "FunctionExpression": fEnter, - "ArrowFunctionExpression": fEnter, + FunctionExpression: fEnter, + ArrowFunctionExpression: fEnter, "FunctionExpression:exit": fExit, "ArrowFunctionExpression:exit": fExit, - "VariableDeclaration": function (node) { + VariableDeclaration (node) { if (insideSuite && !insideHookOrTest && !(skipSkipped && n.tryDetectSkipInParent(node))) { - context.report(node, m); + context.report(node, m) } } - }; + } }, meta: { diff --git a/lib/rules/no-same-titles.js b/lib/rules/no-same-titles.js index 3c08abe..1989abb 100644 --- a/lib/rules/no-same-titles.js +++ b/lib/rules/no-same-titles.js @@ -4,93 +4,92 @@ * @copyright 2015 onechiporenko. All rights reserved. */ -"use strict"; +"use strict" -var obj = require("../utils/obj.js"); -var n = require("../utils/node.js"); -var mocha = require("../utils/mocha-specs.js"); -var isSkipSkipped = require("../utils/options.js").isSkipSkipped; -var hasOwnProperty = Object.prototype.hasOwnProperty; -//------------------------------------------------------------------------------ +const obj = require("../utils/obj.js") +const n = require("../utils/node.js") +const mocha = require("../utils/mocha-specs.js") +const { isSkipSkipped } = require("../utils/options.js") +const { hasOwnProperty } = Object.prototype +// ------------------------------------------------------------------------------ // Rule Definition -//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ module.exports = { - create: function (context) { + create (context) { + let insideSuite = false + const testTitles = [] + const options = context.options[0] || {} + const skipSkipped = isSkipSkipped(options, context) + const scope = hasOwnProperty.call(options, "scope") ? options.scope : "suite" + const checkNesting = scope === "suite" + let nestingLevel = checkNesting ? -1 : 0 - var insideSuite = false; - var testTitles = []; - var options = context.options[0] || {}; - var skipSkipped = isSkipSkipped(options, context); - var scope = hasOwnProperty.call(options, "scope") ? options.scope : "suite"; - var checkNesting = scope === "suite"; - var nestingLevel = checkNesting ? -1 : 0; - - function report(level) { + function report (level) { Object.keys(testTitles[level]).forEach(function (title) { if (testTitles[level][title].length > 1) { - testTitles[level][title].forEach(function(node) { - context.report(node, "Some tests have same titles."); - }); + testTitles[level][title].forEach(function (node) { + context.report(node, "Some tests have same titles.") + }) } - }); + }) } function fEnter (node) { if (n.isSuiteBody(node) && !(skipSkipped && n.tryDetectSkipInParent(node))) { - insideSuite = true; + insideSuite = true if (checkNesting) { - nestingLevel++; + nestingLevel++ } if (!testTitles[nestingLevel]) { - testTitles[nestingLevel] = {}; + testTitles[nestingLevel] = {} } } } function fExit (node) { if (n.isSuiteBody(node) && !(skipSkipped && n.tryDetectSkipInParent(node))) { - insideSuite = false; + insideSuite = false if (checkNesting) { - report(nestingLevel); - testTitles[nestingLevel] = {}; - nestingLevel--; + report(nestingLevel) + testTitles[nestingLevel] = {} + nestingLevel-- } } } return { - "FunctionExpression": fEnter, - "ArrowFunctionExpression": fEnter, + FunctionExpression: fEnter, + ArrowFunctionExpression: fEnter, "FunctionExpression:exit": fExit, "ArrowFunctionExpression:exit": fExit, - "CallExpression": function (node) { - if (insideSuite && !(skipSkipped && n.tryDetectSkipInParent(node)) && mocha.tests.indexOf(obj.get(node, "callee.name")) !== -1) { - var firstArgType = obj.get(node, "arguments.0.type"); + CallExpression (node) { + if (insideSuite && !(skipSkipped && n.tryDetectSkipInParent(node)) && mocha.tests.includes(obj.get(node, "callee.name"))) { + const firstArgType = obj.get(node, "arguments.0.type") if (firstArgType === "Literal") { - var title = obj.get(node, "arguments.0.value"); + const title = obj.get(node, "arguments.0.value") if (!Array.isArray(testTitles[nestingLevel][title])) { // title = "constructor" may break `!testTitles[nestingLevel][title]` - testTitles[nestingLevel][title] = []; + testTitles[nestingLevel][title] = [] } - testTitles[nestingLevel][title].push(node); + testTitles[nestingLevel][title].push(node) } } }, - "Program:exit": function () { + "Program:exit" () { if (checkNesting) { - return; + return } testTitles.forEach(function (level) { Object.keys(level).forEach(function (title) { if (level[title].length > 1) { - level[title].forEach(function(node) { - context.report(node, "Some tests have same titles."); - }); + level[title].forEach(function (node) { + context.report(node, "Some tests have same titles.") + }) } - }); - }); + }) + }) } - }; + } }, meta: { diff --git a/lib/utils/mocha-specs.js b/lib/utils/mocha-specs.js index 34b0c87..c333e6b 100644 --- a/lib/utils/mocha-specs.js +++ b/lib/utils/mocha-specs.js @@ -1,46 +1,46 @@ -"use strict"; +"use strict" -var suites = [ +const suites = [ "describe", "context", "describe.only", "context.only", // BDD "Feature", "Scenario", "Feature.only", "Scenario.only", // Mocha Cakes 2 "suite", "suite.only" // TDD -]; +] -var suitesSkipped = [ +const suitesSkipped = [ "describe.skip", "xdescribe", "xcontext", // BDD "Feature.skip", "Scenario.skip", // Mocha Cakes 2 "suite.skip" // TDD -]; +] -var tests = [ +const tests = [ "it", "specify", "it.only", "specify.only", // BDD "Then", "And", "But", "Then.only", "And.only", "But.only", // Mocha Cakes 2 "test", "test.only" // TDD -]; +] -var testsSkipped = [ +const testsSkipped = [ "xit", "it.skip", "xspecify", // BDD "Then.skip", "And.skip", "But.skip", // Mocha Cakes 2 "test.skip" // TDD -]; +] -var hooks = [ +const hooks = [ "before", "beforeEach", "after", "afterEach" -]; +] module.exports = { - hooks: hooks, + hooks, - suites: suites, + suites, - suitesSkipped: suitesSkipped, + suitesSkipped, allSuites: suites.concat(suitesSkipped), - tests: tests, + tests, - testsSkipped: testsSkipped, + testsSkipped, allTests: tests.concat(testsSkipped), @@ -50,4 +50,4 @@ module.exports = { all: suites.concat(suitesSkipped).concat(tests).concat(testsSkipped) -}; +} diff --git a/lib/utils/node.js b/lib/utils/node.js index 50b9de0..c5035f7 100644 --- a/lib/utils/node.js +++ b/lib/utils/node.js @@ -1,10 +1,10 @@ -"use strict"; +"use strict" -var obj = require("./obj.js"); +const obj = require("./obj.js") -var mocha = require("./mocha-specs.js"); +const mocha = require("./mocha-specs.js") -var chainable = ["to", "be", "been", "is", "that", "which", "and", "has", "have", "with", "at", "of", "same"]; +const chainable = ["to", "be", "been", "is", "that", "which", "and", "has", "have", "with", "at", "of", "same"] /** * @typedef {object} ASTNode @@ -16,10 +16,10 @@ var chainable = ["to", "be", "been", "is", "that", "which", "and", "has", "have" * @param {ASTNode} node * @returns {boolean} */ -function isSinonAssert(node) { +function isSinonAssert (node) { return node.type === "MemberExpression" && node.object.name === "sinon" && - (node.property.name === "assert" || node.property.value === "assert"); + (node.property.name === "assert" || node.property.value === "assert") } /** @@ -28,9 +28,9 @@ function isSinonAssert(node) { * @param {ASTNode} node * @returns {boolean} */ -function isChaiShould(node) { +function isChaiShould (node) { return node.type === "MemberExpression" && - (node.property.name === "should" || node.property.value === "should"); + (node.property.name === "should" || node.property.value === "should") } /** @@ -39,9 +39,9 @@ function isChaiShould(node) { * @param {ASTNode} node * @returns {boolean} */ -function isChaiChainable(node) { +function isChaiChainable (node) { return node.type === "MemberExpression" && - chainable.indexOf(node.property.name) !== -1; + chainable.includes(node.property.name) } /** @@ -50,15 +50,14 @@ function isChaiChainable(node) { * @param {ASTNode} node * @returns {boolean} */ -function isChaiExpect(node) { - var callee = node.callee; +function isChaiExpect (node) { + const { callee } = node return node.type === "CallExpression" && ( - callee.name === "expect" - || - obj.get(callee, "object.name") === "chai" && - (callee.property.name === "expect" || callee.property.value === "expect") - ); + callee.name === "expect" || + (obj.get(callee, "object.name") === "chai" && + (callee.property.name === "expect" || callee.property.value === "expect")) + ) } /** @@ -68,8 +67,8 @@ function isChaiExpect(node) { * @returns {boolean} * @private */ -function _isChaiAssert1(node) { - return node.type === "MemberExpression" && obj.get(node, "parent.type") === "CallExpression" && node.object.name === "assert"; +function _isChaiAssert1 (node) { + return node.type === "MemberExpression" && obj.get(node, "parent.type") === "CallExpression" && node.object.name === "assert" } /** @@ -79,8 +78,8 @@ function _isChaiAssert1(node) { * @returns {boolean} * @private */ -function _isChaiAssert2(node) { - return node.type === "CallExpression" && node.callee.name === "assert"; +function _isChaiAssert2 (node) { + return node.type === "CallExpression" && node.callee.name === "assert" } /** @@ -90,11 +89,11 @@ function _isChaiAssert2(node) { * @returns {boolean} * @private */ -function _isChaiAssert3(node) { +function _isChaiAssert3 (node) { return node.type === "MemberExpression" && obj.get(node, "parent.type") === "CallExpression" && node.object.name === "chai" && - (node.property.name === "assert" || node.property.value === "assert"); + (node.property.name === "assert" || node.property.value === "assert") } /** @@ -104,12 +103,12 @@ function _isChaiAssert3(node) { * @returns {boolean} * @private */ -function _isChaiAssert4(node) { +function _isChaiAssert4 (node) { return node.type === "MemberExpression" && obj.get(node, "parent.type") === "CallExpression" && node.object.type === "MemberExpression" && node.object.object.name === "chai" && - (node.object.property.name === "assert" || node.object.property.value === "assert"); + (node.object.property.name === "assert" || node.object.property.value === "assert") } /** @@ -118,8 +117,8 @@ function _isChaiAssert4(node) { * @param {ASTNode} node * @returns {boolean} */ -function isChaiAssert(node) { - return _isChaiAssert1(node) || _isChaiAssert2(node) || _isChaiAssert3(node) || _isChaiAssert4(node); +function isChaiAssert (node) { + return _isChaiAssert1(node) || _isChaiAssert2(node) || _isChaiAssert3(node) || _isChaiAssert4(node) } /** @@ -130,24 +129,24 @@ function isChaiAssert(node) { * @param {string} type * @returns {boolean} */ -function isBlockBody(node, type) { +function isBlockBody (node, type) { /* istanbul ignore next */ - var types = Array.isArray(type) ? type : [type]; - var parent = node.parent; + const types = Array.isArray(type) ? type : [type] + const { parent } = node if (!parent) { - return false; + return false } - var parentType = obj.get(parent, "callee.object") ? "MemberExpression" : "Identifier"; + const parentType = obj.get(parent, "callee.object") ? "MemberExpression" : "Identifier" if (parentType === "MemberExpression") { - return types.indexOf(parent.callee.object.name + "." + parent.callee.property.name) !== -1 && obj.get(parent, "arguments.1") === node; + return types.includes(parent.callee.object.name + "." + parent.callee.property.name) && obj.get(parent, "arguments.1") === node } /* istanbul ignore else */ if (parentType === "Identifier") { - return types.indexOf(obj.get(parent, "callee.name")) !== -1 && (obj.get(parent, "arguments.0") === node || obj.get(parent, "arguments.1") === node); + return types.includes(obj.get(parent, "callee.name")) && (obj.get(parent, "arguments.0") === node || obj.get(parent, "arguments.1") === node) } /* istanbul ignore next */ - return false; + return false } /** @@ -156,20 +155,20 @@ function isBlockBody(node, type) { * @param {ASTNode} node * @returns {boolean} */ -function isTestSkipped(node) { +function isTestSkipped (node) { if (node.type !== "CallExpression") { - return false; + return false } - var callee = node.callee; + const { callee } = node if (callee.type === "Identifier") { - return mocha.allSkipped.indexOf(callee.name) !== -1; + return mocha.allSkipped.includes(callee.name) } - var o = callee.object.name; - if (mocha.allBlocks.indexOf(o) === -1) { - return false; + const o = callee.object.name + if (!mocha.allBlocks.includes(o)) { + return false } - var prop = callee.property.name; - return mocha.allSkipped.indexOf(o + "." + prop) !== -1; + const prop = callee.property.name + return mocha.allSkipped.includes(o + "." + prop) } /** @@ -178,15 +177,15 @@ function isTestSkipped(node) { * @param {ASTNode} node * @returns {boolean} */ -function tryDetectSkipInParent(node) { - var n = node; +function tryDetectSkipInParent (node) { + let n = node while (n) { if (isTestSkipped(n)) { - return true; + return true } - n = n.parent; + n = n.parent } - return false; + return false } /** @@ -195,8 +194,8 @@ function tryDetectSkipInParent(node) { * @param {ASTNode} node * @returns {boolean} */ -function isSuiteBody(node) { - return isBlockBody(node, mocha.allSuites); +function isSuiteBody (node) { + return isBlockBody(node, mocha.allSuites) } /** @@ -205,8 +204,8 @@ function isSuiteBody(node) { * @param {ASTNode} node * @returns {boolean} */ -function isTestBody(node) { - return isBlockBody(node, mocha.allTests); +function isTestBody (node) { + return isBlockBody(node, mocha.allTests) } /** @@ -215,8 +214,8 @@ function isTestBody(node) { * @param {ASTNode} node * @returns {boolean} */ -function isHookBody(node) { - return isBlockBody(node, mocha.hooks); +function isHookBody (node) { + return isBlockBody(node, mocha.hooks) } /** @@ -226,7 +225,7 @@ function isHookBody(node) { * @returns {boolean} */ function isAssertion (node) { - return isChaiShould(node) || isChaiExpect(node) || isChaiAssert(node) || isSinonAssert(node); + return isChaiShould(node) || isChaiExpect(node) || isChaiAssert(node) || isSinonAssert(node) } /** @@ -236,26 +235,26 @@ function isAssertion (node) { * @returns {string} */ function getCaller (node) { - var o, p; + let o, p if (obj.get(node, "type") === "MemberExpression") { - o = node.object.type === "MemberExpression" ? getCaller(node.object) : node.object.name; - p = node.property.name || node.property.value; - return p ? o + "." + p : o; + o = node.object.type === "MemberExpression" ? getCaller(node.object) : node.object.name + p = node.property.name || node.property.value + return p ? o + "." + p : o } - var callee = node.callee; + const { callee } = node if (!callee) { - return ""; + return "" } if (callee.type === "MemberExpression") { - o = callee.object.type === "MemberExpression" ? getCaller(callee.object) : callee.object.name; - p = callee.property.name || callee.property.value; - return p ? o + "." + p : o; + o = callee.object.type === "MemberExpression" ? getCaller(callee.object) : callee.object.name + p = callee.property.name || callee.property.value + return p ? o + "." + p : o } - return obj.get(callee, "name"); + return obj.get(callee, "name") } function _endsWith (str, suffix) { - return str.indexOf(suffix, str.length - suffix.length) !== -1; + return str.includes(suffix, str.length - suffix.length) } /** @@ -266,15 +265,15 @@ function _endsWith (str, suffix) { */ function cleanCaller (caller) { if (!caller) { - return ""; + return "" } [".call", ".apply"].forEach(function (e) { if (_endsWith(caller, e)) { - var i = caller.lastIndexOf(e); - caller = caller.substr(0, i); + const i = caller.lastIndexOf(e) + caller = caller.substr(0, i) } - }); - return caller; + }) + return caller } /** @@ -284,8 +283,8 @@ function cleanCaller (caller) { * @param {ASTNode} node * @returns {ASTNode} */ -function getParentExpression(node) { - return _getParentByTypes(node, "ExpressionStatement"); +function getParentExpression (node) { + return _getParentByTypes(node, "ExpressionStatement") } /** @@ -295,43 +294,43 @@ function getParentExpression(node) { * @returns {?ASTNode} * @private */ -function _getParentByTypes(node, types) { - var _types = Array.isArray(types) ? types : [types]; - if (_types.indexOf(node.type) !== -1) { - return node; +function _getParentByTypes (node, types) { + const _types = Array.isArray(types) ? types : [types] + if (_types.includes(node.type)) { + return node } - return node.parent ? _getParentByTypes(node.parent, _types) : null; + return node.parent ? _getParentByTypes(node.parent, _types) : null } -function isSinonStub(node) { - var caller = cleanCaller(getCaller(node)); - return caller === "stub" || caller === "sinon.stub"; +function isSinonStub (node) { + const caller = cleanCaller(getCaller(node)) + return caller === "stub" || caller === "sinon.stub" } module.exports = { chaiChainable: chainable, - isChaiShould: isChaiShould, - isChaiExpect: isChaiExpect, - isChaiAssert: isChaiAssert, - isSinonAssert: isSinonAssert, + isChaiShould, + isChaiExpect, + isChaiAssert, + isSinonAssert, - isTestBody: isTestBody, - isSuiteBody: isSuiteBody, - isHookBody: isHookBody, + isTestBody, + isSuiteBody, + isHookBody, - isAssertion: isAssertion, + isAssertion, - isChaiChainable: isChaiChainable, + isChaiChainable, - isSinonStub: isSinonStub, + isSinonStub, - tryDetectSkipInParent: tryDetectSkipInParent, + tryDetectSkipInParent, - getCaller: getCaller, - cleanCaller: cleanCaller, + getCaller, + cleanCaller, - getParentExpression: getParentExpression + getParentExpression -}; +} diff --git a/lib/utils/obj.js b/lib/utils/obj.js index 8c9706f..028a920 100644 --- a/lib/utils/obj.js +++ b/lib/utils/obj.js @@ -1,6 +1,6 @@ -"use strict"; +"use strict" -var _typesMap = { +const _typesMap = { "[object Boolean]": "boolean", "[object Number]": "number", "[object String]": "string", @@ -11,38 +11,38 @@ var _typesMap = { "[object Object]": "object", "[object Undefined]": "undefined", "[object Null]": "null" -}; +} module.exports = { - get: function (obj, path) { - var subpathes = path.split("."); + get (obj, path) { + const subpathes = path.split(".") while (subpathes.length) { - var subpath = subpathes.shift(); - obj = obj[subpath]; + const subpath = subpathes.shift() + obj = obj[subpath] if (!obj) { - return obj; + return obj } } - return obj; + return obj }, - has: function (obj, path) { - var subpathes = path.split("."); + has (obj, path) { + const subpathes = path.split(".") while (subpathes.length) { - var subpath = subpathes.shift(); - obj = obj[subpath]; + const subpath = subpathes.shift() + obj = obj[subpath] if (!obj) { - return false; + return false } } - return true; + return true }, - getType: function (value) { + getType (value) { return _typesMap[{}.toString.call(value)] || /* istanbul ignore next */ - "object"; + "object" } -}; +} diff --git a/lib/utils/options.js b/lib/utils/options.js index 9f46e25..0875d88 100644 --- a/lib/utils/options.js +++ b/lib/utils/options.js @@ -1,9 +1,9 @@ -var hasOwnProperty = Object.prototype.hasOwnProperty; +const { hasOwnProperty } = Object.prototype -var obj = require("./obj.js"); +const obj = require("./obj.js") exports.isSkipSkipped = function (options, context) { return hasOwnProperty.call(options, "skipSkipped") ? options.skipSkipped - : obj.get(context, "settings.mocha-cleanup.skipSkipped") || false; -}; + : obj.get(context, "settings.mocha-cleanup.skipSkipped") || false +} diff --git a/lib/utils/tests.js b/lib/utils/tests.js index c9707dd..a3b1a1c 100644 --- a/lib/utils/tests.js +++ b/lib/utils/tests.js @@ -1,33 +1,33 @@ -"use strict"; +"use strict" -var fast = process.argv[5] === "--fast"; +const fast = process.argv[5] === "--fast" -var combos = [ - {SUITESKIP: "describe.skip", TESTSKIP: "it.skip", SUITE: "describe", TEST: "it"}, - {SUITESKIP: "xcontext", TESTSKIP: "it.skip", SUITE: "context", TEST: "it"}, - {SUITESKIP: "xcontext", TESTSKIP: "xspecify", SUITE: "context", TEST: "specify"}, - {SUITESKIP: "xdescribe", TESTSKIP: "xit", SUITE: "describe", TEST: "it" }, - {SUITESKIP: "xcontext", TESTSKIP: "xit", SUITE: "context", TEST: "it" }, - {SUITESKIP: "suite.skip", TESTSKIP: "test.skip", SUITE: "suite", TEST: "test" } -]; +const combos = [ + { SUITESKIP: "describe.skip", TESTSKIP: "it.skip", SUITE: "describe", TEST: "it" }, + { SUITESKIP: "xcontext", TESTSKIP: "it.skip", SUITE: "context", TEST: "it" }, + { SUITESKIP: "xcontext", TESTSKIP: "xspecify", SUITE: "context", TEST: "specify" }, + { SUITESKIP: "xdescribe", TESTSKIP: "xit", SUITE: "describe", TEST: "it" }, + { SUITESKIP: "xcontext", TESTSKIP: "xit", SUITE: "context", TEST: "it" }, + { SUITESKIP: "suite.skip", TESTSKIP: "test.skip", SUITE: "suite", TEST: "test" } +] -var es = [ - {ES: "function () {"}, - {ES: "() => {"} -]; +const es = [ + { ES: "function () {" }, + { ES: "() => {" } +] -var hooks = [ - {HOOK: "before"}, - {HOOK: "beforeEach"}, - {HOOK: "after"}, - {HOOK: "afterEach"} -]; +const hooks = [ + { HOOK: "before" }, + { HOOK: "beforeEach" }, + { HOOK: "after" }, + { HOOK: "afterEach" } +] module.exports = { mochaDatasets: fast /* istanbul ignore next */ ? combos[0] : combos, - es: es, - hooks: hooks -}; + es, + hooks +} diff --git a/package-lock.json b/package-lock.json index b57813c..76f9700 100644 --- a/package-lock.json +++ b/package-lock.json @@ -227,15 +227,15 @@ "dev": true }, "acorn": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", - "integrity": "sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", + "integrity": "sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==", "dev": true }, "acorn-jsx": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.1.0.tgz", - "integrity": "sha512-tMUqwBWfLFbJbizRmEcWSLw6HnFzfdJs2sOJEOwwtVPMoH/0Ay+E703oZz78VSXZiiDcZrQ5XKjPIUQixhmgVw==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.2.0.tgz", + "integrity": "sha512-HiUX/+K2YpkpJ+SzBffkM/AQ2YE03S0U1kjTLVpoJdhZMOWy8qvXVN9JdLqv2QsaQ6MPYQIuNmwD8zOiYUofLQ==", "dev": true }, "aggregate-error": { @@ -267,12 +267,20 @@ "dev": true }, "ansi-escapes": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.0.tgz", - "integrity": "sha512-EiYhwo0v255HUL6eDyuLrXEkTi7WwVCLAw+SeOQ7M7qdun1z1pum4DEm/nuqIVbPvi9RPPc9k9LbyBv6H0DwVg==", + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.1.tgz", + "integrity": "sha512-JWF7ocqNrp8u9oqpgV+wH5ftbt+cfvv+PTjOvKLT3AdYly/LmORARfEVT1iyjwN+4MqE5UmVKoAdIBqeoCHgLA==", "dev": true, "requires": { - "type-fest": "^0.8.1" + "type-fest": "^0.11.0" + }, + "dependencies": { + "type-fest": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.11.0.tgz", + "integrity": "sha512-OdjXJxnCN1AvyLSzeKIgXTXxV+99ZuXl3Hpo9XpJAv9MBcHrrJOQ5kV7ypXOuQie+AmWG25hLbiKdwYTifzcfQ==", + "dev": true + } } }, "ansi-regex": { @@ -324,6 +332,27 @@ "sprintf-js": "~1.0.2" } }, + "array-includes": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.1.tgz", + "integrity": "sha512-c2VXaCHl7zPsvpkFsw4nxvFie4fh1ur9bpcgsVkIjqn0H/Xwdg+7fv3n2r/isyS8EBj5b06M9kHyZuIr4El6WQ==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.0", + "is-string": "^1.0.5" + } + }, + "array.prototype.flat": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.2.3.tgz", + "integrity": "sha512-gBlRZV0VSmfPIeWfuuy56XZMvbVfbEUnOXUvt3F/eUUUSyzlgLxhEX4YAEpxNAogRGehPSnfXyPtYyKAhkzQhQ==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.0-next.1" + } + }, "astral-regex": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", @@ -508,6 +537,12 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, + "contains-path": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/contains-path/-/contains-path-0.1.0.tgz", + "integrity": "sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo=", + "dev": true + }, "convert-source-map": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.7.0.tgz", @@ -598,6 +633,15 @@ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "dev": true }, + "error-ex": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", + "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "dev": true, + "requires": { + "is-arrayish": "^0.2.1" + } + }, "es-abstract": { "version": "1.17.4", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.4.tgz", @@ -685,6 +729,235 @@ "v8-compile-cache": "^2.0.3" } }, + "eslint-config-standard": { + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-14.1.0.tgz", + "integrity": "sha512-EF6XkrrGVbvv8hL/kYa/m6vnvmUT+K82pJJc4JJVMM6+Qgqh0pnwprSxdduDLB9p/7bIxD+YV5O0wfb8lmcPbA==", + "dev": true + }, + "eslint-import-resolver-node": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.3.tgz", + "integrity": "sha512-b8crLDo0M5RSe5YG8Pu2DYBj71tSB6OvXkfzwbJU2w7y8P4/yo0MyF8jU26IEuEuHF2K5/gcAJE3LhQGqBBbVg==", + "dev": true, + "requires": { + "debug": "^2.6.9", + "resolve": "^1.13.1" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + } + } + }, + "eslint-module-utils": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.5.2.tgz", + "integrity": "sha512-LGScZ/JSlqGKiT8OC+cYRxseMjyqt6QO54nl281CK93unD89ijSeRV6An8Ci/2nvWVKe8K/Tqdm75RQoIOCr+Q==", + "dev": true, + "requires": { + "debug": "^2.6.9", + "pkg-dir": "^2.0.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", + "dev": true, + "requires": { + "locate-path": "^2.0.0" + } + }, + "locate-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", + "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", + "dev": true, + "requires": { + "p-locate": "^2.0.0", + "path-exists": "^3.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "p-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", + "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "dev": true, + "requires": { + "p-try": "^1.0.0" + } + }, + "p-locate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", + "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", + "dev": true, + "requires": { + "p-limit": "^1.1.0" + } + }, + "p-try": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", + "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=", + "dev": true + }, + "pkg-dir": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-2.0.0.tgz", + "integrity": "sha1-9tXREJ4Z1j7fQo4L1X4Sd3YVM0s=", + "dev": true, + "requires": { + "find-up": "^2.1.0" + } + } + } + }, + "eslint-plugin-es": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-es/-/eslint-plugin-es-3.0.0.tgz", + "integrity": "sha512-6/Jb/J/ZvSebydwbBJO1R9E5ky7YeElfK56Veh7e4QGFHCXoIXGH9HhVz+ibJLM3XJ1XjP+T7rKBLUa/Y7eIng==", + "dev": true, + "requires": { + "eslint-utils": "^2.0.0", + "regexpp": "^3.0.0" + }, + "dependencies": { + "eslint-utils": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.0.0.tgz", + "integrity": "sha512-0HCPuJv+7Wv1bACm8y5/ECVfYdfsAm9xmVb7saeFlxjPYALefjhbYoCkBjPdPzGH8wWyTpAez82Fh3VKYEZ8OA==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0" + } + }, + "regexpp": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.0.0.tgz", + "integrity": "sha512-Z+hNr7RAVWxznLPuA7DIh8UNX1j9CDrUQxskw9IrBE1Dxue2lyXT+shqEIeLUjrokxIP8CMy1WkjgG3rTsd5/g==", + "dev": true + } + } + }, + "eslint-plugin-import": { + "version": "2.20.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.20.1.tgz", + "integrity": "sha512-qQHgFOTjguR+LnYRoToeZWT62XM55MBVXObHM6SKFd1VzDcX/vqT1kAz8ssqigh5eMj8qXcRoXXGZpPP6RfdCw==", + "dev": true, + "requires": { + "array-includes": "^3.0.3", + "array.prototype.flat": "^1.2.1", + "contains-path": "^0.1.0", + "debug": "^2.6.9", + "doctrine": "1.5.0", + "eslint-import-resolver-node": "^0.3.2", + "eslint-module-utils": "^2.4.1", + "has": "^1.0.3", + "minimatch": "^3.0.4", + "object.values": "^1.1.0", + "read-pkg-up": "^2.0.0", + "resolve": "^1.12.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "doctrine": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", + "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", + "dev": true, + "requires": { + "esutils": "^2.0.2", + "isarray": "^1.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + } + } + }, + "eslint-plugin-node": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-11.0.0.tgz", + "integrity": "sha512-chUs/NVID+sknFiJzxoN9lM7uKSOEta8GC8365hw1nDfwIPIjjpRSwwPvQanWv8dt/pDe9EV4anmVSwdiSndNg==", + "dev": true, + "requires": { + "eslint-plugin-es": "^3.0.0", + "eslint-utils": "^2.0.0", + "ignore": "^5.1.1", + "minimatch": "^3.0.4", + "resolve": "^1.10.1", + "semver": "^6.1.0" + }, + "dependencies": { + "eslint-utils": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.0.0.tgz", + "integrity": "sha512-0HCPuJv+7Wv1bACm8y5/ECVfYdfsAm9xmVb7saeFlxjPYALefjhbYoCkBjPdPzGH8wWyTpAez82Fh3VKYEZ8OA==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0" + } + }, + "ignore": { + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.4.tgz", + "integrity": "sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A==", + "dev": true + } + } + }, + "eslint-plugin-promise": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-4.2.1.tgz", + "integrity": "sha512-VoM09vT7bfA7D+upt+FjeBO5eHIJQBUWki1aPvB+vbNiHS3+oGIJGIeyBtKQTME6UPXXy3vV07OL1tHd3ANuDw==", + "dev": true + }, + "eslint-plugin-standard": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-standard/-/eslint-plugin-standard-4.0.1.tgz", + "integrity": "sha512-v/KBnfyaOMPmZc/dmc6ozOdWqekGp7bBGq4jLAecEfPGmfKiWS4sA8sC0LqiV9w5qmXAtXVn4M3p1jSyhY85SQ==", + "dev": true + }, "eslint-scope": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.0.0.tgz", @@ -711,13 +984,13 @@ "dev": true }, "espree": { - "version": "6.1.2", - "resolved": "https://registry.npmjs.org/espree/-/espree-6.1.2.tgz", - "integrity": "sha512-2iUPuuPP+yW1PZaMSDM9eyVf8D5P0Hi8h83YtZ5bPc/zHYjII5khoixIUTMO794NOY8F/ThF1Bo8ncZILarUTA==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-6.2.0.tgz", + "integrity": "sha512-Xs8airJ7RQolnDIbLtRutmfvSsAe0xqMMAantCN/GMoqf81TFbeI1T7Jpd56qYu1uuh32dOG5W/X9uO+ghPXzA==", "dev": true, "requires": { "acorn": "^7.1.0", - "acorn-jsx": "^5.1.0", + "acorn-jsx": "^5.2.0", "eslint-visitor-keys": "^1.1.0" } }, @@ -1036,6 +1309,12 @@ "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true }, + "hosted-git-info": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz", + "integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==", + "dev": true + }, "html-escaper": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.0.tgz", @@ -1096,26 +1375,93 @@ "dev": true }, "inquirer": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-7.0.4.tgz", - "integrity": "sha512-Bu5Td5+j11sCkqfqmUTiwv+tWisMtP0L7Q8WrqA2C/BbBhy1YTdFrvjjlrKq8oagA/tLQBski2Gcx/Sqyi2qSQ==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-7.0.6.tgz", + "integrity": "sha512-7SVO4h+QIdMq6XcqIqrNte3gS5MzCCKZdsq9DO4PJziBFNYzP3PGFbDjgadDb//MCahzgjCxvQ/O2wa7kx9o4w==", "dev": true, "requires": { "ansi-escapes": "^4.2.1", - "chalk": "^2.4.2", + "chalk": "^3.0.0", "cli-cursor": "^3.1.0", "cli-width": "^2.0.0", "external-editor": "^3.0.3", "figures": "^3.0.0", "lodash": "^4.17.15", "mute-stream": "0.0.8", - "run-async": "^2.2.0", + "run-async": "^2.4.0", "rxjs": "^6.5.3", "string-width": "^4.1.0", - "strip-ansi": "^5.1.0", + "strip-ansi": "^6.0.0", "through": "^2.3.6" + }, + "dependencies": { + "ansi-styles": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "dev": true, + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.0" + } + }, + "supports-color": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + } } }, + "is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", + "dev": true + }, "is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", @@ -1191,6 +1537,12 @@ "integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==", "dev": true }, + "is-string": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.5.tgz", + "integrity": "sha512-buY6VNRjhQMiF1qWDouloZlQbRhDPCebwxSjxMjxgemYT46YMd2NR0/H+fBhEfWX4A/w9TBJ+ol+okqJKFE6vQ==", + "dev": true + }, "is-symbol": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz", @@ -1212,6 +1564,12 @@ "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==", "dev": true }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "dev": true + }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -1439,6 +1797,26 @@ "type-check": "~0.3.2" } }, + "load-json-file": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", + "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "parse-json": "^2.2.0", + "pify": "^2.0.0", + "strip-bom": "^3.0.0" + }, + "dependencies": { + "strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", + "dev": true + } + } + }, "locate-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", @@ -1638,6 +2016,26 @@ "process-on-spawn": "^1.0.0" } }, + "normalize-package-data": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", + "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", + "dev": true, + "requires": { + "hosted-git-info": "^2.1.4", + "resolve": "^1.10.0", + "semver": "2 || 3 || 4 || 5", + "validate-npm-package-license": "^3.0.1" + }, + "dependencies": { + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + } + } + }, "normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -1850,6 +2248,18 @@ "es-abstract": "^1.17.0-next.1" } }, + "object.values": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.1.tgz", + "integrity": "sha512-WTa54g2K8iu0kmS/us18jEmdv1a4Wi//BZ/DTVYEcH0XhLM5NYdpDHja3gt57VrZLcNAO2WGA+KpWsDBaHt6eA==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.0-next.1", + "function-bind": "^1.1.1", + "has": "^1.0.3" + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -1942,6 +2352,15 @@ "callsites": "^3.0.0" } }, + "parse-json": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", + "integrity": "sha1-9ID0BDTvgHQfhGkJn43qGPVaTck=", + "dev": true, + "requires": { + "error-ex": "^1.2.0" + } + }, "path-exists": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", @@ -1966,12 +2385,27 @@ "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "dev": true }, + "path-type": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz", + "integrity": "sha1-8BLMuEFbcJb8LaoQVMPXI4lZTHM=", + "dev": true, + "requires": { + "pify": "^2.0.0" + } + }, "picomatch": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.1.tgz", "integrity": "sha512-ISBaA8xQNmwELC7eOjqFKMESB2VIqt4PPDD0nsS95b/9dZXvVKOlz9keMSnoGGKcOHXfTvDD6WMaRoSc9UuhRA==", "dev": true }, + "pify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", + "dev": true + }, "pkg-dir": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", @@ -2044,6 +2478,72 @@ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "dev": true }, + "read-pkg": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", + "integrity": "sha1-jvHAYjxqbbDcZxPEv6xGMysjaPg=", + "dev": true, + "requires": { + "load-json-file": "^2.0.0", + "normalize-package-data": "^2.3.2", + "path-type": "^2.0.0" + } + }, + "read-pkg-up": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-2.0.0.tgz", + "integrity": "sha1-a3KoBImE4MQeeVEP1en6mbO1Sb4=", + "dev": true, + "requires": { + "find-up": "^2.0.0", + "read-pkg": "^2.0.0" + }, + "dependencies": { + "find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", + "dev": true, + "requires": { + "locate-path": "^2.0.0" + } + }, + "locate-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", + "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", + "dev": true, + "requires": { + "p-locate": "^2.0.0", + "path-exists": "^3.0.0" + } + }, + "p-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", + "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "dev": true, + "requires": { + "p-try": "^1.0.0" + } + }, + "p-locate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", + "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", + "dev": true, + "requires": { + "p-limit": "^1.1.0" + } + }, + "p-try": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", + "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=", + "dev": true + } + } + }, "readdirp": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.2.0.tgz", @@ -2120,9 +2620,9 @@ } }, "run-async": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", - "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.0.tgz", + "integrity": "sha512-xJTbh/d7Lm7SBhc1tNvTpeCHaEzoyxPrqNlvSdMfBTYwaY++UJFyXUOxAtsRUXjlqOfj8luNaR9vjCh4KeV+pg==", "dev": true, "requires": { "is-promise": "^2.1.0" @@ -2241,6 +2741,38 @@ } } }, + "spdx-correct": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz", + "integrity": "sha512-lr2EZCctC2BNR7j7WzJ2FpDznxky1sjfxvvYEyzxNyb6lZXHODmEoJeFu4JupYlkfha1KZpJyoqiJ7pgA1qq8Q==", + "dev": true, + "requires": { + "spdx-expression-parse": "^3.0.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-exceptions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.2.0.tgz", + "integrity": "sha512-2XQACfElKi9SlVb1CYadKDXvoajPgBVPn/gOQLrTvHdElaVhr7ZEbqJaRnJLVNeaI4cMEAgVCeBMKF6MWRDCRA==", + "dev": true + }, + "spdx-expression-parse": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz", + "integrity": "sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg==", + "dev": true, + "requires": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-license-ids": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.5.tgz", + "integrity": "sha512-J+FWzZoynJEXGphVIS+XEh3kFSjZX/1i9gFBaWQcB+/tmpe2qUsSBABpcxqxnAxFdiUFEgAX1bjYGQvIZmoz9Q==", + "dev": true + }, "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -2412,9 +2944,9 @@ } }, "tslib": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.0.tgz", - "integrity": "sha512-BmndXUtiTn/VDDrJzQE7Mm22Ix3PxgLltW9bSNLoeCY31gnG2OPx0QqJnuc9oMIKioYrz487i6K9o4Pdn0j+Kg==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz", + "integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==", "dev": true }, "type-check": { @@ -2462,6 +2994,16 @@ "integrity": "sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g==", "dev": true }, + "validate-npm-package-license": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "dev": true, + "requires": { + "spdx-correct": "^3.0.0", + "spdx-expression-parse": "^3.0.0" + } + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/package.json b/package.json index 520f5eb..2fd16a6 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,12 @@ "requireindex": "~1.2.0" }, "devDependencies": { - "eslint": "~6.8.0", + "eslint": "^6.8.0", + "eslint-config-standard": "^14.1.0", + "eslint-plugin-import": "^2.20.1", + "eslint-plugin-node": "^11.0.0", + "eslint-plugin-promise": "^4.2.1", + "eslint-plugin-standard": "^4.0.1", "jsonium": "^1.5.0", "mocha": ">=7.0.1", "nyc": "^15.0.0" diff --git a/tests/lib/rules/asserts-limit.js b/tests/lib/rules/asserts-limit.js index 2c94178..82ab5be 100644 --- a/tests/lib/rules/asserts-limit.js +++ b/tests/lib/rules/asserts-limit.js @@ -1,110 +1,110 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/asserts-limit"), - RuleTester = require("eslint").RuleTester; -var testHelpers = require("../../../lib/utils/tests.js"); +const rule = require("../../../lib/rules/asserts-limit") +const { RuleTester } = require("eslint") +const testHelpers = require("../../../lib/utils/tests.js") -var ruleTester = new RuleTester({env: {es6: true}}); +const ruleTester = new RuleTester({ env: { es6: true } }) -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const Jsonium = require("jsonium") +const j = new Jsonium() -var assertions = [ - {ASSERTION: "chai.expect(1).to.be.equal(1);"}, - {ASSERTION: "chai['expect'](1).to.be.equal(1);"}, - {ASSERTION: "expect(1).to.be.equal(1);"}, - {ASSERTION: "'1'.should.equal('1');"}, - {ASSERTION: "'1'['should'].equal('1');"}, - {ASSERTION: "assert.equal(1, 1);"}, - {ASSERTION: "assert['equal'](1, 1);"}, - {ASSERTION: "chai.assert.equal(1, 1);"}, - {ASSERTION: "chai.assert['equal'](1, 1);"}, - {ASSERTION: "chai['assert']['equal'](1, 1);"}, - {ASSERTION: "chai['assert'].equal(1, 1);"}, - {ASSERTION: "assert(1, 1);"}, - {ASSERTION: "sinon.assert.calledOn(sp, {});"}, - {ASSERTION: "sinon['assert'].calledOn(sp, {});"} -]; +const assertions = [ + { ASSERTION: "chai.expect(1).to.be.equal(1);" }, + { ASSERTION: "chai['expect'](1).to.be.equal(1);" }, + { ASSERTION: "expect(1).to.be.equal(1);" }, + { ASSERTION: "'1'.should.equal('1');" }, + { ASSERTION: "'1'['should'].equal('1');" }, + { ASSERTION: "assert.equal(1, 1);" }, + { ASSERTION: "assert['equal'](1, 1);" }, + { ASSERTION: "chai.assert.equal(1, 1);" }, + { ASSERTION: "chai.assert['equal'](1, 1);" }, + { ASSERTION: "chai['assert']['equal'](1, 1);" }, + { ASSERTION: "chai['assert'].equal(1, 1);" }, + { ASSERTION: "assert(1, 1);" }, + { ASSERTION: "sinon.assert.calledOn(sp, {});" }, + { ASSERTION: "sinon['assert'].calledOn(sp, {});" } +] -var validTestTemplates = [ - { - code: +const validTestTemplates = [ + { + code: "{{TEST}}('1234', {{ES}}" + "{{ASSERTION}} {{ASSERTION}} {{ASSERTION}} {{ASSERTION}}" + "});", - options: [{assertsLimit: 4}] - }, - { - code: + options: [{ assertsLimit: 4 }] + }, + { + code: "{{TEST}}('1234', {{ES}}" + "assert; {{ASSERTION}}" + "});" - }, - { - code: + }, + { + code: "{{TEST}}('1234', {{ES}}" + "should; {{ASSERTION}}" + "});" - }, - { - code: + }, + { + code: "{{TEST}}('1234', {{ES}}" + "notAssert['assert']; {{ASSERTION}}" + "});" - }, - { - code: + }, + { + code: "{{TEST}}('1234', {{ES}}" + "should(); {{ASSERTION}}" + "});" - }, - { - code: + }, + { + code: "{{TEST}}('1234', {{ES}}" + "expect; {{ASSERTION}}" + "});" - }, - { - code: + }, + { + code: "{{TEST}}('1234', {{ES}}" + "var expect = {};" + assertions[0] + "});" - }, - { - code: + }, + { + code: "{{TEST}}('1234', {{ES}}" + "var should = {}; {{ASSERTION}}" + "});" - }, - { - code: + }, + { + code: "{{TEST}}('1234', {{ES}}" + "var assert = {}; {{ASSERTION}}" + "});" - }, - { - code: + }, + { + code: "{{SUITESKIP}}('1234', {{ES}} " + "{{TEST}}('1234', {{ES}}" + "{{ASSERTION}} {{ASSERTION}} {{ASSERTION}}" + "});" + "});", - options: [{assertsLimit: 1, skipSkipped: true}], - errors: [{message: "Too many assertions (3). Maximum allowed is 2."}] - }, - { - code: + options: [{ assertsLimit: 1, skipSkipped: true }], + errors: [{ message: "Too many assertions (3). Maximum allowed is 2." }] + }, + { + code: "{{SUITESKIP}}('1234', {{ES}} " + "{{TEST}}('1234', {{ES}}" + "{{ASSERTION}} {{ASSERTION}} {{ASSERTION}}" + "});" + "});", - settings: {"mocha-cleanup": {"skipSkipped": true}}, - options: [{assertsLimit: 1}], - errors: [{message: "Too many assertions (3). Maximum allowed is 2."}] - }, - { - code: + settings: { "mocha-cleanup": { skipSkipped: true } }, + options: [{ assertsLimit: 1 }], + errors: [{ message: "Too many assertions (3). Maximum allowed is 2." }] + }, + { + code: "{{SUITESKIP}}('1234', {{ES}} " + "{{SUITE}}('4321', {{ES}} " + "{{TEST}}('1234', {{ES}}" + @@ -112,69 +112,69 @@ var validTestTemplates = [ "});" + "});" + "});", - options: [{assertsLimit: 1, skipSkipped: true}] - }, - { - code: + options: [{ assertsLimit: 1, skipSkipped: true }] + }, + { + code: "{{TEST}}('1234', function (done) {" + "done();" + "});" - }, - { - code: + }, + { + code: "{{TEST}}('1234', function (done) {});" - }, - { - code: + }, + { + code: "{{TEST}}('1234', function (notDone) {" + "notDone();" + "});" - }, - { - code: + }, + { + code: "{{TEST}}('1234', function (notDone) {});" - }, - { - code: + }, + { + code: "{{TESTSKIP}}('1234', {{ES}}" + "{{ASSERTION}} {{ASSERTION}} {{ASSERTION}}" + "});", - options: [{assertsLimit: 1, skipSkipped: true}] - }, - { - code: + options: [{ assertsLimit: 1, skipSkipped: true }] + }, + { + code: "{{TESTSKIP}}('1234', {{ES}} });", - options: [{assertsLimit: 1, skipSkipped: true}] - }, - { - code: + options: [{ assertsLimit: 1, skipSkipped: true }] + }, + { + code: "{{SUITESKIP}}('1234', {{ES}} " + "{{TEST}}('1234', {{ES}} });" + "});", - options: [{assertsLimit: 1, skipSkipped: true}] - }, - { - code: + options: [{ assertsLimit: 1, skipSkipped: true }] + }, + { + code: "{{SUITESKIP}}('1234', {{ES}} " + "{{{{SUITE}}}}('4321', {{ES}} " + "{{TEST}}('1234', {{ES}} });" + "});" + "});", - options: [{assertsLimit: 1, skipSkipped: true}] - } - ]; + options: [{ assertsLimit: 1, skipSkipped: true }] + } +] -var invalidTestTemplates = [ - { - code: +const invalidTestTemplates = [ + { + code: "{{TEST}}('1234', {{ES}}" + "{{ASSERTION}} {{ASSERTION}} {{ASSERTION}}" + "});", - options: [{assertsLimit: 2}], - errors: [{message: "Too many assertions (3). Maximum allowed is 2.", type: "CallExpression"}] - }, - { - code: + options: [{ assertsLimit: 2 }], + errors: [{ message: "Too many assertions (3). Maximum allowed is 2.", type: "CallExpression" }] + }, + { + code: "{{SUITESKIP}}('1234', {{ES}} " + "{{SUITE}}('4321', {{ES}} " + "{{TEST}}('1234', {{ES}}" + @@ -182,87 +182,87 @@ var invalidTestTemplates = [ "});" + "});" + "});", - options: [{assertsLimit: 1}], - errors: [{message: "Too many assertions (3). Maximum allowed is 1.", type: "CallExpression"}] - }, - { - code: + options: [{ assertsLimit: 1 }], + errors: [{ message: "Too many assertions (3). Maximum allowed is 1.", type: "CallExpression" }] + }, + { + code: "{{TESTSKIP}}('1234', {{ES}}" + "{{ASSERTION}} {{ASSERTION}} {{ASSERTION}}" + "});", - options: [{assertsLimit: 1}], - errors: [{message: "Too many assertions (3). Maximum allowed is 1.", type: "CallExpression"}] - } - ]; - var invalidTestTemplatesWithoutAssertions = [ - { - code: + options: [{ assertsLimit: 1 }], + errors: [{ message: "Too many assertions (3). Maximum allowed is 1.", type: "CallExpression" }] + } +] +const invalidTestTemplatesWithoutAssertions = [ + { + code: "{{TEST}}('1234', {{ES}} });", - errors: [{message: "Test without assertions is not allowed.", type: "CallExpression"}] - }, - { - code: + errors: [{ message: "Test without assertions is not allowed.", type: "CallExpression" }] + }, + { + code: "{{TESTSKIP}}('1234', {{ES}} });", - errors: [{message: "Test without assertions is not allowed.", type: "CallExpression"}] - }, - { - code: + errors: [{ message: "Test without assertions is not allowed.", type: "CallExpression" }] + }, + { + code: "{{SUITESKIP}}('1234',{{ES}} " + "{{TEST}}('1234', {{ES}} });" + "});", - errors: [{message: "Test without assertions is not allowed.", type: "CallExpression"}] - }, - { - code: + errors: [{ message: "Test without assertions is not allowed.", type: "CallExpression" }] + }, + { + code: "{{SUITE}}('1234', {{ES}} " + "{{TEST}}('1234', {{ES}} });" + "});", - errors: [{message: "Test without assertions is not allowed.", type: "CallExpression"}] - }, - { - code: + errors: [{ message: "Test without assertions is not allowed.", type: "CallExpression" }] + }, + { + code: "{{SUITESKIP}}('1234', {{ES}} " + "{{SUITE}}('4321', {{ES}} " + "{{TEST}}('1234', {{ES}} });" + "});" + "});", - errors: [{message: "Test without assertions is not allowed.", type: "CallExpression"}] - }, - { - code: + errors: [{ message: "Test without assertions is not allowed.", type: "CallExpression" }] + }, + { + code: "{{TEST}}('1234', function (done) {" + "done();" + "});", - options: [{assertsLimit: 1, skipSkipped: true, ignoreZeroAssertionsIfDoneExists: false}], - errors: [{message: "Test without assertions is not allowed.", type: "CallExpression"}] - }, - { - code: + options: [{ assertsLimit: 1, skipSkipped: true, ignoreZeroAssertionsIfDoneExists: false }], + errors: [{ message: "Test without assertions is not allowed.", type: "CallExpression" }] + }, + { + code: "{{TEST}}('1234', function (done) {});", - options: [{assertsLimit: 1, skipSkipped: true, ignoreZeroAssertionsIfDoneExists: false}], - errors: [{message: "Test without assertions is not allowed.", type: "CallExpression"}] - }, - { - code: + options: [{ assertsLimit: 1, skipSkipped: true, ignoreZeroAssertionsIfDoneExists: false }], + errors: [{ message: "Test without assertions is not allowed.", type: "CallExpression" }] + }, + { + code: "{{TEST}}('1234', function (notDone) {" + "notDone();" + "});", - options: [{assertsLimit: 1, skipSkipped: true, ignoreZeroAssertionsIfDoneExists: false}], - errors: [{message: "Test without assertions is not allowed.", type: "CallExpression"}] - }, - { - code: + options: [{ assertsLimit: 1, skipSkipped: true, ignoreZeroAssertionsIfDoneExists: false }], + errors: [{ message: "Test without assertions is not allowed.", type: "CallExpression" }] + }, + { + code: "{{TEST}}('1234', function (notDone) {});", - options: [{assertsLimit: 1, skipSkipped: true, ignoreZeroAssertionsIfDoneExists: false}], - errors: [{message: "Test without assertions is not allowed.", type: "CallExpression"}] - } - ]; + options: [{ assertsLimit: 1, skipSkipped: true, ignoreZeroAssertionsIfDoneExists: false }], + errors: [{ message: "Test without assertions is not allowed.", type: "CallExpression" }] + } +] -function filter(combo) { - return !combo.code.match(/\{\s*\}/); +function filter (combo) { + return !combo.code.match(/\{\s*\}/) } -var validTests = j +const validTests = j .setTemplates(validTestTemplates) .createCombos(["code"], assertions) .useCombosAsTemplates() @@ -271,11 +271,11 @@ var validTests = j .createCombos(["code"], testHelpers.mochaDatasets) .uniqueCombos() .getCombos() - .filter(filter); + .filter(filter) -j.clearTemplates().clearCombos(); +j.clearTemplates().clearCombos() -var invalidTests = j +let invalidTests = j .setTemplates(invalidTestTemplates) .createCombos(["code"], assertions) .useCombosAsTemplates() @@ -284,9 +284,9 @@ var invalidTests = j .createCombos(["code"], testHelpers.mochaDatasets) .uniqueCombos() .getCombos() - .filter(filter); + .filter(filter) -j.clearTemplates().clearCombos(); +j.clearTemplates().clearCombos() invalidTests = j .setTemplates(invalidTestTemplatesWithoutAssertions) @@ -297,9 +297,9 @@ invalidTests = j .createCombos(["code"], testHelpers.mochaDatasets) .concatCombos(invalidTests) .uniqueCombos() - .getCombos(); + .getCombos() ruleTester.run("asserts-limit", rule, { valid: validTests, invalid: invalidTests -}); +}) diff --git a/tests/lib/rules/complexity-it.js b/tests/lib/rules/complexity-it.js index f2e719b..b98cc4c 100644 --- a/tests/lib/rules/complexity-it.js +++ b/tests/lib/rules/complexity-it.js @@ -1,23 +1,23 @@ -"use strict"; +"use strict" -var testHelpers = require("../../../lib/utils/tests.js"); -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const testHelpers = require("../../../lib/utils/tests.js") +const Jsonium = require("jsonium") +const j = new Jsonium() -var rule = require("../../../lib/rules/complexity-it"), - RuleTester = require("eslint").RuleTester; +const rule = require("../../../lib/rules/complexity-it") +const { RuleTester } = require("eslint") -var ruleTester = new RuleTester({env: {es6: true}}); +const ruleTester = new RuleTester({ env: { es6: true } }) -var assertions = [ - {ASSERT: "sinon.assert.calledOn(sp, {});", COMPLEXITY: "3"}, - {ASSERT: "expect(func()).to.be.equal(1);", COMPLEXITY: "4"}, - {ASSERT: "assert.equal(func(), 1, '4321');", COMPLEXITY: "3"}, - {ASSERT: "assert(func(), 1, '4321');", COMPLEXITY: "3"}, - {ASSERT: "func().should.be.equal(1);", COMPLEXITY: "4"} -]; +const assertions = [ + { ASSERT: "sinon.assert.calledOn(sp, {});", COMPLEXITY: "3" }, + { ASSERT: "expect(func()).to.be.equal(1);", COMPLEXITY: "4" }, + { ASSERT: "assert.equal(func(), 1, '4321');", COMPLEXITY: "3" }, + { ASSERT: "assert(func(), 1, '4321');", COMPLEXITY: "3" }, + { ASSERT: "func().should.be.equal(1);", COMPLEXITY: "4" } +] -var validTestTemplates = [ +const validTestTemplates = [ { code: "{{SUITE}}('3421', {{ES}}" + @@ -37,7 +37,7 @@ var validTestTemplates = [ "expect(result).to.be.equal(expected);" + "});" + "});", - options: [{maxAllowedComplexity: 6}] + options: [{ maxAllowedComplexity: 6 }] }, { code: @@ -48,7 +48,7 @@ var validTestTemplates = [ "expect(result).to.be.equal(expected);" + "});" + "});", - options: [{maxAllowedComplexity: 9}] + options: [{ maxAllowedComplexity: 9 }] }, { code: @@ -57,14 +57,14 @@ var validTestTemplates = [ "{{ASSERT}}" + "});" + "});", - options: [{maxAllowedComplexity: 0, skipSkipped: true}] + options: [{ maxAllowedComplexity: 0, skipSkipped: true }] }, { code: "{{TESTSKIP}}('1234', {{ES}} " + "{{ASSERT}}" + "});", - options: [{maxAllowedComplexity: 0, skipSkipped: true}] + options: [{ maxAllowedComplexity: 0, skipSkipped: true }] }, { code: @@ -73,14 +73,14 @@ var validTestTemplates = [ "{{ASSERT}}" + "});" + "});", - options: [{maxAllowedComplexity: 0, skipSkipped: true}] + options: [{ maxAllowedComplexity: 0, skipSkipped: true }] }, { code: "{{TESTSKIP}}('1234', {{ES}} " + "expect(func()).to.be.been.is.that.which.and.has.have.with.at.of.same.equal(1);" + "});", - options: [{maxAllowedComplexity: 0, skipSkipped: true}] + options: [{ maxAllowedComplexity: 0, skipSkipped: true }] }, { code: @@ -89,18 +89,18 @@ var validTestTemplates = [ "expect(func()).to.be.been.is.that.which.and.has.have.with.at.of.same.equal(1);" + "});" + "});", - options: [{maxAllowedComplexity: 0, skipSkipped: true}] + options: [{ maxAllowedComplexity: 0, skipSkipped: true }] } -]; +] -var invalidTestTemplates = [ +const invalidTestTemplates = [ { code: "{{TEST}}('1234', {{ES}} " + "{{ASSERT}}" + "});", - options: [{maxAllowedComplexity: 0}], - errors: [{ message: "`{{TEST}}` has a complexity of {{COMPLEXITY}}. Maximum allowed is 0.", type: "CallExpression"}] + options: [{ maxAllowedComplexity: 0 }], + errors: [{ message: "`{{TEST}}` has a complexity of {{COMPLEXITY}}. Maximum allowed is 0.", type: "CallExpression" }] }, { code: @@ -109,32 +109,32 @@ var invalidTestTemplates = [ "{{ASSERT}}" + "});" + "});", - options: [{maxAllowedComplexity: 0}], - errors: [{ message: "`{{TEST}}` has a complexity of {{COMPLEXITY}}. Maximum allowed is 0.", type: "CallExpression"}] + options: [{ maxAllowedComplexity: 0 }], + errors: [{ message: "`{{TEST}}` has a complexity of {{COMPLEXITY}}. Maximum allowed is 0.", type: "CallExpression" }] }, { code: "{{TESTSKIP}}('1234', {{ES}} " + "{{ASSERT}}" + "});", - options: [{maxAllowedComplexity: 0}], - errors: [{ message: "`{{TESTSKIP}}` has a complexity of {{COMPLEXITY}}. Maximum allowed is 0.", type: "CallExpression"}] + options: [{ maxAllowedComplexity: 0 }], + errors: [{ message: "`{{TESTSKIP}}` has a complexity of {{COMPLEXITY}}. Maximum allowed is 0.", type: "CallExpression" }] }, { code: "{{TEST}}('1234', {{ES}} " + "expect(func()).to.be.been.is.that.which.and.has.have.with.at.of.same.equal(1);" + "});", - options: [{maxAllowedComplexity: 0}], - errors: [{ message: "`{{TEST}}` has a complexity of 4. Maximum allowed is 0.", type: "CallExpression"}] + options: [{ maxAllowedComplexity: 0 }], + errors: [{ message: "`{{TEST}}` has a complexity of 4. Maximum allowed is 0.", type: "CallExpression" }] }, { code: "{{TESTSKIP}}('1234', {{ES}} " + "expect(func()).to.be.been.is.that.which.and.has.have.with.at.of.same.equal(1);" + "});", - options: [{maxAllowedComplexity: 0}], - errors: [{ message: "`{{TESTSKIP}}` has a complexity of 4. Maximum allowed is 0.", type: "CallExpression"}] + options: [{ maxAllowedComplexity: 0 }], + errors: [{ message: "`{{TESTSKIP}}` has a complexity of 4. Maximum allowed is 0.", type: "CallExpression" }] }, { code: @@ -143,11 +143,11 @@ var invalidTestTemplates = [ "expect(func()).to.be.been.is.that.which.and.has.have.with.at.of.same.equal(1);" + "});" + "});", - options: [{maxAllowedComplexity: 0}], - errors: [{ message: "`{{TEST}}` has a complexity of 4. Maximum allowed is 0.", type: "CallExpression"}] + options: [{ maxAllowedComplexity: 0 }], + errors: [{ message: "`{{TEST}}` has a complexity of 4. Maximum allowed is 0.", type: "CallExpression" }] } -]; -var validTests = j +] +const validTests = j .setTemplates(validTestTemplates) .createCombos(["code"], assertions) .useCombosAsTemplates() @@ -155,10 +155,10 @@ var validTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() -j.clearTemplates().clearCombos(); -var invalidTests = j +j.clearTemplates().clearCombos() +const invalidTests = j .setTemplates(invalidTestTemplates) .createCombos(["code", "errors.@each.message"], assertions) .useCombosAsTemplates() @@ -166,9 +166,9 @@ var invalidTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() ruleTester.run("complexity-it", rule, { valid: validTests, invalid: invalidTests -}); +}) diff --git a/tests/lib/rules/disallow-stub-spy-restore-in-it.js b/tests/lib/rules/disallow-stub-spy-restore-in-it.js index 915ba69..7aa76f7 100644 --- a/tests/lib/rules/disallow-stub-spy-restore-in-it.js +++ b/tests/lib/rules/disallow-stub-spy-restore-in-it.js @@ -1,14 +1,13 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/disallow-stub-spy-restore-in-it"), - RuleTester = require("eslint").RuleTester; -var testHelpers = require("../../../lib/utils/tests.js"); -var ruleTester = new RuleTester({env: {es6: true}}); -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const rule = require("../../../lib/rules/disallow-stub-spy-restore-in-it") +const { RuleTester } = require("eslint") +const testHelpers = require("../../../lib/utils/tests.js") +const ruleTester = new RuleTester({ env: { es6: true } }) +const Jsonium = require("jsonium") +const j = new Jsonium() - -var validTestTemplates = [ +const validTestTemplates = [ { code: "sinon.restore();" }, @@ -182,7 +181,7 @@ var validTestTemplates = [ "sinon.restore{{MOD}}();" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -191,7 +190,7 @@ var validTestTemplates = [ "sinon['restore']{{MOD}}();" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -200,7 +199,7 @@ var validTestTemplates = [ "sinon.stub{{MOD}}();" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -209,7 +208,7 @@ var validTestTemplates = [ "sinon['stub']{{MOD}}();" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -218,7 +217,7 @@ var validTestTemplates = [ "sinon.spy{{MOD}}();" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -227,7 +226,7 @@ var validTestTemplates = [ "sinon['spy']{{MOD}}();" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -238,7 +237,7 @@ var validTestTemplates = [ "});" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -249,59 +248,59 @@ var validTestTemplates = [ "});" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: "{{TESTSKIP}}('12345', {{ES}}" + "sinon.stub{{MOD}}().withArgs().returns();" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: "{{TESTSKIP}}('12345', {{ES}}" + "sinon['stub']{{MOD}}().withArgs().returns();" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] } -]; +] -var invalidTestTemplates = [ +const invalidTestTemplates = [ { code: "{{TEST}}('12345', {{ES}}" + "sinon.restore{{MOD}}();" + "});", - errors: [{message: "`restore` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`restore` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: "{{TEST}}('12345', {{ES}}" + "sinon['restore']{{MOD}}();" + "});", - errors: [{message: "`restore` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`restore` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: "{{TEST}}('12345', {{ES}}" + "sinon.stub{{MOD}}();" + "});", - errors: [{message: "`stub` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`stub` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: "{{TEST}}('12345', {{ES}}" + "sinon['stub']{{MOD}}();" + "});", - errors: [{message: "`stub` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`stub` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: "{{TEST}}('12345', {{ES}}" + "sinon.spy{{MOD}}();" + "});", - errors: [{message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: @@ -312,7 +311,7 @@ var invalidTestTemplates = [ "});" + "});" + "});", - errors: [{message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: @@ -323,21 +322,21 @@ var invalidTestTemplates = [ "});" + "});" + "});", - errors: [{message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: "{{TEST}}('12345', {{ES}}" + "sinon.stub{{MOD}}().withArgs().returns();" + "});", - errors: [{message: "`stub` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`stub` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: "{{TEST}}('12345', {{ES}}" + "sinon['stub']{{MOD}}().withArgs().returns();" + "});", - errors: [{message: "`stub` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`stub` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: @@ -346,7 +345,7 @@ var invalidTestTemplates = [ "sinon.restore{{MOD}}();" + "});" + "});", - errors: [{message: "`restore` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`restore` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: @@ -355,7 +354,7 @@ var invalidTestTemplates = [ "sinon['restore']{{MOD}}();" + "});" + "});", - errors: [{message: "`restore` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`restore` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: @@ -364,7 +363,7 @@ var invalidTestTemplates = [ "sinon.stub{{MOD}}();" + "});" + "});", - errors: [{message: "`stub` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`stub` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: @@ -373,7 +372,7 @@ var invalidTestTemplates = [ "sinon['stub']{{MOD}}();" + "});" + "});", - errors: [{message: "`stub` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`stub` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: @@ -382,7 +381,7 @@ var invalidTestTemplates = [ "sinon.spy{{MOD}}();" + "});" + "});", - errors: [{message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: @@ -391,7 +390,7 @@ var invalidTestTemplates = [ "sinon['spy']{{MOD}}();" + "});" + "});", - errors: [{message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: @@ -402,7 +401,7 @@ var invalidTestTemplates = [ "});" + "});" + "});", - errors: [{message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: @@ -413,48 +412,48 @@ var invalidTestTemplates = [ "});" + "});" + "});", - errors: [{message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "`spy` is not allowed to use inside `{{TEST}}`.", type: "CallExpression" }] }, { code: "{{TESTSKIP}}('12345', {{ES}}" + "sinon.stub{{MOD}}().withArgs().returns();" + "});", - errors: [{message: "`stub` is not allowed to use inside `{{TESTSKIP}}`.", type: "CallExpression"}] + errors: [{ message: "`stub` is not allowed to use inside `{{TESTSKIP}}`.", type: "CallExpression" }] }, { code: "{{TESTSKIP}}('12345', {{ES}}" + "sinon['stub']{{MOD}}().withArgs().returns();" + "});", - errors: [{message: "`stub` is not allowed to use inside `{{TESTSKIP}}`.", type: "CallExpression"}] + errors: [{ message: "`stub` is not allowed to use inside `{{TESTSKIP}}`.", type: "CallExpression" }] } -]; +] -var validTests = j +const validTests = j .setTemplates(validTestTemplates) .createCombos(["code"], testHelpers.mochaDatasets) .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() .useCombosAsTemplates() - .createCombos(["code"], [{MOD: ".apply"}, {MOD: ".call"}, {MOD: ""}]) + .createCombos(["code"], [{ MOD: ".apply" }, { MOD: ".call" }, { MOD: "" }]) .uniqueCombos() - .getCombos(); + .getCombos() -j.clearTemplates().clearCombos(); -var invalidTests = j +j.clearTemplates().clearCombos() +const invalidTests = j .setTemplates(invalidTestTemplates) .createCombos(["code", "errors.@each.message"], testHelpers.mochaDatasets) .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() .useCombosAsTemplates() - .createCombos(["code"], [{MOD: ".apply"}, {MOD: ".call"}, {MOD: ""}]) + .createCombos(["code"], [{ MOD: ".apply" }, { MOD: ".call" }, { MOD: "" }]) .uniqueCombos() - .getCombos(); + .getCombos() ruleTester.run("disallow-stub-spy-restore-in-it", rule, { valid: validTests, invalid: invalidTests -}); +}) diff --git a/tests/lib/rules/disallow-stub-window.js b/tests/lib/rules/disallow-stub-window.js index 4da9e61..30271de 100644 --- a/tests/lib/rules/disallow-stub-window.js +++ b/tests/lib/rules/disallow-stub-window.js @@ -1,26 +1,26 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/disallow-stub-window"), - RuleTester = require("eslint").RuleTester; -var testHelpers = require("../../../lib/utils/tests.js"); -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const rule = require("../../../lib/rules/disallow-stub-window") +const { RuleTester } = require("eslint") +const testHelpers = require("../../../lib/utils/tests.js") +const Jsonium = require("jsonium") +const j = new Jsonium() -var ruleTester = new RuleTester({env: {es6: true}}); +const ruleTester = new RuleTester({ env: { es6: true } }) -var m1 = "`sinon.stub` should not be used for `window.{{METHOD1}}`"; -var m2 = "`sinon.stub` should not be used for `window.{{METHOD2}}`"; +const m1 = "`sinon.stub` should not be used for `window.{{METHOD1}}`" +const m2 = "`sinon.stub` should not be used for `window.{{METHOD2}}`" -var templates = [ +const templates = [ { code: "{{CODE}}", options: [ - {methods: ["{{METHOD1}}", "{{METHOD2}}"]} + { methods: ["{{METHOD1}}", "{{METHOD2}}"] } ], errors: [ - {message: m1}, - {message: m2} + { message: m1 }, + { message: m2 } ] }, { @@ -31,11 +31,11 @@ var templates = [ "});" + "});", options: [ - {methods: ["{{METHOD1}}", "{{METHOD2}}"]} + { methods: ["{{METHOD1}}", "{{METHOD2}}"] } ], errors: [ - {message: m1}, - {message: m2} + { message: m1 }, + { message: m2 } ] }, { @@ -46,11 +46,11 @@ var templates = [ "});" + "});", options: [ - {methods: ["{{METHOD1}}", "{{METHOD2}}"]} + { methods: ["{{METHOD1}}", "{{METHOD2}}"] } ], errors: [ - {message: m1}, - {message: m2} + { message: m1 }, + { message: m2 } ] }, { @@ -61,11 +61,11 @@ var templates = [ "});" + "});", options: [ - {methods: ["{{METHOD1}}", "{{METHOD2}}"]} + { methods: ["{{METHOD1}}", "{{METHOD2}}"] } ], errors: [ - {message: m1}, - {message: m2} + { message: m1 }, + { message: m2 } ] }, { @@ -76,40 +76,39 @@ var templates = [ "});" + "});", options: [ - {methods: ["{{METHOD1}}", "{{METHOD2}}"]} + { methods: ["{{METHOD1}}", "{{METHOD2}}"] } ], errors: [ - {message: m1}, - {message: m2} + { message: m1 }, + { message: m2 } ] } -]; +] -var stubs = [ - {STUB: "sinon.stub"}, - {STUB: "sinon['stub']"}, - {STUB: "stub"} -]; +const stubs = [ + { STUB: "sinon.stub" }, + { STUB: "sinon['stub']" }, + { STUB: "stub" } +] -var codes = [ - {CODE: "{{STUB}}(window, '{{METHOD1}}'); {{STUB}}(window, '{{METHOD2}}');"}, - {CODE: "var stub = {{STUB}}(window, '{{METHOD1}}'); {{STUB}}(window, '{{METHOD2}}', function () {});"} -]; +const codes = [ + { CODE: "{{STUB}}(window, '{{METHOD1}}'); {{STUB}}(window, '{{METHOD2}}');" }, + { CODE: "var stub = {{STUB}}(window, '{{METHOD1}}'); {{STUB}}(window, '{{METHOD2}}', function () {});" } +] -var methods = [ - {METHOD1: "setTimeout", METHOD2: "clearTimeout"}, - {METHOD1: "setInterval", METHOD2: "ClearInterval"} -]; +const methods = [ + { METHOD1: "setTimeout", METHOD2: "clearTimeout" }, + { METHOD1: "setInterval", METHOD2: "ClearInterval" } +] -var hooks = [ - {HOOK: "before"}, - {HOOK: "beforeEach"}, - {HOOK: "after"}, - {HOOK: "afterEach"} -]; +const hooks = [ + { HOOK: "before" }, + { HOOK: "beforeEach" }, + { HOOK: "after" }, + { HOOK: "afterEach" } +] - -var validTests = j +const validTests = j .setTemplates(templates) .createCombos(["code"], hooks) .useCombosAsTemplates() @@ -125,11 +124,11 @@ var validTests = j .uniqueCombos() .getCombos() .map(function (c) { - c.options[0].methods = ["someFakeMethod"]; - return c; - }); + c.options[0].methods = ["someFakeMethod"] + return c + }) -var invalidTests = j +const invalidTests = j .setTemplates(templates) .createCombos(["code"], hooks) .useCombosAsTemplates() @@ -143,11 +142,11 @@ var invalidTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() ruleTester.run("disallow-stub-window", rule, { valid: [ "stub(notWindow, 'setTimeout');" ].concat(validTests), invalid: invalidTests -}); +}) diff --git a/tests/lib/rules/disallowed-usage.js b/tests/lib/rules/disallowed-usage.js index 905b7eb..acfa2f9 100644 --- a/tests/lib/rules/disallowed-usage.js +++ b/tests/lib/rules/disallowed-usage.js @@ -1,36 +1,36 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/disallowed-usage"), - RuleTester = require("eslint").RuleTester; -var testHelpers = require("../../../lib/utils/tests.js"); -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const rule = require("../../../lib/rules/disallowed-usage") +const { RuleTester } = require("eslint") +const testHelpers = require("../../../lib/utils/tests.js") +const Jsonium = require("jsonium") +const j = new Jsonium() -var ruleTester = new RuleTester({env: {es6: true}}); +const ruleTester = new RuleTester({ env: { es6: true } }) -var disallowed = [ - {CODE: "obj.subObj.prop = 1;", MESSAGE: "obj.subObj.prop", "options.0.test": [{o: "obj.subObj", p: ["prop"]}], "options.0.hook": [{o: "obj.subObj", p: ["prop"]}]}, - {CODE: "obj['subObj'].prop = 1;", MESSAGE: "obj.subObj.prop", "options.0.test": [{o: "obj.subObj", p: ["prop"]}], "options.0.hook": [{o: "obj.subObj", p: ["prop"]}]}, - {CODE: "obj.subObj['prop'] = 1;", MESSAGE: "obj.subObj.prop", "options.0.test": [{o: "obj.subObj", p: ["prop"]}], "options.0.hook": [{o: "obj.subObj", p: ["prop"]}]}, - {CODE: "obj.prop = '1';", MESSAGE: "obj.prop", "options.0.test": [{o: "obj", p: ["prop"]}], "options.0.hook": [{o: "obj", p: ["prop"]}]}, - {CODE: "obj['prop'] = '1';", MESSAGE: "obj.prop", "options.0.test": [{o: "obj", p: ["prop"]}], "options.0.hook": [{o: "obj", p: ["prop"]}]}, - {CODE: "expect(obj.property).to.be.equal('1');", MESSAGE: "obj.property", "options.0.test": [{o: "obj", p: ["property"]}], "options.0.hook": [{o: "obj", p: ["property"]}]}, - {CODE: "expect(obj['property']).to.be.equal('1');", MESSAGE: "obj.property", "options.0.test": [{o: "obj", p: ["property"]}], "options.0.hook": [{o: "obj", p: ["property"]}]}, - {CODE: "obj.subObj.method{{MOD}}(1, 2);", MESSAGE: "obj.subObj.method", "options.0.test": [{o: "obj.subObj", m: ["method"]}], "options.0.hook": [{o: "obj.subObj", m: ["method"]}]}, - {CODE: "obj['subObj'].method{{MOD}}(1, 2);", MESSAGE: "obj.subObj.method", "options.0.test": [{o: "obj.subObj", m: ["method"]}], "options.0.hook": [{o: "obj.subObj", m: ["method"]}]}, - {CODE: "obj.subObj['method']{{MOD}}(1, 2);", MESSAGE: "obj.subObj.method", "options.0.test": [{o: "obj.subObj", m: ["method"]}], "options.0.hook": [{o: "obj.subObj", m: ["method"]}]}, - {CODE: "obj.method{{MOD}}('1');", MESSAGE: "obj.method", "options.0.test": [{o: "obj", m: ["method"]}], "options.0.hook": [{o: "obj", m: ["method"]}]}, - {CODE: "method{{MOD}}();", MESSAGE: "method", "options.0.test": [{f: "method"}], "options.0.hook": [{f: "method"}]} -]; +const disallowed = [ + { CODE: "obj.subObj.prop = 1;", MESSAGE: "obj.subObj.prop", "options.0.test": [{ o: "obj.subObj", p: ["prop"] }], "options.0.hook": [{ o: "obj.subObj", p: ["prop"] }] }, + { CODE: "obj['subObj'].prop = 1;", MESSAGE: "obj.subObj.prop", "options.0.test": [{ o: "obj.subObj", p: ["prop"] }], "options.0.hook": [{ o: "obj.subObj", p: ["prop"] }] }, + { CODE: "obj.subObj['prop'] = 1;", MESSAGE: "obj.subObj.prop", "options.0.test": [{ o: "obj.subObj", p: ["prop"] }], "options.0.hook": [{ o: "obj.subObj", p: ["prop"] }] }, + { CODE: "obj.prop = '1';", MESSAGE: "obj.prop", "options.0.test": [{ o: "obj", p: ["prop"] }], "options.0.hook": [{ o: "obj", p: ["prop"] }] }, + { CODE: "obj['prop'] = '1';", MESSAGE: "obj.prop", "options.0.test": [{ o: "obj", p: ["prop"] }], "options.0.hook": [{ o: "obj", p: ["prop"] }] }, + { CODE: "expect(obj.property).to.be.equal('1');", MESSAGE: "obj.property", "options.0.test": [{ o: "obj", p: ["property"] }], "options.0.hook": [{ o: "obj", p: ["property"] }] }, + { CODE: "expect(obj['property']).to.be.equal('1');", MESSAGE: "obj.property", "options.0.test": [{ o: "obj", p: ["property"] }], "options.0.hook": [{ o: "obj", p: ["property"] }] }, + { CODE: "obj.subObj.method{{MOD}}(1, 2);", MESSAGE: "obj.subObj.method", "options.0.test": [{ o: "obj.subObj", m: ["method"] }], "options.0.hook": [{ o: "obj.subObj", m: ["method"] }] }, + { CODE: "obj['subObj'].method{{MOD}}(1, 2);", MESSAGE: "obj.subObj.method", "options.0.test": [{ o: "obj.subObj", m: ["method"] }], "options.0.hook": [{ o: "obj.subObj", m: ["method"] }] }, + { CODE: "obj.subObj['method']{{MOD}}(1, 2);", MESSAGE: "obj.subObj.method", "options.0.test": [{ o: "obj.subObj", m: ["method"] }], "options.0.hook": [{ o: "obj.subObj", m: ["method"] }] }, + { CODE: "obj.method{{MOD}}('1');", MESSAGE: "obj.method", "options.0.test": [{ o: "obj", m: ["method"] }], "options.0.hook": [{ o: "obj", m: ["method"] }] }, + { CODE: "method{{MOD}}();", MESSAGE: "method", "options.0.test": [{ f: "method" }], "options.0.hook": [{ f: "method" }] } +] -var hooks = [ - {HOOK: "before"}, - {HOOK: "beforeEach"}, - {HOOK: "after"}, - {HOOK: "afterEach"} -]; +const hooks = [ + { HOOK: "before" }, + { HOOK: "beforeEach" }, + { HOOK: "after" }, + { HOOK: "afterEach" } +] -var validTestTemplates = [ +const validTestTemplates = [ { code: "{{SUITESKIP}}('1234', {{ES}}" + @@ -73,8 +73,8 @@ var validTestTemplates = [ } ] } -]; -var invalidTestTemplates = [ +] +const invalidTestTemplates = [ { code: "{{SUITE}}('1234', {{ES}}" + @@ -88,7 +88,7 @@ var invalidTestTemplates = [ } ], errors: [ - {message: "`{{MESSAGE}}` is not allowed here."} + { message: "`{{MESSAGE}}` is not allowed here." } ] }, { @@ -104,7 +104,7 @@ var invalidTestTemplates = [ } ], errors: [ - {message: "`{{MESSAGE}}` is not allowed here."} + { message: "`{{MESSAGE}}` is not allowed here." } ] }, { @@ -122,9 +122,9 @@ var invalidTestTemplates = [ } ], errors: [ - {message: "`{{MESSAGE}}` is not allowed here."}, - {message: "`{{MESSAGE}}` is not allowed here."}, - {message: "`{{MESSAGE}}` is not allowed here."} + { message: "`{{MESSAGE}}` is not allowed here." }, + { message: "`{{MESSAGE}}` is not allowed here." }, + { message: "`{{MESSAGE}}` is not allowed here." } ] }, { @@ -142,9 +142,9 @@ var invalidTestTemplates = [ } ], errors: [ - {message: "`{{MESSAGE}}` is not allowed here."}, - {message: "`{{MESSAGE}}` is not allowed here."}, - {message: "`{{MESSAGE}}` is not allowed here."} + { message: "`{{MESSAGE}}` is not allowed here." }, + { message: "`{{MESSAGE}}` is not allowed here." }, + { message: "`{{MESSAGE}}` is not allowed here." } ] }, { @@ -164,13 +164,13 @@ var invalidTestTemplates = [ } ], errors: [ - {message: "`{{MESSAGE}}` is not allowed here."}, - {message: "`{{MESSAGE}}` is not allowed here."} + { message: "`{{MESSAGE}}` is not allowed here." }, + { message: "`{{MESSAGE}}` is not allowed here." } ] } -]; +] -var validTests = j +const validTests = j .setTemplates(validTestTemplates) .createCombos(["code"], hooks) .useCombosAsTemplates() @@ -180,12 +180,12 @@ var validTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .useCombosAsTemplates() - .createCombos(["code"], [{MOD: ".call"}, {MOD: ".apply"}, {MOD: ""}]) + .createCombos(["code"], [{ MOD: ".call" }, { MOD: ".apply" }, { MOD: "" }]) .uniqueCombos() - .getCombos(); + .getCombos() -j.clearTemplates().clearCombos(); -var invalidTests = j +j.clearTemplates().clearCombos() +const invalidTests = j .setTemplates(invalidTestTemplates) .createCombos(["code"], hooks) .useCombosAsTemplates() @@ -195,13 +195,13 @@ var invalidTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .useCombosAsTemplates() - .createCombos(["code"], [{MOD: ".call"}, {MOD: ".apply"}, {MOD: ""}]) + .createCombos(["code"], [{ MOD: ".call" }, { MOD: ".apply" }, { MOD: "" }]) .uniqueCombos() - .getCombos(); + .getCombos() ruleTester.run("disallowed-usage", rule, { valid: [ "ifNoOptionsJustIgnore;" ].concat(validTests), invalid: invalidTests -}); +}) diff --git a/tests/lib/rules/invalid-assertions.js b/tests/lib/rules/invalid-assertions.js index af08d13..8b9cd65 100644 --- a/tests/lib/rules/invalid-assertions.js +++ b/tests/lib/rules/invalid-assertions.js @@ -1,36 +1,36 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/invalid-assertions"), - RuleTester = require("eslint").RuleTester; -var testHelpers = require("../../../lib/utils/tests.js"); -var n = require("../../../lib/utils/node.js"); -var m = "Invalid assertion usage."; -var ruleTester = new RuleTester({env: {es6: true}}); +const rule = require("../../../lib/rules/invalid-assertions") +const { RuleTester } = require("eslint") +const testHelpers = require("../../../lib/utils/tests.js") +const n = require("../../../lib/utils/node.js") +const m = "Invalid assertion usage." +const ruleTester = new RuleTester({ env: { es6: true } }) -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const Jsonium = require("jsonium") +const j = new Jsonium() -var chains = n.chaiChainable.map(function (c) { - return {CHAIN: "." + c}; -}); +const chains = n.chaiChainable.map(function (c) { + return { CHAIN: "." + c } +}) -chains.push({CHAIN: ""}); +chains.push({ CHAIN: "" }) -var assertions = [ - {ASSERTION: "expect(1){{CHAIN}};", TYPE: "CallExpression"}, - {ASSERTION: "chai.expect(1){{CHAIN}};", TYPE: "CallExpression"}, - {ASSERTION: "chai['expect'](1){{CHAIN}};", TYPE: "CallExpression"}, - {ASSERTION: "'1'.should{{CHAIN}};", TYPE: "MemberExpression"}, - {ASSERTION: "'1'['should']{{CHAIN}};", TYPE: "MemberExpression"} -]; +let assertions = [ + { ASSERTION: "expect(1){{CHAIN}};", TYPE: "CallExpression" }, + { ASSERTION: "chai.expect(1){{CHAIN}};", TYPE: "CallExpression" }, + { ASSERTION: "chai['expect'](1){{CHAIN}};", TYPE: "CallExpression" }, + { ASSERTION: "'1'.should{{CHAIN}};", TYPE: "MemberExpression" }, + { ASSERTION: "'1'['should']{{CHAIN}};", TYPE: "MemberExpression" } +] assertions = j .setTemplates(assertions) .createCombos("ASSERTION", chains) .uniqueCombos() - .getCombos(); + .getCombos() -var validTestTemplates = [ +const validTestTemplates = [ { code: "{{ASSERTION}}" @@ -51,7 +51,7 @@ var validTestTemplates = [ "})" + "})", options: [ - {skipSkipped: true} + { skipSkipped: true } ] }, { @@ -62,12 +62,12 @@ var validTestTemplates = [ "})" + "})", options: [ - {skipSkipped: true} + { skipSkipped: true } ] } -]; +] -var invalidTestTemplates = [ +const invalidTestTemplates = [ { code: "{{SUITE}}('1234', {{ES}}" + @@ -76,12 +76,12 @@ var invalidTestTemplates = [ "})" + "})", errors: [ - {message: m, type: "{{TYPE}}"} + { message: m, type: "{{TYPE}}" } ] } -]; +] -var validTests = j +const validTests = j .setTemplates(validTestTemplates) .createCombos(["code"], assertions) .useCombosAsTemplates() @@ -89,9 +89,9 @@ var validTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() -var invalidTests = j +const invalidTests = j .setTemplates(invalidTestTemplates) .createCombos(["code", "errors.@each.type"], assertions) .useCombosAsTemplates() @@ -99,7 +99,7 @@ var invalidTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() ruleTester.run("invalid-assertions", rule, { valid: [ @@ -110,4 +110,4 @@ ruleTester.run("invalid-assertions", rule, { "})" ].concat(validTests), invalid: invalidTests -}); +}) diff --git a/tests/lib/rules/no-assertions-in-loop.js b/tests/lib/rules/no-assertions-in-loop.js index e9d470f..6f58788 100644 --- a/tests/lib/rules/no-assertions-in-loop.js +++ b/tests/lib/rules/no-assertions-in-loop.js @@ -1,21 +1,21 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/no-assertions-in-loop"), - RuleTester = require("eslint").RuleTester; -var testHelpers = require("../../../lib/utils/tests.js"); -var ruleTester = new RuleTester({env: {es6: true}}); +const rule = require("../../../lib/rules/no-assertions-in-loop") +const { RuleTester } = require("eslint") +const testHelpers = require("../../../lib/utils/tests.js") +const ruleTester = new RuleTester({ env: { es6: true } }) -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const Jsonium = require("jsonium") +const j = new Jsonium() -var loops = [ - {code: "for(var i = 0; i < 5; i++) {{{ASSERTION}}}"}, - {code: "for(var i in obj) {{{ASSERTION}}}"}, - {code: "while(i < 5) {{{ASSERTION}}}"}, - {code: "do {{{ASSERTION}}} while (i < 5)"} -]; +const loops = [ + { code: "for(var i = 0; i < 5; i++) {{{ASSERTION}}}" }, + { code: "for(var i in obj) {{{ASSERTION}}}" }, + { code: "while(i < 5) {{{ASSERTION}}}" }, + { code: "do {{{ASSERTION}}} while (i < 5)" } +] -var pLoops = [ +const pLoops = [ { LO: "for(var i = 0; i < 5; i++) {", OP: "}" @@ -32,20 +32,20 @@ var pLoops = [ LO: "do {", OP: "} while (i < 5)" } -]; +] -var assertions = [ - {ASSERTION: "assert.equal(1, 1);"}, - {ASSERTION: "assert(1, 1);"}, - {ASSERTION: "assert['equal'](1, 1);"}, - {ASSERTION: "expect(1).to.be.equal(1);"}, - {ASSERTION: "'1'.should.be.equal('1');"}, - {ASSERTION: "'1'['should'].be.equal('1');"}, - {ASSERTION: "sinon.assert.called(a, 1);"}, - {ASSERTION: "sinon['assert'].called(a, 1);"} -]; +const assertions = [ + { ASSERTION: "assert.equal(1, 1);" }, + { ASSERTION: "assert(1, 1);" }, + { ASSERTION: "assert['equal'](1, 1);" }, + { ASSERTION: "expect(1).to.be.equal(1);" }, + { ASSERTION: "'1'.should.be.equal('1');" }, + { ASSERTION: "'1'['should'].be.equal('1');" }, + { ASSERTION: "sinon.assert.called(a, 1);" }, + { ASSERTION: "sinon['assert'].called(a, 1);" } +] -var validTestTemplates = [ +const validTestTemplates = [ { code: "{{LO}}" + @@ -71,7 +71,7 @@ var validTestTemplates = [ "{{LOOP}}" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -80,7 +80,7 @@ var validTestTemplates = [ "{{LOOP}}" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -91,11 +91,11 @@ var validTestTemplates = [ "});" + "});" + "});", - options: [{skipSkipped: true, extraMemberExpression: ["forEach"]}] + options: [{ skipSkipped: true, extraMemberExpression: ["forEach"] }] } -]; +] -var invalidTestTemplates = [ +const invalidTestTemplates = [ { code: "{{SUITE}}('1234', {{ES}}" + @@ -104,7 +104,7 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: "Assertions should not be used in loops."} + { message: "Assertions should not be used in loops." } ] }, { @@ -115,7 +115,7 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: "Assertions should not be used in loops."} + { message: "Assertions should not be used in loops." } ] }, { @@ -126,7 +126,7 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: "Assertions should not be used in loops."} + { message: "Assertions should not be used in loops." } ] }, { @@ -138,21 +138,21 @@ var invalidTestTemplates = [ "});" + "});" + "});", - options: [{extraMemberExpression: ["forEach"]}], + options: [{ extraMemberExpression: ["forEach"] }], errors: [ - {message: "Assertions should not be used in loops."} + { message: "Assertions should not be used in loops." } ] } -]; +] -var loopsWithAssertions = j +const loopsWithAssertions = j .setTemplates(loops) .createCombos("code", assertions) .uniqueCombos() .switchKeys("code", "LOOP") - .getCombos(); + .getCombos() -var validTests = j +const validTests = j .setTemplates(validTestTemplates) .createCombos(["code"], pLoops) .useCombosAsTemplates() @@ -164,11 +164,11 @@ var validTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() -j.clearTemplates().clearCombos(); +j.clearTemplates().clearCombos() -var invalidTests = j +const invalidTests = j .setTemplates(invalidTestTemplates) .createCombos(["code"], loopsWithAssertions) .useCombosAsTemplates() @@ -178,9 +178,9 @@ var invalidTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() ruleTester.run("no-assertions-in-loop", rule, { valid: validTests, invalid: invalidTests -}); +}) diff --git a/tests/lib/rules/no-assertions-outside-it.js b/tests/lib/rules/no-assertions-outside-it.js index 9440843..ecb0f63 100644 --- a/tests/lib/rules/no-assertions-outside-it.js +++ b/tests/lib/rules/no-assertions-outside-it.js @@ -1,26 +1,26 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/no-assertions-outside-it"), - RuleTester = require("eslint").RuleTester; +const rule = require("../../../lib/rules/no-assertions-outside-it") +const { RuleTester } = require("eslint") -var ruleTester = new RuleTester({env: {es6: true}}); +const ruleTester = new RuleTester({ env: { es6: true } }) -var testHelpers = require("../../../lib/utils/tests.js"); +const testHelpers = require("../../../lib/utils/tests.js") -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const Jsonium = require("jsonium") +const j = new Jsonium() -var asserts = [ - {ASSERT: "expect(1).to.be.equal(1);", TYPE: "MemberExpression"}, - {ASSERT: "'1'.should.equal('1');", TYPE: "MemberExpression"}, - {ASSERT: "'1'['should'].equal('1');", TYPE: "MemberExpression"}, - {ASSERT: "assert.equal(1, 1);", TYPE: "CallExpression"}, - {ASSERT: "assert(1, 1);", TYPE: "ExpressionStatement"}, - {ASSERT: "sinon.assert.calledOn(sp, {});", TYPE: "MemberExpression"}, - {ASSERT: "sinon['assert'].calledOn(sp, {});", TYPE: "MemberExpression"} -]; +const asserts = [ + { ASSERT: "expect(1).to.be.equal(1);", TYPE: "MemberExpression" }, + { ASSERT: "'1'.should.equal('1');", TYPE: "MemberExpression" }, + { ASSERT: "'1'['should'].equal('1');", TYPE: "MemberExpression" }, + { ASSERT: "assert.equal(1, 1);", TYPE: "CallExpression" }, + { ASSERT: "assert(1, 1);", TYPE: "ExpressionStatement" }, + { ASSERT: "sinon.assert.calledOn(sp, {});", TYPE: "MemberExpression" }, + { ASSERT: "sinon['assert'].calledOn(sp, {});", TYPE: "MemberExpression" } +] -var validTestTemplates = [ +const validTestTemplates = [ { code: "{{TEST}}('1234', {{ES}}" + @@ -140,7 +140,7 @@ var validTestTemplates = [ "{{SUITESKIP}}('1234', {{ES}}" + "{{ASSERT}}" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -148,23 +148,23 @@ var validTestTemplates = [ "{{TEST}}('321', {{ES}}});" + "{{ASSERT}}" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: "{{SUITESKIP}}('1234', {{ES}}" + "{{ASSERT}}" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] } -]; +] -var invalidTestTemplates = [ +const invalidTestTemplates = [ { code: "{{ASSERT}}", errors: [ - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"} + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" } ] }, { @@ -172,8 +172,8 @@ var invalidTestTemplates = [ "{{ASSERT}}" + "{{ASSERT}}", errors: [ - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"}, - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"} + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" }, + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" } ] }, { @@ -182,7 +182,7 @@ var invalidTestTemplates = [ "{{ASSERT}}" + "});", errors: [ - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"} + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" } ] }, { @@ -193,7 +193,7 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"} + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" } ] }, { @@ -206,7 +206,7 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"} + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" } ] }, { @@ -216,7 +216,7 @@ var invalidTestTemplates = [ "{{ASSERT}}" + "});", errors: [ - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"} + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" } ] }, { @@ -228,10 +228,10 @@ var invalidTestTemplates = [ "{{ASSERT}}" + "});", errors: [ - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"}, - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"}, - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"}, - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"} + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" }, + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" }, + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" }, + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" } ] }, { @@ -241,7 +241,7 @@ var invalidTestTemplates = [ "{{ASSERT}}" + "});", errors: [ - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"} + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" } ] }, { @@ -250,7 +250,7 @@ var invalidTestTemplates = [ "{{ASSERT}}" + "});", errors: [ - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"} + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" } ] }, { @@ -262,15 +262,15 @@ var invalidTestTemplates = [ "{{ASSERT}}" + "});", errors: [ - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"}, - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"}, - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"}, - {message: "Assertion outside tests is not allowed.", type: "{{TYPE}}"} + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" }, + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" }, + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" }, + { message: "Assertion outside tests is not allowed.", type: "{{TYPE}}" } ] } -]; +] -var validTests = j +const validTests = j .setTemplates(validTestTemplates) .createCombos(["code"], asserts) .useCombosAsTemplates() @@ -278,11 +278,11 @@ var validTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() -j.clearTemplates().clearCombos(); +j.clearTemplates().clearCombos() -var invalidTests = j +const invalidTests = j .setTemplates(invalidTestTemplates) .createCombos(["code", "errors.@each.type"], asserts) .useCombosAsTemplates() @@ -290,10 +290,9 @@ var invalidTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); - + .getCombos() ruleTester.run("no-assertions-outside-it", rule, { valid: validTests, invalid: invalidTests -}); +}) diff --git a/tests/lib/rules/no-empty-body.js b/tests/lib/rules/no-empty-body.js index 424b654..2c9264f 100644 --- a/tests/lib/rules/no-empty-body.js +++ b/tests/lib/rules/no-empty-body.js @@ -1,35 +1,35 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/no-empty-body"), - RuleTester = require("eslint").RuleTester; -var testHelpers = require("../../../lib/utils/tests.js"); -var ruleTester = new RuleTester({env: {es6: true}}); +const rule = require("../../../lib/rules/no-empty-body") +const { RuleTester } = require("eslint") +const testHelpers = require("../../../lib/utils/tests.js") +const ruleTester = new RuleTester({ env: { es6: true } }) -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const Jsonium = require("jsonium") +const j = new Jsonium() -var msg = "Empty function is not allowed here."; -var hooks = [ - {HO: "before({{ES}}", OK: "});"}, - {HO: "beforeEach({{ES}}", OK: "});"}, - {HO: "after({{ES}}", OK: "});"}, - {HO: "afterEach({{ES}}", OK: "});"}, - {HO: "before('12345', {{ES}}", OK: "});"}, - {HO: "beforeEach('12345', {{ES}}", OK: "});"}, - {HO: "after('12345', {{ES}}", OK: "});"}, - {HO: "afterEach('12345', {{ES}}", OK: "});"} -]; -var emptyBodies = [ - {BODY: ""}, - {BODY: "/* some comment */"}, - {BODY: "// some comment\n"} -]; +const msg = "Empty function is not allowed here." +const hooks = [ + { HO: "before({{ES}}", OK: "});" }, + { HO: "beforeEach({{ES}}", OK: "});" }, + { HO: "after({{ES}}", OK: "});" }, + { HO: "afterEach({{ES}}", OK: "});" }, + { HO: "before('12345', {{ES}}", OK: "});" }, + { HO: "beforeEach('12345', {{ES}}", OK: "});" }, + { HO: "after('12345', {{ES}}", OK: "});" }, + { HO: "afterEach('12345', {{ES}}", OK: "});" } +] +const emptyBodies = [ + { BODY: "" }, + { BODY: "/* some comment */" }, + { BODY: "// some comment\n" } +] -var validTestTemplates = [ +const validTestTemplates = [ { code: "{{SUITESKIP}}('1234', {{ES}}{{BODY}}});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -38,7 +38,7 @@ var validTestTemplates = [ "{{BODY}}" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -47,12 +47,12 @@ var validTestTemplates = [ "{{BODY}}" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: "{{SUITESKIP}}('1234', {{ES}}{{HO}} {{BODY}} {{OK}}});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -61,23 +61,23 @@ var validTestTemplates = [ "{{HO}} {{BODY}} {{OK}}" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] } -]; +] -var invalidTestTemplates = [ +const invalidTestTemplates = [ { code: "{{SUITE}}('1234', {{ES}}{{BODY}}});", errors: [ - {message: msg} + { message: msg } ] }, { code: "{{SUITE}}('1234', {{ES}}{{HO}} {{BODY}} {{OK}}});", errors: [ - {message: msg} + { message: msg } ] }, { @@ -88,7 +88,7 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: msg} + { message: msg } ] }, { @@ -102,15 +102,15 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: msg}, - {message: msg} + { message: msg }, + { message: msg } ] }, { code: "{{SUITESKIP}}('1234', {{ES}}{{BODY}}});", errors: [ - {message: msg} + { message: msg } ] }, { @@ -121,7 +121,7 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: msg} + { message: msg } ] }, { @@ -132,12 +132,12 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: msg} + { message: msg } ] } -]; +] -var validTests = j +const validTests = j .setTemplates(validTestTemplates) .createCombos(["code"], emptyBodies) .useCombosAsTemplates() @@ -147,11 +147,11 @@ var validTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() -j.clearTemplates().clearCombos(); +j.clearTemplates().clearCombos() -var invalidTests = j +const invalidTests = j .setTemplates(invalidTestTemplates) .createCombos(["code"], emptyBodies) .useCombosAsTemplates() @@ -161,12 +161,11 @@ var invalidTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); - + .getCombos() ruleTester.run("no-empty-body", rule, { valid: [ "var a = function () {}" ].concat(validTests), invalid: invalidTests -}); +}) diff --git a/tests/lib/rules/no-empty-title.js b/tests/lib/rules/no-empty-title.js index d7ce4e1..735062e 100644 --- a/tests/lib/rules/no-empty-title.js +++ b/tests/lib/rules/no-empty-title.js @@ -1,20 +1,20 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/no-empty-title"), - RuleTester = require("eslint").RuleTester; -var testHelpers = require("../../../lib/utils/tests.js"); -var ruleTester = new RuleTester({env: {es6: true}}); +const rule = require("../../../lib/rules/no-empty-title") +const { RuleTester } = require("eslint") +const testHelpers = require("../../../lib/utils/tests.js") +const ruleTester = new RuleTester({ env: { es6: true } }) -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const Jsonium = require("jsonium") +const j = new Jsonium() -var titles = [ - {TITLE: "''"}, - {TITLE: "' '"}, - {TITLE: "'\t'"} -]; +const titles = [ + { TITLE: "''" }, + { TITLE: "' '" }, + { TITLE: "'\t'" } +] -var validTestTemplates = [ +const validTestTemplates = [ { code: "{{TEST}}('some title', {{ES}}});" @@ -71,52 +71,52 @@ var validTestTemplates = [ { code: "{{TESTSKIP}}({{TITLE}}, {{ES}}});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: "{{SUITESKIP}}({{TITLE}}, {{ES}}" + "{{TEST}}('some title', {{ES}}});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] } -]; +] -var invalidTestTemplates = [ +const invalidTestTemplates = [ { code: "{{TEST}}({{TITLE}}, {{ES}}});", - errors: [{message: "Empty title is not allowed for `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "Empty title is not allowed for `{{TEST}}`.", type: "CallExpression" }] }, { code: "{{SUITESKIP}}('123', {{ES}}" + "{{TEST}}({{TITLE}}, {{ES}}});" + "});", - errors: [{message: "Empty title is not allowed for `{{TEST}}`.", type: "CallExpression"}] + errors: [{ message: "Empty title is not allowed for `{{TEST}}`.", type: "CallExpression" }] }, { code: "{{SUITE}}({{TITLE}}, {{ES}}" + "{{TEST}}('some title', {{ES}}});" + "});", - errors: [{message: "Empty title is not allowed for `{{SUITE}}`.", type: "CallExpression"}] + errors: [{ message: "Empty title is not allowed for `{{SUITE}}`.", type: "CallExpression" }] }, { code: "{{TESTSKIP}}({{TITLE}}, {{ES}}});", - errors: [{message: "Empty title is not allowed for `{{TESTSKIP}}`.", type: "CallExpression"}] + errors: [{ message: "Empty title is not allowed for `{{TESTSKIP}}`.", type: "CallExpression" }] }, { code: "{{SUITESKIP}}({{TITLE}}, {{ES}}" + "{{TEST}}('some title', {{ES}}});" + "});", - errors: [{message: "Empty title is not allowed for `{{SUITESKIP}}`.", type: "CallExpression"}] + errors: [{ message: "Empty title is not allowed for `{{SUITESKIP}}`.", type: "CallExpression" }] } -]; +] -var validTests = j +const validTests = j .setTemplates(validTestTemplates) .createCombos(["code"], titles) .useCombosAsTemplates() @@ -124,11 +124,11 @@ var validTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() -j.clearTemplates().clearCombos(); +j.clearTemplates().clearCombos() -var invalidTests = j +const invalidTests = j .setTemplates(invalidTestTemplates) .createCombos(["code"], titles) .useCombosAsTemplates() @@ -136,8 +136,7 @@ var invalidTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); - + .getCombos() ruleTester.run("no-empty-title", rule, { valid: [ @@ -146,4 +145,4 @@ ruleTester.run("no-empty-title", rule, { "});" ].concat(validTests), invalid: invalidTests -}); +}) diff --git a/tests/lib/rules/no-eql-primitives.js b/tests/lib/rules/no-eql-primitives.js index ad5f78c..ce13f1c 100644 --- a/tests/lib/rules/no-eql-primitives.js +++ b/tests/lib/rules/no-eql-primitives.js @@ -1,57 +1,57 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/no-eql-primitives"), - RuleTester = require("eslint").RuleTester; -var testHelpers = require("../../../lib/utils/tests.js"); -var ruleTester = new RuleTester({env: {es6: true}}); +const rule = require("../../../lib/rules/no-eql-primitives") +const { RuleTester } = require("eslint") +const testHelpers = require("../../../lib/utils/tests.js") +const ruleTester = new RuleTester({ env: { es6: true } }) -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const Jsonium = require("jsonium") +const j = new Jsonium() -var invalidVals = [ - {VAL: "1"}, - {VAL: "true"}, - {VAL: "''"}, - {VAL: "null"} -]; +const invalidVals = [ + { VAL: "1" }, + { VAL: "true" }, + { VAL: "''" }, + { VAL: "null" } +] -var validVals = [ - {VAL: "{}"}, - {VAL: "b"} -]; +const validVals = [ + { VAL: "{}" }, + { VAL: "b" } +] -var invalidAssertions = [ - {INVALID_ASSERTION: "assert.deepEqual(a, {{VAL}});", IN_MESSAGE: "assert.deepEqual"}, - {INVALID_ASSERTION: "assert['deepEqual'](a, {{VAL}});", IN_MESSAGE: "assert.deepEqual"}, - {INVALID_ASSERTION: "assert.notDeepEqual(a, {{VAL}});", IN_MESSAGE: "assert.notDeepEqual"}, - {INVALID_ASSERTION: "assert['notDeepEqual'](a, {{VAL}});", IN_MESSAGE: "assert.notDeepEqual"}, - {INVALID_ASSERTION: "expect(a).to.be.eql({{VAL}});", IN_MESSAGE: ".eql"}, - {INVALID_ASSERTION: "expect(a).to.be.deep.equal({{VAL}});", IN_MESSAGE: ".deep.equal"}, - {INVALID_ASSERTION: "a.should.be.eql({{VAL}});", IN_MESSAGE: ".eql"}, - {INVALID_ASSERTION: "a['should'].be.eql({{VAL}});", IN_MESSAGE: ".eql"}, - {INVALID_ASSERTION: "a.should.be.deep.equal({{VAL}});", IN_MESSAGE: ".deep.equal"}, - {INVALID_ASSERTION: "a['should'].be.deep.equal({{VAL}});", IN_MESSAGE: ".deep.equal"} -]; -var validAssertions = [ - {ASSERTION: "assert.deepEqual(a, {{VAL}});"}, - {ASSERTION: "chai.assert.deepEqual(a, {{VAL}});"}, - {ASSERTION: "chai['assert'].deepEqual(a, {{VAL}});"}, - {ASSERTION: "assert['deepEqual'](a, {{VAL}});"}, - {ASSERTION: "chai.assert['deepEqual'](a, {{VAL}});"}, - {ASSERTION: "assert.notDeepEqual(a, {{VAL}});"}, - {ASSERTION: "chai.assert.notDeepEqual(a, {{VAL}});"}, - {ASSERTION: "chai['assert'].notDeepEqual(a, {{VAL}});"}, - {ASSERTION: "assert['notDeepEqual'](a, {{VAL}});"}, - {ASSERTION: "expect(a).to.be.eql({{VAL}});"}, - {ASSERTION: "chai.expect(a).to.be.eql({{VAL}});"}, - {ASSERTION: "chai['expect'](a).to.be.eql({{VAL}});"}, - {ASSERTION: "a.should.be.eql({{VAL}});"}, - {ASSERTION: "a['should'].be.eql({{VAL}});"}, - {ASSERTION: "a.should.be.deep.equal({{VAL}});"}, - {ASSERTION: "a['should'].be.deep.equal({{VAL}});"} -]; +let invalidAssertions = [ + { INVALID_ASSERTION: "assert.deepEqual(a, {{VAL}});", IN_MESSAGE: "assert.deepEqual" }, + { INVALID_ASSERTION: "assert['deepEqual'](a, {{VAL}});", IN_MESSAGE: "assert.deepEqual" }, + { INVALID_ASSERTION: "assert.notDeepEqual(a, {{VAL}});", IN_MESSAGE: "assert.notDeepEqual" }, + { INVALID_ASSERTION: "assert['notDeepEqual'](a, {{VAL}});", IN_MESSAGE: "assert.notDeepEqual" }, + { INVALID_ASSERTION: "expect(a).to.be.eql({{VAL}});", IN_MESSAGE: ".eql" }, + { INVALID_ASSERTION: "expect(a).to.be.deep.equal({{VAL}});", IN_MESSAGE: ".deep.equal" }, + { INVALID_ASSERTION: "a.should.be.eql({{VAL}});", IN_MESSAGE: ".eql" }, + { INVALID_ASSERTION: "a['should'].be.eql({{VAL}});", IN_MESSAGE: ".eql" }, + { INVALID_ASSERTION: "a.should.be.deep.equal({{VAL}});", IN_MESSAGE: ".deep.equal" }, + { INVALID_ASSERTION: "a['should'].be.deep.equal({{VAL}});", IN_MESSAGE: ".deep.equal" } +] +let validAssertions = [ + { ASSERTION: "assert.deepEqual(a, {{VAL}});" }, + { ASSERTION: "chai.assert.deepEqual(a, {{VAL}});" }, + { ASSERTION: "chai['assert'].deepEqual(a, {{VAL}});" }, + { ASSERTION: "assert['deepEqual'](a, {{VAL}});" }, + { ASSERTION: "chai.assert['deepEqual'](a, {{VAL}});" }, + { ASSERTION: "assert.notDeepEqual(a, {{VAL}});" }, + { ASSERTION: "chai.assert.notDeepEqual(a, {{VAL}});" }, + { ASSERTION: "chai['assert'].notDeepEqual(a, {{VAL}});" }, + { ASSERTION: "assert['notDeepEqual'](a, {{VAL}});" }, + { ASSERTION: "expect(a).to.be.eql({{VAL}});" }, + { ASSERTION: "chai.expect(a).to.be.eql({{VAL}});" }, + { ASSERTION: "chai['expect'](a).to.be.eql({{VAL}});" }, + { ASSERTION: "a.should.be.eql({{VAL}});" }, + { ASSERTION: "a['should'].be.eql({{VAL}});" }, + { ASSERTION: "a.should.be.deep.equal({{VAL}});" }, + { ASSERTION: "a['should'].be.deep.equal({{VAL}});" } +] -var validTestTemplates = [ +const validTestTemplates = [ { code: "{{TEST}}('123', {{ES}}" + @@ -65,7 +65,7 @@ var validTestTemplates = [ "{{INVALID_ASSERTION}}" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -74,18 +74,18 @@ var validTestTemplates = [ "{{INVALID_ASSERTION}}" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] } -]; +] -var invalidTestTemplates = [ +const invalidTestTemplates = [ { code: "{{TEST}}('123', {{ES}}" + "{{INVALID_ASSERTION}}" + "});", errors: [ - {message: "`{{IN_MESSAGE}}` should not be used with primitives.", type: "MemberExpression"} + { message: "`{{IN_MESSAGE}}` should not be used with primitives.", type: "MemberExpression" } ] }, { @@ -94,7 +94,7 @@ var invalidTestTemplates = [ "{{INVALID_ASSERTION}}" + "});", errors: [ - {message: "`{{IN_MESSAGE}}` should not be used with primitives.", type: "MemberExpression"} + { message: "`{{IN_MESSAGE}}` should not be used with primitives.", type: "MemberExpression" } ] }, { @@ -105,32 +105,32 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: "`{{IN_MESSAGE}}` should not be used with primitives.", type: "MemberExpression"} + { message: "`{{IN_MESSAGE}}` should not be used with primitives.", type: "MemberExpression" } ] } -]; +] validAssertions = j .setTemplates(validAssertions) .createCombos(["ASSERTION"], validVals) .uniqueCombos() - .getCombos(); + .getCombos() j .clearTemplates() - .clearCombos(); + .clearCombos() invalidAssertions = j .setTemplates(invalidAssertions) .createCombos(["INVALID_ASSERTION"], invalidVals) .uniqueCombos() - .getCombos(); + .getCombos() j .clearTemplates() - .clearCombos(); + .clearCombos() -var validTests = j +const validTests = j .setTemplates(validTestTemplates) .createCombos(["code"], validAssertions) .useCombosAsTemplates() @@ -138,11 +138,11 @@ var validTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() -j.clearTemplates().clearCombos(); +j.clearTemplates().clearCombos() -var invalidTests = j +const invalidTests = j .setTemplates(invalidTestTemplates) .createCombos(["code", "errors.@each.message"], invalidAssertions) .useCombosAsTemplates() @@ -150,7 +150,7 @@ var invalidTests = j .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() ruleTester.run("no-eql-primitives", rule, { valid: [ @@ -163,7 +163,7 @@ ruleTester.run("no-eql-primitives", rule, { "assert.deepEqual(a, 1)" + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, "it('123', function () {" + "abc[''];" + @@ -179,4 +179,4 @@ ruleTester.run("no-eql-primitives", rule, { "});" ].concat(validTests), invalid: invalidTests -}); +}) diff --git a/tests/lib/rules/no-expressions-in-assertions.js b/tests/lib/rules/no-expressions-in-assertions.js index f8394d6..1012431 100644 --- a/tests/lib/rules/no-expressions-in-assertions.js +++ b/tests/lib/rules/no-expressions-in-assertions.js @@ -1,123 +1,123 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/no-expressions-in-assertions"), - RuleTester = require("eslint").RuleTester; -var testHelpers = require("../../../lib/utils/tests.js"); -var ruleTester = new RuleTester({env: {es6: true}}); +const rule = require("../../../lib/rules/no-expressions-in-assertions") +const { RuleTester } = require("eslint") +const testHelpers = require("../../../lib/utils/tests.js") +const ruleTester = new RuleTester({ env: { es6: true } }) -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const Jsonium = require("jsonium") +const j = new Jsonium() -var defaultMessage = "Expression should not be used here."; -var detailedMessage = "`{{USE}}` should be used."; -var emptyArgMessage = "Empty assertion is not allowed."; +const defaultMessage = "Expression should not be used here." +const detailedMessage = "`{{USE}}` should be used." +const emptyArgMessage = "Empty assertion is not allowed." -var binariesForExpect = [ - {BINARY: ">", USE: ".to.be.above"}, - {BINARY: "<", USE: ".to.be.below"}, - {BINARY: ">=", USE: ".to.be.at.least"}, - {BINARY: "<=", USE: ".to.be.most"}, - {BINARY: "==", USE: ".to.be.equal"}, - {BINARY: "===", USE: ".to.be.equal"}, - {BINARY: "!=", USE: ".to.be.not.equal"}, - {BINARY: "!==", USE: ".to.be.not.equal"}, - {BINARY: "instanceof", USE: ".to.be.instanceof"} -]; +const binariesForExpect = [ + { BINARY: ">", USE: ".to.be.above" }, + { BINARY: "<", USE: ".to.be.below" }, + { BINARY: ">=", USE: ".to.be.at.least" }, + { BINARY: "<=", USE: ".to.be.most" }, + { BINARY: "==", USE: ".to.be.equal" }, + { BINARY: "===", USE: ".to.be.equal" }, + { BINARY: "!=", USE: ".to.be.not.equal" }, + { BINARY: "!==", USE: ".to.be.not.equal" }, + { BINARY: "instanceof", USE: ".to.be.instanceof" } +] -var binariesForAssert = [ - {BINARY: ">", USE: ".isAbove"}, - {BINARY: "<", USE: ".isBelow"}, - {BINARY: ">=", USE: ".isAtLeast"}, - {BINARY: "<=", USE: ".isAtMost"}, - {BINARY: "==", USE: ".equal"}, - {BINARY: "===", USE: ".strictEqual"}, - {BINARY: "!=", USE: ".notEqual"}, - {BINARY: "!==", USE: ".notStrictEqual"} -]; +const binariesForAssert = [ + { BINARY: ">", USE: ".isAbove" }, + { BINARY: "<", USE: ".isBelow" }, + { BINARY: ">=", USE: ".isAtLeast" }, + { BINARY: "<=", USE: ".isAtMost" }, + { BINARY: "==", USE: ".equal" }, + { BINARY: "===", USE: ".strictEqual" }, + { BINARY: "!=", USE: ".notEqual" }, + { BINARY: "!==", USE: ".notStrictEqual" } +] -var logical = [ - {LOGICAL: "+"}, - {LOGICAL: "-"}, - {LOGICAL: "/"}, - {LOGICAL: "*"}, - {LOGICAL: "%"}, - {LOGICAL: "^"}, - {LOGICAL: "&&"}, - {LOGICAL: "||"} -]; +const logical = [ + { LOGICAL: "+" }, + { LOGICAL: "-" }, + { LOGICAL: "/" }, + { LOGICAL: "*" }, + { LOGICAL: "%" }, + { LOGICAL: "^" }, + { LOGICAL: "&&" }, + { LOGICAL: "||" } +] -var updates = [ - {UPDATE: "++"}, - {UPDATE: "--"} -]; +const updates = [ + { UPDATE: "++" }, + { UPDATE: "--" } +] -var unaries = [ - {UNARY: "!"}, - {UNARY: "~"}, - {UNARY: "+"}, - {UNARY: "-"} -]; +const unaries = [ + { UNARY: "!" }, + { UNARY: "~" }, + { UNARY: "+" }, + { UNARY: "-" } +] -var primitiveEqualitiesForExpect = [ - {EQL_BINARY: "==", NOT: ""}, - {EQL_BINARY: "===", NOT: ""}, - {EQL_BINARY: "!=", NOT: "not."}, - {EQL_BINARY: "!==", NOT: "not."} -]; +const primitiveEqualitiesForExpect = [ + { EQL_BINARY: "==", NOT: "" }, + { EQL_BINARY: "===", NOT: "" }, + { EQL_BINARY: "!=", NOT: "not." }, + { EQL_BINARY: "!==", NOT: "not." } +] -var primitiveEqualitiesForAssert = [ - {EQL_BINARY: "==", NOT: ""}, - {EQL_BINARY: "===", NOT: ""}, - {EQL_BINARY: "!=", NOT: "Not"}, - {EQL_BINARY: "!==", NOT: "Not"} -]; +const primitiveEqualitiesForAssert = [ + { EQL_BINARY: "==", NOT: "" }, + { EQL_BINARY: "===", NOT: "" }, + { EQL_BINARY: "!=", NOT: "Not" }, + { EQL_BINARY: "!==", NOT: "Not" } +] -var primitiveValuesForExpect = [ - {VAL: "null", EQL_BINARY: "{{EQL_BINARY}}", USE: ".to.{{NOT}}be.null"}, - {VAL: "true", EQL_BINARY: "{{EQL_BINARY}}", USE: ".to.{{NOT}}be.true"}, - {VAL: "false", EQL_BINARY: "{{EQL_BINARY}}", USE: ".to.{{NOT}}be.false"}, - {VAL: "undefined", EQL_BINARY: "{{EQL_BINARY}}", USE: ".to.{{NOT}}be.undefined"} -]; +const primitiveValuesForExpect = [ + { VAL: "null", EQL_BINARY: "{{EQL_BINARY}}", USE: ".to.{{NOT}}be.null" }, + { VAL: "true", EQL_BINARY: "{{EQL_BINARY}}", USE: ".to.{{NOT}}be.true" }, + { VAL: "false", EQL_BINARY: "{{EQL_BINARY}}", USE: ".to.{{NOT}}be.false" }, + { VAL: "undefined", EQL_BINARY: "{{EQL_BINARY}}", USE: ".to.{{NOT}}be.undefined" } +] -var primitiveValuesForAssert = [ - {VAL: "null", EQL_BINARY: "{{EQL_BINARY}}", USE: ".is{{NOT}}Null"}, - {VAL: "true", EQL_BINARY: "{{EQL_BINARY}}", USE: ".is{{NOT}}True"}, - {VAL: "false", EQL_BINARY: "{{EQL_BINARY}}", USE: ".is{{NOT}}False"} -]; +const primitiveValuesForAssert = [ + { VAL: "null", EQL_BINARY: "{{EQL_BINARY}}", USE: ".is{{NOT}}Null" }, + { VAL: "true", EQL_BINARY: "{{EQL_BINARY}}", USE: ".is{{NOT}}True" }, + { VAL: "false", EQL_BINARY: "{{EQL_BINARY}}", USE: ".is{{NOT}}False" } +] -var primitiveAssertions = [ - {ASSERTION: "a {{EQL_BINARY}} {{VAL}}", MESSAGE: detailedMessage}, - {ASSERTION: "a {{EQL_BINARY}} {{VAL}}", MESSAGE: detailedMessage}, - {ASSERTION: "{{VAL}} {{EQL_BINARY}} b", MESSAGE: detailedMessage}, - {ASSERTION: "{{VAL}} {{EQL_BINARY}} b", MESSAGE: detailedMessage} -]; +const primitiveAssertions = [ + { ASSERTION: "a {{EQL_BINARY}} {{VAL}}", MESSAGE: detailedMessage }, + { ASSERTION: "a {{EQL_BINARY}} {{VAL}}", MESSAGE: detailedMessage }, + { ASSERTION: "{{VAL}} {{EQL_BINARY}} b", MESSAGE: detailedMessage }, + { ASSERTION: "{{VAL}} {{EQL_BINARY}} b", MESSAGE: detailedMessage } +] -var primitiveAssertionsForExpect = j +const primitiveAssertionsForExpect = j .setTemplates(primitiveAssertions) .createCombos(["ASSERTION", "MESSAGE"], primitiveValuesForExpect) .useCombosAsTemplates() .createCombos(["ASSERTION", "MESSAGE"], primitiveEqualitiesForExpect) .uniqueCombos() - .getCombos(); + .getCombos() -var primitiveAssertionsForAssert = j +const primitiveAssertionsForAssert = j .setTemplates(primitiveAssertions) .createCombos(["ASSERTION", "MESSAGE"], primitiveValuesForAssert) .useCombosAsTemplates() .createCombos(["ASSERTION", "MESSAGE"], primitiveEqualitiesForAssert) .uniqueCombos() - .getCombos(); + .getCombos() -var assertions = [ - {ASSERTION: "a {{BINARY}} b", MESSAGE: detailedMessage}, - {ASSERTION: "a {{LOGICAL}} b", MESSAGE: defaultMessage}, - {ASSERTION: "{{UPDATE}} b", MESSAGE: defaultMessage}, - {ASSERTION: "b{{UPDATE}}", MESSAGE: defaultMessage}, - {ASSERTION: "{{UNARY}} a", MESSAGE: defaultMessage}, - {ASSERTION: "", MESSAGE: emptyArgMessage} -]; +const assertions = [ + { ASSERTION: "a {{BINARY}} b", MESSAGE: detailedMessage }, + { ASSERTION: "a {{LOGICAL}} b", MESSAGE: defaultMessage }, + { ASSERTION: "{{UPDATE}} b", MESSAGE: defaultMessage }, + { ASSERTION: "b{{UPDATE}}", MESSAGE: defaultMessage }, + { ASSERTION: "{{UNARY}} a", MESSAGE: defaultMessage }, + { ASSERTION: "", MESSAGE: emptyArgMessage } +] -var assertionsForExpect = j +const assertionsForExpect = j .setTemplates(assertions) .createCombos(["ASSERTION", "MESSAGE"], binariesForExpect) .uniqueCombos() @@ -131,9 +131,9 @@ var assertionsForExpect = j .createCombos(["ASSERTION"], unaries) .uniqueCombos() .concatCombos(primitiveAssertionsForExpect) - .getCombos(); + .getCombos() -var assertionsForAssert = j +const assertionsForAssert = j .setTemplates(assertions) .createCombos(["ASSERTION", "MESSAGE"], binariesForAssert) .uniqueCombos() @@ -147,10 +147,9 @@ var assertionsForAssert = j .createCombos(["ASSERTION"], unaries) .uniqueCombos() .concatCombos(primitiveAssertionsForAssert) - .getCombos(); + .getCombos() - -var validTestTemplatesForExpect = [ +const validTestTemplatesForExpect = [ { code: "{{EXPECT}}({{ASSERTION}}).to.be.true;" @@ -167,7 +166,7 @@ var validTestTemplatesForExpect = [ "});" + "});", options: [ - {skipSkipped: true} + { skipSkipped: true } ] }, { @@ -178,13 +177,13 @@ var validTestTemplatesForExpect = [ "});" + "});", options: [ - {skipSkipped: true} + { skipSkipped: true } ] } -]; +] -var validTestTemplatesForAssert = [ +const validTestTemplatesForAssert = [ { code: "{{ASSERT}}.equal({{ASSERTION}});" @@ -201,7 +200,7 @@ var validTestTemplatesForAssert = [ "});" + "});", options: [ - {skipSkipped: true} + { skipSkipped: true } ] }, { @@ -212,7 +211,7 @@ var validTestTemplatesForAssert = [ "});" + "});", options: [ - {skipSkipped: true} + { skipSkipped: true } ] }, { @@ -223,7 +222,7 @@ var validTestTemplatesForAssert = [ "});" + "});", options: [ - {skipSkipped: true} + { skipSkipped: true } ] }, { @@ -234,12 +233,12 @@ var validTestTemplatesForAssert = [ "});" + "});", options: [ - {skipSkipped: true} + { skipSkipped: true } ] } -]; +] -var invalidTestTemplatesForExpect = [ +const invalidTestTemplatesForExpect = [ { code: "{{SUITE}}('123', {{ES}}" + @@ -248,12 +247,12 @@ var invalidTestTemplatesForExpect = [ "});" + "});", errors: [ - {message: "{{MESSAGE}}", type: "CallExpression"} + { message: "{{MESSAGE}}", type: "CallExpression" } ] } -]; +] -var invalidTestTemplatesForAssert = [ +const invalidTestTemplatesForAssert = [ { code: "{{SUITE}}('123', {{ES}}" + @@ -262,7 +261,7 @@ var invalidTestTemplatesForAssert = [ "});" + "});", errors: [ - {message: "{{MESSAGE}}", type: "MemberExpression"} + { message: "{{MESSAGE}}", type: "MemberExpression" } ] }, { @@ -273,60 +272,60 @@ var invalidTestTemplatesForAssert = [ "});" + "});", errors: [ - {message: "{{MESSAGE}}", type: "{{TYPE}}"} + { message: "{{MESSAGE}}", type: "{{TYPE}}" } ] } -]; +] -var validTests = j +let validTests = j .setTemplates(validTestTemplatesForExpect) .createCombos(["code"], assertionsForExpect) .useCombosAsTemplates() - .createCombos(["code"], [{EXPECT: "expect"}, {EXPECT: "chai.expect"}, {EXPECT: "chai['expect']"}]) + .createCombos(["code"], [{ EXPECT: "expect" }, { EXPECT: "chai.expect" }, { EXPECT: "chai['expect']" }]) .useCombosAsTemplates() .createCombos(["code"], testHelpers.mochaDatasets) .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() validTests = j .setTemplates(validTestTemplatesForAssert) .createCombos(["code"], assertionsForAssert) .useCombosAsTemplates() - .createCombos(["code"], [{ASSERT: "assert"}, {ASSERT: "chai.assert"}, {ASSERT: "chai['assert']"}]) + .createCombos(["code"], [{ ASSERT: "assert" }, { ASSERT: "chai.assert" }, { ASSERT: "chai['assert']" }]) .useCombosAsTemplates() .createCombos(["code"], testHelpers.mochaDatasets) .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() .concatCombos(validTests) - .getCombos(); + .getCombos() -var invalidTests = j +let invalidTests = j .setTemplates(invalidTestTemplatesForExpect) .createCombos(["code", "errors.@each.message"], assertionsForExpect) .useCombosAsTemplates() - .createCombos(["code"], [{EXPECT: "expect"}, {EXPECT: "chai.expect"}, {EXPECT: "chai['expect']"}]) + .createCombos(["code"], [{ EXPECT: "expect" }, { EXPECT: "chai.expect" }, { EXPECT: "chai['expect']" }]) .useCombosAsTemplates() .createCombos(["code"], testHelpers.mochaDatasets) .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() invalidTests = j .setTemplates(invalidTestTemplatesForAssert) .createCombos(["code", "errors.@each.message"], assertionsForAssert) .useCombosAsTemplates() - .createCombos(["code", "errors.0.type"], [{ASSERT: "assert", TYPE: "CallExpression"}, {ASSERT: "chai.assert", TYPE: "MemberExpression"}, {ASSERT: "chai['assert']", TYPE: "MemberExpression"}]) + .createCombos(["code", "errors.0.type"], [{ ASSERT: "assert", TYPE: "CallExpression" }, { ASSERT: "chai.assert", TYPE: "MemberExpression" }, { ASSERT: "chai['assert']", TYPE: "MemberExpression" }]) .useCombosAsTemplates() .createCombos(["code"], testHelpers.mochaDatasets) .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() .concatCombos(invalidTests) - .getCombos(); + .getCombos() ruleTester.run("no-expressions-in-assertions", rule, { valid: [ @@ -352,7 +351,7 @@ ruleTester.run("no-expressions-in-assertions", rule, { "});" + "});", options: [ - {replacementsOnly: true} + { replacementsOnly: true } ] }, { @@ -362,7 +361,7 @@ ruleTester.run("no-expressions-in-assertions", rule, { "});" + "});", options: [ - {replacementsOnly: true} + { replacementsOnly: true } ] }, { @@ -372,7 +371,7 @@ ruleTester.run("no-expressions-in-assertions", rule, { "});" + "});", options: [ - {replacementsOnly: true} + { replacementsOnly: true } ] } ].concat(validTests), @@ -385,7 +384,7 @@ ruleTester.run("no-expressions-in-assertions", rule, { "});" + "});", errors: [ - {message: "`.isUndefined` should be used.", type: "CallExpression"} + { message: "`.isUndefined` should be used.", type: "CallExpression" } ] }, { @@ -396,8 +395,8 @@ ruleTester.run("no-expressions-in-assertions", rule, { "});" + "});", errors: [ - {message: "`.isDefined` should be used.", type: "CallExpression"} + { message: "`.isDefined` should be used.", type: "CallExpression" } ] } ].concat(invalidTests) -}); +}) diff --git a/tests/lib/rules/no-nested-it.js b/tests/lib/rules/no-nested-it.js index 67216e0..6d52473 100644 --- a/tests/lib/rules/no-nested-it.js +++ b/tests/lib/rules/no-nested-it.js @@ -1,14 +1,14 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/no-nested-it"), - RuleTester = require("eslint").RuleTester; -var testHelpers = require("../../../lib/utils/tests.js"); -var ruleTester = new RuleTester({env: {es6: true}}); +const rule = require("../../../lib/rules/no-nested-it") +const { RuleTester } = require("eslint") +const testHelpers = require("../../../lib/utils/tests.js") +const ruleTester = new RuleTester({ env: { es6: true } }) -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const Jsonium = require("jsonium") +const j = new Jsonium() -var validTestTemplates = [ +const validTestTemplates = [ { code: "{{TEST}}('123', {{ES}}}); " + @@ -73,7 +73,7 @@ var validTestTemplates = [ "{{TEST}}('4321', {{ES}}}); " + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -82,7 +82,7 @@ var validTestTemplates = [ "{{TEST}}('4321', {{ES}}}); " + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -93,7 +93,7 @@ var validTestTemplates = [ "}); " + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -104,11 +104,11 @@ var validTestTemplates = [ "}); " + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] } -]; +] -var invalidTestTemplates = [ +const invalidTestTemplates = [ { code: "{{SUITE}}('1234', {{ES}} " + @@ -116,7 +116,7 @@ var invalidTestTemplates = [ "{{TEST}}('4321', {{ES}}}); " + "});" + "});", - errors: [{message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression"}] + errors: [{ message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression" }] }, { code: @@ -128,8 +128,8 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression"}, - {message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression"} + { message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression" }, + { message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression" } ] }, { @@ -140,7 +140,7 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression"} + { message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression" } ] }, { @@ -153,7 +153,7 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression"} + { message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression" } ] }, { @@ -164,7 +164,7 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression"} + { message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression" } ] }, { @@ -177,8 +177,8 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression"}, - {message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression"} + { message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression" }, + { message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression" } ] }, { @@ -191,31 +191,31 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression"}, - {message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression"} + { message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression" }, + { message: "Nested tests are not allowed. Only nested suites are allowed.", type: "CallExpression" } ] } -]; +] -var validTests = j +const validTests = j .setTemplates(validTestTemplates) .createCombos(["code"], testHelpers.mochaDatasets) .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() -j.clearTemplates().clearCombos(); +j.clearTemplates().clearCombos() -var invalidTests = j +const invalidTests = j .setTemplates(invalidTestTemplates) .createCombos(["code", "errors.@each.message"], testHelpers.mochaDatasets) .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() ruleTester.run("no-nested-it", rule, { valid: validTests, invalid: invalidTests -}); +}) diff --git a/tests/lib/rules/no-outside-declaration.js b/tests/lib/rules/no-outside-declaration.js index 93a633d..a640b83 100644 --- a/tests/lib/rules/no-outside-declaration.js +++ b/tests/lib/rules/no-outside-declaration.js @@ -1,23 +1,23 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/no-outside-declaration"), - RuleTester = require("eslint").RuleTester; -var testHelpers = require("../../../lib/utils/tests.js"); -var ruleTester = new RuleTester({env: {es6: true}}); +const rule = require("../../../lib/rules/no-outside-declaration") +const { RuleTester } = require("eslint") +const testHelpers = require("../../../lib/utils/tests.js") +const ruleTester = new RuleTester({ env: { es6: true } }) -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const Jsonium = require("jsonium") +const j = new Jsonium() -var m = "Variable declaration is not allowed outside tests and hooks."; +const m = "Variable declaration is not allowed outside tests and hooks." -var declarations = [ - {DECLARATION: "var a = require('abc');"}, - {DECLARATION: "let b = a + c;"}, - {DECLARATION: "const c = 1;"}, - {DECLARATION: "const {e, f, g} = d;"} -]; +const declarations = [ + { DECLARATION: "var a = require('abc');" }, + { DECLARATION: "let b = a + c;" }, + { DECLARATION: "const c = 1;" }, + { DECLARATION: "const {e, f, g} = d;" } +] -var validTestTemplates = [ +const validTestTemplates = [ { code: "{{DECLARATION}}" + @@ -48,7 +48,7 @@ var validTestTemplates = [ "{{DECLARATION}}" + "{{TEST}}('4321', {{ES}}}); " + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -56,7 +56,7 @@ var validTestTemplates = [ "{{TEST}}('4321', {{ES}}}); " + "{{DECLARATION}}" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -65,11 +65,11 @@ var validTestTemplates = [ "{{DECLARATION}}" + "{{TEST}}('4321', {{ES}}}); " + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] } -]; +] -var invalidTestTemplates = [ +const invalidTestTemplates = [ { code: "{{SUITESKIP}}('1234', {{ES}} " + @@ -77,7 +77,7 @@ var invalidTestTemplates = [ "{{TEST}}('4321', {{ES}}}); " + "});", errors: [ - {message: m, type: "VariableDeclaration"} + { message: m, type: "VariableDeclaration" } ] }, { @@ -87,7 +87,7 @@ var invalidTestTemplates = [ "{{DECLARATION}}" + "});", errors: [ - {message: m, type: "VariableDeclaration"} + { message: m, type: "VariableDeclaration" } ] }, { @@ -98,12 +98,12 @@ var invalidTestTemplates = [ "{{TEST}}('4321', {{ES}}}); " + "});", errors: [ - {message: m, type: "VariableDeclaration"} + { message: m, type: "VariableDeclaration" } ] } -]; +] -var validTests = j +const validTests = j .setTemplates(validTestTemplates) .createCombos(["code"], testHelpers.mochaDatasets) .useCombosAsTemplates() @@ -113,11 +113,11 @@ var validTests = j .useCombosAsTemplates() .createCombos(["code"], declarations) .uniqueCombos() - .getCombos(); + .getCombos() -j.clearTemplates().clearCombos(); +j.clearTemplates().clearCombos() -var invalidTests = j +const invalidTests = j .setTemplates(invalidTestTemplates) .createCombos(["code"], testHelpers.mochaDatasets) .useCombosAsTemplates() @@ -127,9 +127,9 @@ var invalidTests = j .useCombosAsTemplates() .createCombos(["code"], declarations) .uniqueCombos() - .getCombos(); + .getCombos() ruleTester.run("no-outside-declaration", rule, { valid: validTests, invalid: invalidTests -}); +}) diff --git a/tests/lib/rules/no-same-titles.js b/tests/lib/rules/no-same-titles.js index 4069d8d..eabbba8 100644 --- a/tests/lib/rules/no-same-titles.js +++ b/tests/lib/rules/no-same-titles.js @@ -1,16 +1,16 @@ -"use strict"; +"use strict" -var rule = require("../../../lib/rules/no-same-titles"), - RuleTester = require("eslint").RuleTester; -var testHelpers = require("../../../lib/utils/tests.js"); -var ruleTester = new RuleTester({env: {es6: true}}); +const rule = require("../../../lib/rules/no-same-titles") +const { RuleTester } = require("eslint") +const testHelpers = require("../../../lib/utils/tests.js") +const ruleTester = new RuleTester({ env: { es6: true } }) -var Jsonium = require("jsonium"); -var j = new Jsonium(); +const Jsonium = require("jsonium") +const j = new Jsonium() -var m = "Some tests have same titles."; +const m = "Some tests have same titles." -var validTestTemplates = [ +const validTestTemplates = [ { code: "{{TEST}}('123', {{ES}}}); " + @@ -24,7 +24,7 @@ var validTestTemplates = [ "{{SUITE}}('321', {{ES}}" + "{{TEST}}('123', {{ES}}});" + "});", - options: [{scope: "suite"}] + options: [{ scope: "suite" }] }, { code: @@ -45,7 +45,7 @@ var validTestTemplates = [ "{{TEST}}('123', {{ES}}});" + "});" + "});", - options: [{scope: "suite"}] + options: [{ scope: "suite" }] }, { code: @@ -64,7 +64,7 @@ var validTestTemplates = [ "{{SUITE}}('4321', {{ES}}" + "{{TEST}}('123', {{ES}}});" + "});", - options: [{scope: "suite"}] + options: [{ scope: "suite" }] }, { code: @@ -72,7 +72,7 @@ var validTestTemplates = [ "{{TEST}}('1234', {{ES}}}); " + "{{TEST}}('1234', {{ES}}}); " + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -80,7 +80,7 @@ var validTestTemplates = [ "{{TEST}}('1234', {{ES}}}); " + "{{TEST}}('1234', {{ES}}}); " + "});", - options: [{skipSkipped: true, scope: "suite"}] + options: [{ skipSkipped: true, scope: "suite" }] }, { code: @@ -90,7 +90,7 @@ var validTestTemplates = [ "{{TEST}}('1234', {{ES}}}); " + "});" + "});", - options: [{skipSkipped: true}] + options: [{ skipSkipped: true }] }, { code: @@ -100,7 +100,7 @@ var validTestTemplates = [ "{{TEST}}('1234', {{ES}}}); " + "});" + "});", - options: [{skipSkipped: true, scope: "suite"}] + options: [{ skipSkipped: true, scope: "suite" }] }, { code: @@ -111,7 +111,7 @@ var validTestTemplates = [ "{{TEST}}('123', {{ES}}});" + "});" + "});", - options: [{scope: "file", skipSkipped: true}] + options: [{ scope: "file", skipSkipped: true }] }, { code: @@ -119,9 +119,9 @@ var validTestTemplates = [ "{{TEST}}(foo, {{ES}}}); " + "});" } -]; +] -var invalidTestTemplates = [ +const invalidTestTemplates = [ { code: "{{SUITE}}('4321', {{ES}} " + @@ -129,8 +129,8 @@ var invalidTestTemplates = [ "{{TEST}}('1234', {{ES}}}); " + "});", errors: [ - {message: m, type: "CallExpression"}, - {message: m, type: "CallExpression"} + { message: m, type: "CallExpression" }, + { message: m, type: "CallExpression" } ] }, { @@ -140,8 +140,8 @@ var invalidTestTemplates = [ "{{TEST}}('1234', {{ES}}}); " + "});", errors: [ - {message: m, type: "CallExpression"}, - {message: m, type: "CallExpression"} + { message: m, type: "CallExpression" }, + { message: m, type: "CallExpression" } ] }, { @@ -153,8 +153,8 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: m, type: "CallExpression"}, - {message: m, type: "CallExpression"} + { message: m, type: "CallExpression" }, + { message: m, type: "CallExpression" } ] }, { @@ -168,8 +168,8 @@ var invalidTestTemplates = [ "});" + "});", errors: [ - {message: m, type: "CallExpression"}, - {message: m, type: "CallExpression"} + { message: m, type: "CallExpression" }, + { message: m, type: "CallExpression" } ] }, { @@ -181,34 +181,33 @@ var invalidTestTemplates = [ "{{TEST}}('123', {{ES}}});" + "});" + "});", - options: [{scope: "file"}], + options: [{ scope: "file" }], errors: [ - {message: m, type: "CallExpression"}, - {message: m, type: "CallExpression"} + { message: m, type: "CallExpression" }, + { message: m, type: "CallExpression" } ] } -]; +] -var validTests = j +const validTests = j .setTemplates(validTestTemplates) .createCombos(["code"], testHelpers.mochaDatasets) .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); + .getCombos() -j.clearTemplates().clearCombos(); +j.clearTemplates().clearCombos() -var invalidTests = j +const invalidTests = j .setTemplates(invalidTestTemplates) .createCombos(["code", "errors.@each.message"], testHelpers.mochaDatasets) .useCombosAsTemplates() .createCombos(["code"], testHelpers.es) .uniqueCombos() - .getCombos(); - + .getCombos() ruleTester.run("no-same-title", rule, { valid: validTests, invalid: invalidTests -}); +}) diff --git a/tests/lib/utils/node.js b/tests/lib/utils/node.js index 6eb1435..431b837 100644 --- a/tests/lib/utils/node.js +++ b/tests/lib/utils/node.js @@ -1,17 +1,17 @@ -"use strict"; +"use strict" -var assert = require("assert"); -var espree = require("espree"); -var node = require("../../../lib/utils/node.js"); +const assert = require("assert") +const espree = require("espree") +const node = require("../../../lib/utils/node.js") describe("obj", function () { it("`isSuiteBody` (`isBlockBody`) called with node with no parent", function () { - var result = node.isSuiteBody(espree.parse("")); - assert(!result); - }); + const result = node.isSuiteBody(espree.parse("")) + assert(!result) + }) it("`getParentExpression` (`_getParentByTypes`) called with node with no parent", function () { - var result = node.getParentExpression(espree.parse("")); - assert(!result); - }); -}); + const result = node.getParentExpression(espree.parse("")) + assert(!result) + }) +}) diff --git a/tests/lib/utils/obj.js b/tests/lib/utils/obj.js index f314074..22ce32a 100644 --- a/tests/lib/utils/obj.js +++ b/tests/lib/utils/obj.js @@ -2,18 +2,18 @@ * @fileoverview Unit testing of `obj.js`'s currently unused methods */ -"use strict"; +"use strict" -var assert = require("assert"); -var obj = require("../../../lib/utils/obj.js"); +const assert = require("assert") +const obj = require("../../../lib/utils/obj.js") describe("obj", function () { it("Returns false for absent child path", function () { - var result = obj.has({a: {b: {c: 1}}}, "a.b.d"); - assert(!result); - }); + const result = obj.has({ a: { b: { c: 1 } } }, "a.b.d") + assert(!result) + }) it("Returns true for present child path", function () { - var result = obj.has({a: {b: {c: 1}}}, "a.b.c"); - assert(result); - }); -}); + const result = obj.has({ a: { b: { c: 1 } } }, "a.b.c") + assert(result) + }) +})