From 71d03e5d419383efb022d7440e77bd3c1e0a48f4 Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:40:21 -0500 Subject: [PATCH] chore: add prettier (#442) * chore: add prettier * fix lint --- eslint-remote-tester.config.js | 17 +- eslint.config.js | 199 ++- index.js | 14 +- lib/configs/recommended.js | 2 +- lib/rules/assert-args.js | 47 +- lib/rules/literal-compare-order.js | 56 +- lib/rules/no-arrow-tests.js | 73 +- lib/rules/no-assert-equal-boolean.js | 82 +- lib/rules/no-assert-equal.js | 78 +- lib/rules/no-assert-logical-expression.js | 34 +- lib/rules/no-assert-ok.js | 24 +- lib/rules/no-async-in-loops.js | 57 +- lib/rules/no-async-module-callbacks.js | 20 +- lib/rules/no-async-test.js | 15 +- lib/rules/no-commented-tests.js | 34 +- lib/rules/no-compare-relation-boolean.js | 87 +- lib/rules/no-conditional-assertions.js | 40 +- lib/rules/no-early-return.js | 62 +- lib/rules/no-global-assertions.js | 21 +- lib/rules/no-global-expect.js | 18 +- lib/rules/no-global-module-test.js | 22 +- lib/rules/no-global-stop-start.js | 22 +- lib/rules/no-hooks-from-ancestor-modules.js | 70 +- lib/rules/no-identical-names.js | 91 +- lib/rules/no-init.js | 21 +- lib/rules/no-jsdump.js | 21 +- lib/rules/no-loose-assertions.js | 110 +- lib/rules/no-negated-ok.js | 78 +- lib/rules/no-nested-tests.js | 20 +- lib/rules/no-ok-equality.js | 93 +- lib/rules/no-only.js | 14 +- lib/rules/no-qunit-push.js | 21 +- lib/rules/no-qunit-start-in-tests.js | 53 +- lib/rules/no-qunit-stop.js | 20 +- lib/rules/no-reassign-log-callbacks.js | 16 +- lib/rules/no-reset.js | 21 +- lib/rules/no-setup-teardown.js | 38 +- lib/rules/no-skip.js | 14 +- lib/rules/no-test-expect-argument.js | 14 +- lib/rules/no-throws-string.js | 38 +- lib/rules/require-expect.js | 110 +- lib/rules/require-object-in-propequal.js | 62 +- lib/rules/resolve-async.js | 82 +- lib/utils.js | 172 ++- package-lock.json | 131 +- package.json | 3 + tests/index.js | 35 +- tests/lib/rules/assert-args.js | 1278 ++++++++++------- tests/lib/rules/literal-compare-order.js | 870 ++++++----- tests/lib/rules/no-arrow-tests.js | 280 ++-- tests/lib/rules/no-assert-equal-boolean.js | 38 +- tests/lib/rules/no-assert-equal.js | 232 +-- .../lib/rules/no-assert-logical-expression.js | 831 ++++++----- tests/lib/rules/no-assert-ok.js | 126 +- tests/lib/rules/no-async-in-loops.js | 890 +++++++----- tests/lib/rules/no-async-module-callbacks.js | 39 +- tests/lib/rules/no-async-test.js | 26 +- tests/lib/rules/no-commented-tests.js | 208 ++- .../lib/rules/no-compare-relation-boolean.js | 125 +- tests/lib/rules/no-conditional-assertions.js | 21 +- tests/lib/rules/no-early-return.js | 86 +- tests/lib/rules/no-global-assertions.js | 35 +- tests/lib/rules/no-global-expect.js | 49 +- tests/lib/rules/no-global-module-test.js | 50 +- tests/lib/rules/no-global-stop-start.js | 38 +- .../rules/no-hooks-from-ancestor-modules.js | 75 +- tests/lib/rules/no-identical-names.js | 165 ++- tests/lib/rules/no-init.js | 18 +- tests/lib/rules/no-jsdump.js | 19 +- tests/lib/rules/no-loose-assertions.js | 400 +++--- tests/lib/rules/no-negated-ok.js | 34 +- tests/lib/rules/no-nested-tests.js | 21 +- tests/lib/rules/no-ok-equality.js | 120 +- tests/lib/rules/no-only.js | 46 +- tests/lib/rules/no-qunit-push.js | 17 +- tests/lib/rules/no-qunit-start-in-tests.js | 31 +- tests/lib/rules/no-qunit-stop.js | 30 +- tests/lib/rules/no-reassign-log-callbacks.js | 77 +- tests/lib/rules/no-reset.js | 17 +- tests/lib/rules/no-setup-teardown.js | 69 +- tests/lib/rules/no-skip.js | 16 +- tests/lib/rules/no-test-expect-argument.js | 63 +- tests/lib/rules/no-throws-string.js | 77 +- tests/lib/rules/require-expect.js | 144 +- .../lib/rules/require-object-in-propequal.js | 97 +- tests/lib/rules/resolve-async.js | 196 +-- 86 files changed, 5445 insertions(+), 3881 deletions(-) diff --git a/eslint-remote-tester.config.js b/eslint-remote-tester.config.js index 82c07be8..5959f7f3 100644 --- a/eslint-remote-tester.config.js +++ b/eslint-remote-tester.config.js @@ -23,7 +23,7 @@ module.exports = { "l10n-tw/canvas-lms", "rust-lang/crates.io", "simonihmig/ember-responsive-image", - "videojs/video.js" + "videojs/video.js", ], /** Extensions of files under scanning */ @@ -40,15 +40,18 @@ module.exports = { rules: Object.fromEntries( fs .readdirSync(`${__dirname}/lib/rules`) - .map((filename) => `qunit/${basename(filename, extname(filename))}`) - .map((ruleName) => [ruleName, "error"]) + .map( + (filename) => + `qunit/${basename(filename, extname(filename))}`, + ) + .map((ruleName) => [ruleName, "error"]), ), overrides: [ { files: ["*.ts", "*.mts", "*.cts"], - parser: "@typescript-eslint/parser" - } - ] - } + parser: "@typescript-eslint/parser", + }, + ], + }, }; diff --git a/eslint.config.js b/eslint.config.js index 2e763a21..0d216fc4 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -2,85 +2,64 @@ const js = require("@eslint/js"); const { FlatCompat } = require("@eslint/eslintrc"); -const eslintPluginMarkdown = require("eslint-plugin-markdown"); const eslintPluginEslintPluginAll = require("eslint-plugin-eslint-plugin/configs/all"); +const eslintPluginMarkdown = require("eslint-plugin-markdown"); const globals = require("globals"); const compat = new FlatCompat({ baseDirectory: __dirname, - recommendedConfig: js.configs.recommended + recommendedConfig: js.configs.recommended, }); module.exports = [ ...compat.extends( - "plugin:node/recommended", "plugin:eslint-comments/recommended", - "plugin:unicorn/recommended" + "plugin:node/recommended", + "plugin:prettier/recommended", + "plugin:unicorn/recommended", ), eslintPluginEslintPluginAll, // Apply mocha config only to tests. - ...compat.extends("plugin:mocha/recommended").map(config => ({ ...config, - files: ["tests/**/*.js"] })), + ...compat + .extends("plugin:mocha/recommended") + .map((config) => ({ ...config, files: ["tests/**/*.js"] })), { languageOptions: { - "sourceType": "script", - "ecmaVersion": "latest", - "globals": globals.node - } - }, - { - "rules": - { - "array-bracket-spacing": ["error", "never"], - "block-spacing": ["error", "always"], - "brace-style": ["error", "1tbs"], - "camelcase": ["error", { "properties": "always" }], - "comma-dangle": ["error", "never"], - "comma-spacing": ["error", { "before": false, - "after": true }], - "comma-style": ["error", "last"], - "complexity": ["error", 10], - "computed-property-spacing": ["error", "never"], + sourceType: "script", + ecmaVersion: "latest", + globals: globals.node, + }, + rules: { + camelcase: ["error", { properties: "always" }], + complexity: ["error", 10], "consistent-return": "error", "consistent-this": ["error", "self"], - "curly": ["error", "multi-line"], + curly: ["error", "multi-line"], "default-case": "error", - "dot-location": ["error", "property"], "dot-notation": "error", - "eol-last": "error", - "eqeqeq": "error", - "func-call-spacing": "error", + eqeqeq: "error", "func-style": ["error", "declaration"], "guard-for-in": "error", - "indent": ["error", 4, { "SwitchCase": 1, - "VariableDeclarator": 1 }], - "key-spacing": ["error", { "beforeColon": false, - "afterColon": true }], - "keyword-spacing": ["error", { "before": true, - "after": true }], - "linebreak-style": ["error", "unix"], "lines-around-comment": [ "error", { - "beforeBlockComment": false, - "afterBlockComment": false, - "beforeLineComment": true, - "afterLineComment": false, - "allowBlockStart": true, - "allowBlockEnd": true, - "allowObjectStart": true, - "allowObjectEnd": true, - "allowArrayStart": true, - "allowArrayEnd": true - } + beforeBlockComment: false, + afterBlockComment: false, + beforeLineComment: true, + afterLineComment: false, + allowBlockStart: true, + allowBlockEnd: true, + allowObjectStart: true, + allowObjectEnd: true, + allowArrayStart: true, + allowArrayEnd: true, + }, ], "max-depth": ["error", 5], - "new-cap": ["error", { "newIsCap": true, - "capIsNew": true }], - "new-parens": "error", + "new-cap": ["error", { newIsCap: true, capIsNew: true }], "no-array-constructor": "error", "no-caller": "error", "no-catch-shadow": "error", @@ -102,10 +81,7 @@ module.exports = [ "no-ex-assign": "error", "no-extend-native": "error", "no-extra-boolean-cast": "error", - "no-extra-parens": "error", - "no-extra-semi": "error", "no-fallthrough": "error", - "no-floating-decimal": "error", "no-func-assign": "error", "no-implied-eval": "error", "no-invalid-regexp": "error", @@ -115,10 +91,7 @@ module.exports = [ "no-lonely-if": "error", "no-loop-func": "error", "no-mixed-requires": "error", - "no-mixed-spaces-and-tabs": "error", - "no-multi-spaces": ["error", { "ignoreEOLComments": true }], "no-multi-str": "error", - "no-multiple-empty-lines": "error", "no-unsafe-negation": "error", "no-nested-ternary": "error", "no-new-func": "error", @@ -156,54 +129,61 @@ module.exports = [ "no-useless-return": "error", "no-var": "error", "no-warning-comments": "error", - "no-whitespace-before-property": "error", "no-with": "error", - "object-curly-newline": ["error", { "consistent": true }], - "object-curly-spacing": ["error", "always"], - "object-property-newline": "error", "operator-assignment": ["error", "always"], - "operator-linebreak": ["error", "after"], - "padded-blocks": ["error", "never"], "prefer-const": "error", "prefer-template": "error", - "quote-props": ["error", "consistent"], - "quotes": ["error", "double"], - "radix": "error", - "semi": ["error", "always"], - "semi-spacing": ["error", { "before": false, - "after": true }], - "space-before-blocks": ["error", "always"], - "space-before-function-paren": ["error", { "anonymous": "always", - "named": "never" }], - "space-in-parens": ["error", "never"], - "space-infix-ops": "error", - "space-unary-ops": ["error", { "words": true, - "nonwords": false }], - "spaced-comment": ["error", "always", { "exceptions": ["-"] }], - "strict": ["error", "global"], - "template-curly-spacing": ["error", "never"], + radix: "error", + "spaced-comment": ["error", "always", { exceptions: ["-"] }], + strict: ["error", "global"], "use-isnan": "error", - "valid-jsdoc": ["error", { - "prefer": { - "return": "returns" - } - }], + "valid-jsdoc": [ + "error", + { + prefer: { + return: "returns", + }, + }, + ], "valid-typeof": "error", - "wrap-iife": "error", - "yoda": ["error", "never"], + yoda: ["error", "never"], // eslint-plugin-eslint-plugin - "eslint-plugin/meta-property-ordering": ["error", [ - "type", "docs", "fixable", "messages", "schema", "deprecated", "replacedBy" - ]], - "eslint-plugin/require-meta-docs-url": ["error", { - "pattern": "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/{{name}}.md" - }], + "eslint-plugin/meta-property-ordering": [ + "error", + [ + "type", + "docs", + "fixable", + "messages", + "schema", + "deprecated", + "replacedBy", + ], + ], + "eslint-plugin/require-meta-docs-url": [ + "error", + { + pattern: + "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/{{name}}.md", + }, + ], // eslint-plugin-node - "node/no-missing-require": ["error", { - "allowModules": ["@typescript-eslint/parser"] - }], + "node/no-missing-require": [ + "error", + { + allowModules: ["@typescript-eslint/parser"], + }, + ], + + // prettier + "prettier/prettier": [ + "error", + { + tabWidth: 4, + }, + ], // eslint-plugin-unicorn "unicorn/consistent-function-scoping": "off", @@ -214,24 +194,24 @@ module.exports = [ // eslint-disable-next-line no-warning-comments "unicorn/prefer-at": "off", // TODO: enable once we raise Node requirement to v16.6.0 "unicorn/prefer-module": "off", - "unicorn/prevent-abbreviations": "off" - } + "unicorn/prevent-abbreviations": "off", + }, }, { files: ["**/*.md"], plugins: { markdown: eslintPluginMarkdown }, - processor: "markdown/markdown" + processor: "markdown/markdown", }, { - "files": ["**/*.md/*.js", "**/*.md/*.javascript"], - "languageOptions": { - "parserOptions": { - "sourceType": "module" - } + // Markdown code samples. + files: ["**/*.md/*.js", "**/*.md/*.javascript"], + languageOptions: { + parserOptions: { + sourceType: "module", + }, }, - "rules": { - "brace-style": "off", - "eqeqeq": "off", + rules: { + eqeqeq: "off", "guard-for-in": "off", "no-constant-condition": "off", "no-empty-function": "off", @@ -239,10 +219,7 @@ module.exports = [ "no-unused-expressions": "off", "no-unused-vars": "off", "no-var": "off", - "quotes": "off", - "space-before-function-paren": "off", - "strict": "off" - } - } + strict: "off", + }, + }, ]; - diff --git a/index.js b/index.js index 0c14ff2b..c62b000e 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ const pkg = require("./package.json"); module.exports = { meta: { name: pkg.name, - version: pkg.version + version: pkg.version, }, rules: requireIndex(`${__dirname}/lib/rules`), @@ -23,8 +23,8 @@ module.exports = { recommended: { description: [ "This configuration includes rules which I recommend to avoid QUnit runtime errors or incorrect behavior, some of which can be difficult to debug. Some of these rules also encourage best practices that help QUnit work better for you.", - "For ESLint `.eslintrc.js` legacy config, extend from `\"plugin:qunit/recommended\"`.", - "For ESLint `eslint.config.js` flat config, load from `require('eslint-plugin-qunit/configs/recommended')`." + 'For ESLint `.eslintrc.js` legacy config, extend from `"plugin:qunit/recommended"`.', + "For ESLint `eslint.config.js` flat config, load from `require('eslint-plugin-qunit/configs/recommended')`.", ].join(" "), plugins: ["qunit"], rules: { @@ -62,8 +62,8 @@ module.exports = { "qunit/no-throws-string": "error", "qunit/require-expect": "error", "qunit/require-object-in-propequal": "error", - "qunit/resolve-async": "error" - } - } - } + "qunit/resolve-async": "error", + }, + }, + }, }; diff --git a/lib/configs/recommended.js b/lib/configs/recommended.js index e5c31c18..2c37001b 100644 --- a/lib/configs/recommended.js +++ b/lib/configs/recommended.js @@ -4,5 +4,5 @@ const plugin = require("../../index.js"); module.exports = { plugins: { qunit: plugin }, - rules: plugin.configs.recommended.rules + rules: plugin.configs.recommended.rules, }; diff --git a/lib/rules/assert-args.js b/lib/rules/assert-args.js index cc978a44..2901b4b9 100644 --- a/lib/rules/assert-args.js +++ b/lib/rules/assert-args.js @@ -20,15 +20,18 @@ module.exports = { meta: { type: "problem", docs: { - description: "enforce that the correct number of assert arguments are used", + description: + "enforce that the correct number of assert arguments are used", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/assert-args.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/assert-args.md", }, messages: { - unexpectedArgCount: "Unexpected call to {{callee}} with {{argCount}} arguments.", - unexpectedArgCountNoMessage: "Unexpected call to {{callee}} with {{argCount}} arguments and no error message." + unexpectedArgCount: + "Unexpected call to {{callee}} with {{argCount}} arguments.", + unexpectedArgCountNoMessage: + "Unexpected call to {{callee}} with {{argCount}} arguments and no error message.", }, - schema: [] + schema: [], }, create: function (context) { @@ -52,7 +55,10 @@ module.exports = { } function checkAssertArity(callExpressionNode) { - const allowedArities = utils.getAllowedArities(callExpressionNode.callee, getAssertContext()), + const allowedArities = utils.getAllowedArities( + callExpressionNode.callee, + getAssertContext(), + ), assertArgs = callExpressionNode.arguments, lastArg = assertArgs[assertArgs.length - 1], mayHaveMessage = lastArg && isPossibleMessage(lastArg); @@ -61,7 +67,10 @@ module.exports = { return assertArgs.length < arity; }); - if (mayHaveMessage && allowedArities.includes(assertArgs.length - 1)) { + if ( + mayHaveMessage && + allowedArities.includes(assertArgs.length - 1) + ) { return; } else if (allowedArities.includes(assertArgs.length)) { return; @@ -69,21 +78,29 @@ module.exports = { context.report({ node: callExpressionNode, - messageId: mayHaveMessage && !definitelyTooFewArgs ? "unexpectedArgCount" : "unexpectedArgCountNoMessage", + messageId: + mayHaveMessage && !definitelyTooFewArgs + ? "unexpectedArgCount" + : "unexpectedArgCountNoMessage", data: { callee: sourceCode.getText(callExpressionNode.callee), - argCount: assertArgs.length - } + argCount: assertArgs.length, + }, }); } return { - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isTest(node.callee)) { testStack.push({ - assertContextVar: utils.getAssertContextNameForTest(node.arguments) + assertContextVar: utils.getAssertContextNameForTest( + node.arguments, + ), }); - } else if (testStack.length > 0 && utils.isAssertion(node.callee, getAssertContext())) { + } else if ( + testStack.length > 0 && + utils.isAssertion(node.callee, getAssertContext()) + ) { checkAssertArity(node); } }, @@ -92,7 +109,7 @@ module.exports = { if (utils.isTest(node.callee)) { testStack.pop(); } - } + }, }; - } + }, }; diff --git a/lib/rules/literal-compare-order.js b/lib/rules/literal-compare-order.js index f0eec5e5..acd73cab 100644 --- a/lib/rules/literal-compare-order.js +++ b/lib/rules/literal-compare-order.js @@ -20,7 +20,7 @@ function swapFirstTwoNodesInList(sourceCode, fixer, list) { const node1Text = sourceCode.getText(list[1]); return [ fixer.replaceText(list[0], node1Text), - fixer.replaceText(list[1], node0Text) + fixer.replaceText(list[1], node0Text), ]; } @@ -29,16 +29,19 @@ module.exports = { meta: { type: "suggestion", docs: { - description: "enforce comparison assertions have arguments in the right order", + description: + "enforce comparison assertions have arguments in the right order", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/literal-compare-order.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/literal-compare-order.md", }, fixable: "code", messages: { - actualFirst: "Expected value {{expected}} should be specified after actual value {{actual}}.", - expectedFirst: "Actual value {{actual}} should be specified after expected value {{expected}}." + actualFirst: + "Expected value {{expected}} should be specified after actual value {{actual}}.", + expectedFirst: + "Actual value {{actual}} should be specified after expected value {{expected}}.", }, - schema: [] + schema: [], }, create: function (context) { @@ -56,29 +59,38 @@ module.exports = { return; } - if (compareActualFirst && args[0].type === "Literal" && args[1].type !== "Literal") { + /* istanbul ignore else: no assertions compare expected first */ + if ( + compareActualFirst && + args[0].type === "Literal" && + args[1].type !== "Literal" + ) { context.report({ node: args[0], messageId: "actualFirst", data: { expected: sourceCode.getText(args[0]), - actual: sourceCode.getText(args[1]) + actual: sourceCode.getText(args[1]), }, fix(fixer) { return swapFirstTwoNodesInList(sourceCode, fixer, args); - } + }, }); - } else /* istanbul ignore next: no assertions compare expected first */ if (!compareActualFirst && args[0].type !== "Literal" && args[1].type === "Literal") { + } else if ( + !compareActualFirst && + args[0].type !== "Literal" && + args[1].type === "Literal" + ) { context.report({ node: args[0], messageId: "expectedFirst", data: { expected: sourceCode.getText(args[0]), - actual: sourceCode.getText(args[1]) + actual: sourceCode.getText(args[1]), }, fix(fixer) { return swapFirstTwoNodesInList(sourceCode, fixer, args); - } + }, }); } } @@ -86,19 +98,27 @@ module.exports = { function processAssertion(node, assertVar) { /* istanbul ignore else: correctly does nothing */ if (utils.isComparativeAssertion(node.callee, assertVar)) { - const compareActualFirst = utils.shouldCompareActualFirst(node.callee, assertVar); + const compareActualFirst = utils.shouldCompareActualFirst( + node.callee, + assertVar, + ); checkLiteralCompareOrder(node.arguments, compareActualFirst); } } return { - "CallExpression": function (node) { + CallExpression: function (node) { /* istanbul ignore else: correctly does nothing */ if (utils.isTest(node.callee)) { testStack.push({ - assertContextVar: utils.getAssertContextNameForTest(node.arguments) + assertContextVar: utils.getAssertContextNameForTest( + node.arguments, + ), }); - } else if (testStack.length > 0 && utils.isAssertion(node.callee, getAssertContext())) { + } else if ( + testStack.length > 0 && + utils.isAssertion(node.callee, getAssertContext()) + ) { processAssertion(node, getAssertContext()); } }, @@ -107,7 +127,7 @@ module.exports = { if (utils.isTest(node.callee)) { testStack.pop(); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-arrow-tests.js b/lib/rules/no-arrow-tests.js index d64520f7..3f2dcc77 100644 --- a/lib/rules/no-arrow-tests.js +++ b/lib/rules/no-arrow-tests.js @@ -21,15 +21,17 @@ module.exports = { meta: { type: "problem", docs: { - description: "disallow arrow functions as QUnit test/module callbacks", + description: + "disallow arrow functions as QUnit test/module callbacks", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-arrow-tests.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-arrow-tests.md", }, fixable: "code", messages: { - noArrowFunction: "Arrow function should not be used as test callback." + noArrowFunction: + "Arrow function should not be used as test callback.", }, - schema: [] + schema: [], }, create: function (context) { @@ -50,22 +52,34 @@ module.exports = { let firstToken = sourceCode.getFirstToken(fn); let functionKeyword = "function"; - let params = extractSourceTextByRange(firstToken.range[0], beforeArrowToken.range[1]); + let params = extractSourceTextByRange( + firstToken.range[0], + beforeArrowToken.range[1], + ); if (fn.async) { // When 'async' specified strip the token from the params text // and prepend it to the function keyword - params = params.slice(firstToken.range[1] - firstToken.range[0]).trim(); + params = params + .slice(firstToken.range[1] - firstToken.range[0]) + .trim(); functionKeyword = "async function"; // Advance firstToken pointer firstToken = sourceCode.getTokenAfter(firstToken); } - const beforeArrowComment = extractSourceTextByRange(beforeArrowToken.range[1], arrow.range[0]); - const afterArrowComment = extractSourceTextByRange(arrow.range[1], fn.body.range[0]); - const paramsFullText = firstToken.type === "Punctuator" ? - `${params}${beforeArrowComment}${afterArrowComment}` : - `(${params}${beforeArrowComment})${afterArrowComment}`; + const beforeArrowComment = extractSourceTextByRange( + beforeArrowToken.range[1], + arrow.range[0], + ); + const afterArrowComment = extractSourceTextByRange( + arrow.range[1], + fn.body.range[0], + ); + const paramsFullText = + firstToken.type === "Punctuator" + ? `${params}${beforeArrowComment}${afterArrowComment}` + : `(${params}${beforeArrowComment})${afterArrowComment}`; return `${functionKeyword}${paramsFullText} `; } @@ -76,14 +90,17 @@ module.exports = { // simply replace '(...) => ' with 'function () ' return fixer.replaceTextRange( [fn.range[0], fn.body.range[0]], - formatFunctionHead(fn) + formatFunctionHead(fn), ); } - const bodyText = sourceCode.text.slice(fn.body.range[0], fn.body.range[1]); + const bodyText = sourceCode.text.slice( + fn.body.range[0], + fn.body.range[1], + ); return fixer.replaceTextRange( [fn.range[0], fn.range[1]], - `${formatFunctionHead(fn)}{ return ${bodyText}; }` + `${formatFunctionHead(fn)}{ return ${bodyText}; }`, ); } @@ -92,23 +109,27 @@ module.exports = { context.report({ node: fn, messageId: "noArrowFunction", - fix: fixer => fixArrowFunction(fixer, fn) + fix: (fixer) => fixArrowFunction(fixer, fn), }); } } function isPropertyInModule(propertyNode) { - return propertyNode && + return ( + propertyNode && propertyNode.parent && propertyNode.parent.type === "ObjectExpression" && propertyNode.parent.parent && propertyNode.parent.parent.type === "CallExpression" && - utils.isModule(propertyNode.parent.parent.callee); + utils.isModule(propertyNode.parent.parent.callee) + ); } function isModuleProperty(propertyNode) { - return isPropertyInModule(propertyNode) && - utils.isModuleHookPropertyKey(propertyNode.key); + return ( + isPropertyInModule(propertyNode) && + utils.isModuleHookPropertyKey(propertyNode.key) + ); } //-------------------------------------------------------------------------- @@ -116,17 +137,21 @@ module.exports = { //-------------------------------------------------------------------------- return { - "CallExpression": function (node) { - if (utils.isTest(node.callee) && node.arguments && node.arguments.length > 1) { + CallExpression: function (node) { + if ( + utils.isTest(node.callee) && + node.arguments && + node.arguments.length > 1 + ) { checkCallback(node.arguments[1]); } }, - "Property": function (node) { + Property: function (node) { if (isModuleProperty(node)) { checkCallback(node.value); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-assert-equal-boolean.js b/lib/rules/no-assert-equal-boolean.js index 0e1facbc..9a10c092 100644 --- a/lib/rules/no-assert-equal-boolean.js +++ b/lib/rules/no-assert-equal-boolean.js @@ -20,13 +20,14 @@ module.exports = { docs: { description: "require use of boolean assertions", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-assert-equal-boolean.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-assert-equal-boolean.md", }, fixable: "code", messages: { - useAssertTrueOrFalse: "Use `assert.true or `assert.false` for boolean assertions." + useAssertTrueOrFalse: + "Use `assert.true or `assert.false` for boolean assertions.", }, - schema: [] + schema: [], }, create: function (context) { @@ -41,32 +42,43 @@ module.exports = { // Check for something like `equal(...)` without assert parameter. function isGlobalEqualityAssertion(calleeNode) { - return calleeNode && + return ( + calleeNode && calleeNode.type === "Identifier" && - EQUALITY_ASSERTIONS.has(calleeNode.name); + EQUALITY_ASSERTIONS.has(calleeNode.name) + ); } // Check for something like `assert.equal(...)`. function isAssertEquality(calleeNode) { - return calleeNode && + return ( + calleeNode && calleeNode.type === "MemberExpression" && calleeNode.property.type === "Identifier" && EQUALITY_ASSERTIONS.has(calleeNode.property.name) && calleeNode.object.type === "Identifier" && - calleeNode.object.name === getCurrentAssertContextVariable(); + calleeNode.object.name === getCurrentAssertContextVariable() + ); } // Check for something like `equal(...)` or `assert.equal(...)`. function isEqualityAssertion(calleeNode) { - return isGlobalEqualityAssertion(calleeNode) || - isAssertEquality(calleeNode); + return ( + isGlobalEqualityAssertion(calleeNode) || + isAssertEquality(calleeNode) + ); } // Finds the first boolean argument of a CallExpression if one exists. function getBooleanArgument(node) { - return node.arguments.length >= 2 && - [node.arguments[0], node.arguments[1]] - .find(arg => arg.type === "Literal" && (arg.value === true || arg.value === false)); + return ( + node.arguments.length >= 2 && + [node.arguments[0], node.arguments[1]].find( + (arg) => + arg.type === "Literal" && + (arg.value === true || arg.value === false), + ) + ); } function reportError(node) { @@ -75,36 +87,58 @@ module.exports = { messageId: "useAssertTrueOrFalse", fix(fixer) { const booleanArgument = getBooleanArgument(node); - const newAssertionFunctionName = booleanArgument.value ? "true" : "false"; + const newAssertionFunctionName = booleanArgument.value + ? "true" + : "false"; const sourceCode = context.getSourceCode(); - const newArgsTextArray = node.arguments.filter(arg => arg !== booleanArgument).map(arg => sourceCode.getText(arg)); + const newArgsTextArray = node.arguments + .filter((arg) => arg !== booleanArgument) + .map((arg) => sourceCode.getText(arg)); const newArgsTextJoined = newArgsTextArray.join(", "); - const assertVariablePrefix = node.callee.type === "Identifier" ? "" : `${getCurrentAssertContextVariable()}.`; + const assertVariablePrefix = + node.callee.type === "Identifier" + ? "" + : `${getCurrentAssertContextVariable()}.`; - return fixer.replaceText(node, `${assertVariablePrefix}${newAssertionFunctionName}(${newArgsTextJoined})`); - } + return fixer.replaceText( + node, + `${assertVariablePrefix}${newAssertionFunctionName}(${newArgsTextJoined})`, + ); + }, }); } return { - "CallExpression": function (node) { + CallExpression: function (node) { /* istanbul ignore else: correctly does nothing */ - if (utils.isTest(node.callee) || utils.isAsyncTest(node.callee)) { + if ( + utils.isTest(node.callee) || + utils.isAsyncTest(node.callee) + ) { testStack.push({ - assertVar: utils.getAssertContextNameForTest(node.arguments) + assertVar: utils.getAssertContextNameForTest( + node.arguments, + ), }); - } else if (testStack.length > 0 && isEqualityAssertion(node.callee) && getBooleanArgument(node)) { + } else if ( + testStack.length > 0 && + isEqualityAssertion(node.callee) && + getBooleanArgument(node) + ) { reportError(node); } }, "CallExpression:exit": function (node) { /* istanbul ignore else: correctly does nothing */ - if (utils.isTest(node.callee) || utils.isAsyncTest(node.callee)) { + if ( + utils.isTest(node.callee) || + utils.isAsyncTest(node.callee) + ) { testStack.pop(); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-assert-equal.js b/lib/rules/no-assert-equal.js index cf56ad58..dd9242fa 100644 --- a/lib/rules/no-assert-equal.js +++ b/lib/rules/no-assert-equal.js @@ -23,17 +23,19 @@ module.exports = { docs: { description: "disallow the use of assert.equal", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-assert-equal.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-assert-equal.md", }, messages: { - unexpectedGlobalEqual: "Unexpected equal. Use strictEqual, deepEqual, or propEqual.", - unexpectedAssertEqual: "Unexpected {{assertVar}}.equal. Use {{assertVar}}.strictEqual, {{assertVar}}.deepEqual, or {{assertVar}}.propEqual.", + unexpectedGlobalEqual: + "Unexpected equal. Use strictEqual, deepEqual, or propEqual.", + unexpectedAssertEqual: + "Unexpected {{assertVar}}.equal. Use {{assertVar}}.strictEqual, {{assertVar}}.deepEqual, or {{assertVar}}.propEqual.", switchToDeepEqual: "Switch to deepEqual.", switchToPropEqual: "Switch to propEqual.", - switchToStrictEqual: "Switch to strictEqual." + switchToStrictEqual: "Switch to strictEqual.", }, schema: [], - hasSuggestions: true + hasSuggestions: true, }, create: function (context) { @@ -52,51 +54,70 @@ module.exports = { } function isAssertEqual(calleeNode) { - return calleeNode && + return ( + calleeNode && calleeNode.type === "MemberExpression" && calleeNode.property.type === "Identifier" && calleeNode.property.name === "equal" && calleeNode.object.type === "Identifier" && - calleeNode.object.name === getCurrentAssertContextVariable(); + calleeNode.object.name === getCurrentAssertContextVariable() + ); } function reportError(node, isGlobal) { context.report({ node: node, - messageId: isGlobal ? "unexpectedGlobalEqual" : "unexpectedAssertEqual", + messageId: isGlobal + ? "unexpectedGlobalEqual" + : "unexpectedAssertEqual", data: { - assertVar: isGlobal ? null : getCurrentAssertContextVariable() + assertVar: isGlobal + ? null + : getCurrentAssertContextVariable(), }, suggest: [ { messageId: "switchToDeepEqual", fix(fixer) { - return fixer.replaceText(isGlobal ? node.callee : node.callee.property, "deepEqual"); - } + return fixer.replaceText( + isGlobal ? node.callee : node.callee.property, + "deepEqual", + ); + }, }, { messageId: "switchToPropEqual", fix(fixer) { - return fixer.replaceText(isGlobal ? node.callee : node.callee.property, "propEqual"); - } + return fixer.replaceText( + isGlobal ? node.callee : node.callee.property, + "propEqual", + ); + }, }, { messageId: "switchToStrictEqual", fix(fixer) { - return fixer.replaceText(isGlobal ? node.callee : node.callee.property, "strictEqual"); - } - } - ] - + return fixer.replaceText( + isGlobal ? node.callee : node.callee.property, + "strictEqual", + ); + }, + }, + ], }); } return { - "CallExpression": function (node) { + CallExpression: function (node) { /* istanbul ignore else: correctly does nothing */ - if (utils.isTest(node.callee) || utils.isAsyncTest(node.callee)) { + if ( + utils.isTest(node.callee) || + utils.isAsyncTest(node.callee) + ) { testStack.push({ - assertVar: utils.getAssertContextNameForTest(node.arguments) + assertVar: utils.getAssertContextNameForTest( + node.arguments, + ), }); } else if (testStack.length > 0) { if (isAssertEqual(node.callee)) { @@ -108,20 +129,25 @@ module.exports = { }, "CallExpression:exit": function (node) { /* istanbul ignore else: correctly does nothing */ - if (utils.isTest(node.callee) || utils.isAsyncTest(node.callee)) { + if ( + utils.isTest(node.callee) || + utils.isAsyncTest(node.callee) + ) { testStack.pop(); } }, - "Program": function () { + Program: function () { // Gather all calls to global `equal()`. const tracker = new ReferenceTracker(context.getScope()); const traceMap = { equal: { [ReferenceTracker.CALL]: true } }; - for (const { node } of tracker.iterateGlobalReferences(traceMap)) { + for (const { node } of tracker.iterateGlobalReferences( + traceMap, + )) { globalEqualCallNodes.add(node); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-assert-logical-expression.js b/lib/rules/no-assert-logical-expression.js index cc0a50d4..a29c149a 100644 --- a/lib/rules/no-assert-logical-expression.js +++ b/lib/rules/no-assert-logical-expression.js @@ -19,16 +19,18 @@ module.exports = { meta: { type: "suggestion", docs: { - description: "disallow binary logical expressions in assert arguments", + description: + "disallow binary logical expressions in assert arguments", category: "Best Practices", recommended: false, - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-assert-logical-expression.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-assert-logical-expression.md", }, fixable: null, messages: { - noLogicalOperator: "Do not use '{{operator}}' in assertion arguments." + noLogicalOperator: + "Do not use '{{operator}}' in assertion arguments.", }, - schema: [] + schema: [], }, create: function (context) { @@ -45,8 +47,8 @@ module.exports = { node: arg, messageId: "noLogicalOperator", data: { - operator: arg.operator - } + operator: arg.operator, + }, }); } } @@ -67,15 +69,20 @@ module.exports = { //---------------------------------------------------------------------- return { - - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isTest(node.callee)) { testStack.push({ - assertContextVar: utils.getAssertContextNameForTest(node.arguments) + assertContextVar: utils.getAssertContextNameForTest( + node.arguments, + ), }); } else if (utils.isAssertion(node.callee, getAssertVar())) { - const countNonMessageArgs = Math.max(...utils.getAllowedArities(node.callee, getAssertVar())); - checkAndReport(node.arguments.slice(0, countNonMessageArgs)); + const countNonMessageArgs = Math.max( + ...utils.getAllowedArities(node.callee, getAssertVar()), + ); + checkAndReport( + node.arguments.slice(0, countNonMessageArgs), + ); } }, @@ -83,8 +90,7 @@ module.exports = { if (utils.isTest(node.callee)) { testStack.pop(); } - } - + }, }; - } + }, }; diff --git a/lib/rules/no-assert-ok.js b/lib/rules/no-assert-ok.js index 529ce4de..7966b4e4 100644 --- a/lib/rules/no-assert-ok.js +++ b/lib/rules/no-assert-ok.js @@ -18,10 +18,14 @@ const GLOBAL_ERROR_MESSAGE_ID = "unexpectedGlobalOkNotOk"; const LOCAL_ERROR_MESSAGE_ID = "unexpectedLocalOkNotOk"; const assertions = ["ok", "notOk"]; const ERROR_MESSAGE_CONFIG = { - ok: { unexpectedGlobalAssertionMessageId: GLOBAL_ERROR_MESSAGE_ID, - unexpectedLocalAssertionMessageId: LOCAL_ERROR_MESSAGE_ID }, - notOk: { unexpectedGlobalAssertionMessageId: GLOBAL_ERROR_MESSAGE_ID, - unexpectedLocalAssertionMessageId: LOCAL_ERROR_MESSAGE_ID } + ok: { + unexpectedGlobalAssertionMessageId: GLOBAL_ERROR_MESSAGE_ID, + unexpectedLocalAssertionMessageId: LOCAL_ERROR_MESSAGE_ID, + }, + notOk: { + unexpectedGlobalAssertionMessageId: GLOBAL_ERROR_MESSAGE_ID, + unexpectedLocalAssertionMessageId: LOCAL_ERROR_MESSAGE_ID, + }, }; /** @type {import('eslint').Rule.RuleModule} */ @@ -30,14 +34,16 @@ module.exports = { type: "suggestion", docs: { description: "disallow the use of assert.ok/assert.notOk", - category: "Best Practices" + category: "Best Practices", }, messages: { - [GLOBAL_ERROR_MESSAGE_ID]: "Unexpected {{assertion}}. Use strictEqual, deepEqual, or propEqual.", - [LOCAL_ERROR_MESSAGE_ID]: "Unexpected {{assertVar}}.{{assertion}}. Use {{assertVar}}.strictEqual, {{assertVar}}.deepEqual, or {{assertVar}}.propEqual." + [GLOBAL_ERROR_MESSAGE_ID]: + "Unexpected {{assertion}}. Use strictEqual, deepEqual, or propEqual.", + [LOCAL_ERROR_MESSAGE_ID]: + "Unexpected {{assertVar}}.{{assertion}}. Use {{assertVar}}.strictEqual, {{assertVar}}.deepEqual, or {{assertVar}}.propEqual.", }, - schema: [] + schema: [], }, - create: utils.createAssertionCheck(assertions, ERROR_MESSAGE_CONFIG) + create: utils.createAssertionCheck(assertions, ERROR_MESSAGE_CONFIG), }; diff --git a/lib/rules/no-async-in-loops.js b/lib/rules/no-async-in-loops.js index 4c88a7cf..e7381c61 100644 --- a/lib/rules/no-async-in-loops.js +++ b/lib/rules/no-async-in-loops.js @@ -18,12 +18,12 @@ module.exports = { docs: { description: "disallow async calls in loops", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-async-in-loops.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-async-in-loops.md", }, messages: { - unexpectedAsyncInLoop: "Unexpected {{call}} in {{loopTypeText}}." + unexpectedAsyncInLoop: "Unexpected {{call}} in {{loopTypeText}}.", }, - schema: [] + schema: [], }, create: function (context) { @@ -31,26 +31,35 @@ module.exports = { assertVariableStack = []; function isAsyncCallExpression(node) { - const assertContextVar = assertVariableStack[assertVariableStack.length - 1]; + const assertContextVar = + assertVariableStack[assertVariableStack.length - 1]; return utils.isAsyncCallExpression(node, assertContextVar); } function popAndMatch(expectedNode) { const actualNode = loopStack.pop(); - assert.strictEqual(actualNode, expectedNode, "Node mismatch in loop stack"); + assert.strictEqual( + actualNode, + expectedNode, + "Node mismatch in loop stack", + ); } function getLoopTypeText(loopType) { switch (loopType) { case "WhileStatement": { return "while loop"; - } case "DoWhileStatement": { + } + case "DoWhileStatement": { return "do-while loop"; - } case "ForStatement": { + } + case "ForStatement": { return "for loop"; - } case "ForInStatement": { + } + case "ForInStatement": { return "for-in loop"; - } case "ForOfStatement": { + } + case "ForOfStatement": { return "for-of loop"; } /* istanbul ignore next */ @@ -65,7 +74,8 @@ module.exports = { /* istanbul ignore else: correctly returning undefined */ if (isAsyncCallExpression(node)) { - const assertContextVar = assertVariableStack[assertVariableStack.length - 1]; + const assertContextVar = + assertVariableStack[assertVariableStack.length - 1]; callType = `${assertContextVar}.async()`; } else if (utils.isStop(node.callee)) { callType = "stop()"; @@ -85,18 +95,21 @@ module.exports = { messageId: "unexpectedAsyncInLoop", data: { call: getAsyncCallType(node), - loopTypeText: getLoopTypeText(loopType) - } + loopTypeText: getLoopTypeText(loopType), + }, }); } return { - "CallExpression": function (node) { + CallExpression: function (node) { /* istanbul ignore else: correctly not doing anything */ if (utils.isTest(node.callee)) { - assertVariableStack.push(utils.getAssertContextNameForTest(node.arguments)); + assertVariableStack.push( + utils.getAssertContextNameForTest(node.arguments), + ); } else if (loopStack.length > 0) { - const isStopOrStartOrAsync = isAsyncCallExpression(node) || + const isStopOrStartOrAsync = + isAsyncCallExpression(node) || utils.isStop(node.callee) || utils.isStart(node.callee); @@ -111,36 +124,36 @@ module.exports = { assertVariableStack.pop(); } }, - "WhileStatement": function (node) { + WhileStatement: function (node) { loopStack.push(node); }, "WhileStatement:exit": function (node) { popAndMatch(node); }, - "DoWhileStatement": function (node) { + DoWhileStatement: function (node) { loopStack.push(node); }, "DoWhileStatement:exit": function (node) { popAndMatch(node); }, - "ForStatement": function (node) { + ForStatement: function (node) { loopStack.push(node); }, "ForStatement:exit": function (node) { popAndMatch(node); }, - "ForInStatement": function (node) { + ForInStatement: function (node) { loopStack.push(node); }, "ForInStatement:exit": function (node) { popAndMatch(node); }, - "ForOfStatement": function (node) { + ForOfStatement: function (node) { loopStack.push(node); }, "ForOfStatement:exit": function (node) { popAndMatch(node); - } + }, }; - } + }, }; diff --git a/lib/rules/no-async-module-callbacks.js b/lib/rules/no-async-module-callbacks.js index 295c4dbe..c44d86f5 100644 --- a/lib/rules/no-async-module-callbacks.js +++ b/lib/rules/no-async-module-callbacks.js @@ -15,7 +15,10 @@ const utils = require("../utils"); //------------------------------------------------------------------------------ function isAsyncFunctionExpression(node) { - return ["ArrowFunctionExpression", "FunctionExpression"].includes(node.type) && node.async === true; + return ( + ["ArrowFunctionExpression", "FunctionExpression"].includes(node.type) && + node.async === true + ); } //------------------------------------------------------------------------------ @@ -30,29 +33,30 @@ module.exports = { description: "disallow async module callbacks", category: "Possible Errors", recommended: false, - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-async-module-callbacks.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-async-module-callbacks.md", }, fixable: null, messages: { - "noAsyncModuleCallbacks": "Do not call module with an async callback function." + noAsyncModuleCallbacks: + "Do not call module with an async callback function.", }, - schema: [] + schema: [], }, create: function (context) { return { - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isModule(node.callee)) { const callback = node.arguments[1]; if (callback && isAsyncFunctionExpression(callback)) { context.report({ node: node, messageId: "noAsyncModuleCallbacks", - data: {} + data: {}, }); } } - } + }, }; - } + }, }; diff --git a/lib/rules/no-async-test.js b/lib/rules/no-async-test.js index 7fb55dbc..e6a2b3a7 100644 --- a/lib/rules/no-async-test.js +++ b/lib/rules/no-async-test.js @@ -21,24 +21,25 @@ module.exports = { docs: { description: "disallow the use of asyncTest or QUnit.asyncTest", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-async-test.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-async-test.md", }, messages: { - unexpectedAsyncTest: "Unexpected asynchronous test. Use assert.async() instead." + unexpectedAsyncTest: + "Unexpected asynchronous test. Use assert.async() instead.", }, - schema: [] + schema: [], }, create: function (context) { return { - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isAsyncTest(node.callee)) { context.report({ node: node, - messageId: "unexpectedAsyncTest" + messageId: "unexpectedAsyncTest", }); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-commented-tests.js b/lib/rules/no-commented-tests.js index b784b81c..05ddaf0f 100644 --- a/lib/rules/no-commented-tests.js +++ b/lib/rules/no-commented-tests.js @@ -15,18 +15,20 @@ module.exports = { docs: { description: "disallow commented tests", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-commented-tests.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-commented-tests.md", }, messages: { - unexpectedTestInComment: "Unexpected \"{{callee}}\" in comment. Use QUnit.skip outside of a comment." + unexpectedTestInComment: + 'Unexpected "{{callee}}" in comment. Use QUnit.skip outside of a comment.', }, - schema: [] + schema: [], }, create: function (context) { const sourceCode = context.getSourceCode(), newlineRegExp = /\r\n|\r|\n/g, - warningRegExp = /\b(QUnit\.test|QUnit\.asyncTest|QUnit\.skip|test|asyncTest)\s*\(\s*["'`]/g; + warningRegExp = + /\b(QUnit\.test|QUnit\.asyncTest|QUnit\.skip|test|asyncTest)\s*\(\s*["'`]/g; function getNewlineIndexes(text) { const indexes = []; @@ -45,8 +47,8 @@ module.exports = { loc: warning.loc, messageId: "unexpectedTestInComment", data: { - callee: warning.term - } + callee: warning.term, + }, }); } @@ -61,7 +63,10 @@ module.exports = { result; while ((result = warningRegExp.exec(text)) !== null) { - while (newlineIndexes.length > 0 && result.index >= newlineIndexes[0]) { + while ( + newlineIndexes.length > 0 && + result.index >= newlineIndexes[0] + ) { ++lineOffset; currentNewlineIndex = newlineIndexes.shift(); } @@ -70,8 +75,10 @@ module.exports = { term: result[1], loc: { line: loc.line + lineOffset, - column: lineOffset ? result.index - currentNewlineIndex : loc.column + result.index - } + column: lineOffset + ? result.index - currentNewlineIndex + : loc.column + result.index, + }, }); } @@ -82,12 +89,13 @@ module.exports = { return { Program: function () { - const comments = sourceCode.getAllComments() - .filter(comment => comment.type !== "Shebang"); + const comments = sourceCode + .getAllComments() + .filter((comment) => comment.type !== "Shebang"); for (const comment of comments) { checkComment(comment); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-compare-relation-boolean.js b/lib/rules/no-compare-relation-boolean.js index e4472de4..30d1cb49 100644 --- a/lib/rules/no-compare-relation-boolean.js +++ b/lib/rules/no-compare-relation-boolean.js @@ -20,66 +20,93 @@ module.exports = { meta: { type: "suggestion", docs: { - description: "disallow comparing relational expressions to booleans in assertions", + description: + "disallow comparing relational expressions to booleans in assertions", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-compare-relation-boolean.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-compare-relation-boolean.md", }, fixable: "code", messages: { - redundantComparison: "Redundant comparison of relational expression to boolean literal." + redundantComparison: + "Redundant comparison of relational expression to boolean literal.", }, - schema: [] + schema: [], }, create: function (context) { const testStack = [], RELATIONAL_OPS = new Set([ - "==", "!=", "===", "!==", "<", "<=", ">", ">=", - "in", "instanceof" + "==", + "!=", + "===", + "!==", + "<", + "<=", + ">", + ">=", + "in", + "instanceof", ]); function shouldCheckArguments(calleeNode) { assert.ok(testStack.length); - const assertContextVar = testStack[testStack.length - 1].assertContextVar; + const assertContextVar = + testStack[testStack.length - 1].assertContextVar; - return utils.isAssertion(calleeNode, assertContextVar) && utils.isComparativeAssertion(calleeNode, assertContextVar); + return ( + utils.isAssertion(calleeNode, assertContextVar) && + utils.isComparativeAssertion(calleeNode, assertContextVar) + ); } function sortLiteralFirst(a, b) { if (a.type === "Literal" && b.type !== "Literal") { - return -1; // Literal is first and should remain first + return -1; // Literal is first and should remain first } if (a.type !== "Literal" && b.type === "Literal") { - return 1; // Literal is second and should be first + return 1; // Literal is second and should be first } return 0; } function checkAndReport(callExprNode, literalNode, binaryExprNode) { - if (RELATIONAL_OPS.has(binaryExprNode.operator) && typeof literalNode.value === "boolean") { + if ( + RELATIONAL_OPS.has(binaryExprNode.operator) && + typeof literalNode.value === "boolean" + ) { context.report({ node: callExprNode, messageId: "redundantComparison", fix(fixer) { const sourceCode = context.getSourceCode(); - const assertionVariableName = callExprNode.callee.object.name; + const assertionVariableName = + callExprNode.callee.object.name; // Decide which assertion function to use based on how many negations we have. let countNegations = 0; - if (callExprNode.callee.property.name.startsWith("not")) { + if ( + callExprNode.callee.property.name.startsWith("not") + ) { countNegations++; } if (!literalNode.value) { countNegations++; } - const newAssertionFunctionName = countNegations % 2 === 0 ? "ok" : "notOk"; - const newArgsTextArray = [binaryExprNode, ...callExprNode.arguments.slice(2)].map(arg => sourceCode.getText(arg)); + const newAssertionFunctionName = + countNegations % 2 === 0 ? "ok" : "notOk"; + const newArgsTextArray = [ + binaryExprNode, + ...callExprNode.arguments.slice(2), + ].map((arg) => sourceCode.getText(arg)); const newArgsTextJoined = newArgsTextArray.join(", "); - return fixer.replaceText(callExprNode, `${assertionVariableName}.${newAssertionFunctionName}(${newArgsTextJoined})`); - } + return fixer.replaceText( + callExprNode, + `${assertionVariableName}.${newAssertionFunctionName}(${newArgsTextJoined})`, + ); + }, }); } } @@ -92,18 +119,30 @@ module.exports = { const firstTwoArgsSorted = args.slice(0, 2).sort(sortLiteralFirst); - if (firstTwoArgsSorted[0].type === "Literal" && firstTwoArgsSorted[1].type === "BinaryExpression") { - checkAndReport(callExprNode, firstTwoArgsSorted[0], firstTwoArgsSorted[1]); + if ( + firstTwoArgsSorted[0].type === "Literal" && + firstTwoArgsSorted[1].type === "BinaryExpression" + ) { + checkAndReport( + callExprNode, + firstTwoArgsSorted[0], + firstTwoArgsSorted[1], + ); } } return { - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isTest(node.callee)) { testStack.push({ - assertContextVar: utils.getAssertContextNameForTest(node.arguments) + assertContextVar: utils.getAssertContextNameForTest( + node.arguments, + ), }); - } else if (testStack.length > 0 && shouldCheckArguments(node.callee)) { + } else if ( + testStack.length > 0 && + shouldCheckArguments(node.callee) + ) { checkAssertArguments(node); } }, @@ -112,7 +151,7 @@ module.exports = { if (utils.isTest(node.callee)) { testStack.pop(); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-conditional-assertions.js b/lib/rules/no-conditional-assertions.js index ce8ca36b..0844784f 100644 --- a/lib/rules/no-conditional-assertions.js +++ b/lib/rules/no-conditional-assertions.js @@ -14,12 +14,15 @@ const utils = require("../utils"); // Constants //------------------------------------------------------------------------------ -const CONDITIONAL_NODE_TYPES = new Set(["IfStatement", "ConditionalExpression"]); +const CONDITIONAL_NODE_TYPES = new Set([ + "IfStatement", + "ConditionalExpression", +]); const STOP_NODE_TYPES = new Set([ "FunctionExpression", "FunctionDeclaration", - "ArrowFunctionExpression" + "ArrowFunctionExpression", ]); //------------------------------------------------------------------------------ @@ -31,16 +34,18 @@ module.exports = { meta: { type: "suggestion", docs: { - description: "disallow assertions within if statements or conditional expressions", + description: + "disallow assertions within if statements or conditional expressions", category: "Best Practices", recommended: false, - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-conditional-assertions.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-conditional-assertions.md", }, - fixable: null, // or "code" or "whitespace" + fixable: null, // or "code" or "whitespace" messages: { - noAssertionInsideConditional: "Do not place an assertion inside a conditional." + noAssertionInsideConditional: + "Do not place an assertion inside a conditional.", }, - schema: [] + schema: [], }, create: function (context) { @@ -61,20 +66,25 @@ module.exports = { function checkAndReport(assertNode) { let currentNode = assertNode; - while (currentNode && !isStopNode(currentNode) && !isConditionalNode(currentNode)) { + while ( + currentNode && + !isStopNode(currentNode) && + !isConditionalNode(currentNode) + ) { currentNode = currentNode.parent; } if (CONDITIONAL_NODE_TYPES.has(currentNode.type)) { context.report({ node: assertNode, - messageId: "noAssertionInsideConditional" + messageId: "noAssertionInsideConditional", }); } } function isAssertion(calleeNode) { - const assertContextVar = testStack[testStack.length - 1].assertContextVar; + const assertContextVar = + testStack[testStack.length - 1].assertContextVar; return utils.isAssertion(calleeNode, assertContextVar); } @@ -83,10 +93,12 @@ module.exports = { //---------------------------------------------------------------------- return { - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isTest(node.callee)) { testStack.push({ - assertContextVar: utils.getAssertContextNameForTest(node.arguments) + assertContextVar: utils.getAssertContextNameForTest( + node.arguments, + ), }); } else if (testStack.length > 0 && isAssertion(node.callee)) { checkAndReport(node); @@ -97,7 +109,7 @@ module.exports = { if (utils.isTest(node.callee)) { testStack.pop(); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-early-return.js b/lib/rules/no-early-return.js index f161b16a..0025a710 100644 --- a/lib/rules/no-early-return.js +++ b/lib/rules/no-early-return.js @@ -22,12 +22,12 @@ module.exports = { docs: { description: "disallow early return in tests", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-early-return.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-early-return.md", }, messages: { - noEarlyReturn: "Do not return early from a QUnit test." + noEarlyReturn: "Do not return early from a QUnit test.", }, - schema: [] + schema: [], }, create: function (context) { @@ -37,7 +37,7 @@ module.exports = { function pushFunction() { if (assertContextVar !== null) { functionScopes.push({ - returnAndAssertNodes: [] + returnAndAssertNodes: [], }); } } @@ -49,19 +49,32 @@ module.exports = { let lastAssert = null, i; - for (i = lastScope.returnAndAssertNodes.length - 1; i >= 0; --i) { - if (lastScope.returnAndAssertNodes[i].type === "CallExpression") { + for ( + i = lastScope.returnAndAssertNodes.length - 1; + i >= 0; + --i + ) { + if ( + lastScope.returnAndAssertNodes[i].type === + "CallExpression" + ) { lastAssert = i; break; } } - if (lastAssert !== null && lastScope.returnAndAssertNodes.length > 0) { - for (const node of lastScope.returnAndAssertNodes.slice(0, lastAssert)) { + if ( + lastAssert !== null && + lastScope.returnAndAssertNodes.length > 0 + ) { + for (const node of lastScope.returnAndAssertNodes.slice( + 0, + lastAssert, + )) { if (node.type === "ReturnStatement") { context.report({ node: node, - messageId: "noEarlyReturn" + messageId: "noEarlyReturn", }); } } @@ -70,21 +83,30 @@ module.exports = { } return { - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isTest(node.callee)) { - assertContextVar = utils.getAssertContextNameForTest(node.arguments); - } else if (utils.isAssertion(node.callee, assertContextVar) && functionScopes.length > 0) { - functionScopes[functionScopes.length - 1].returnAndAssertNodes.push(node); + assertContextVar = utils.getAssertContextNameForTest( + node.arguments, + ); + } else if ( + utils.isAssertion(node.callee, assertContextVar) && + functionScopes.length > 0 + ) { + functionScopes[ + functionScopes.length - 1 + ].returnAndAssertNodes.push(node); } }, - "FunctionDeclaration": pushFunction, - "FunctionExpression": pushFunction, - "ArrowFunctionExpression": pushFunction, + FunctionDeclaration: pushFunction, + FunctionExpression: pushFunction, + ArrowFunctionExpression: pushFunction, - "ReturnStatement": function (node) { + ReturnStatement: function (node) { if (functionScopes.length > 0) { - functionScopes[functionScopes.length - 1].returnAndAssertNodes.push(node); + functionScopes[ + functionScopes.length - 1 + ].returnAndAssertNodes.push(node); } }, @@ -96,7 +118,7 @@ module.exports = { "FunctionDeclaration:exit": popFunction, "FunctionExpression:exit": popFunction, - "ArrowFunctionExpression:exit": popFunction + "ArrowFunctionExpression:exit": popFunction, }; - } + }, }; diff --git a/lib/rules/no-global-assertions.js b/lib/rules/no-global-assertions.js index 86fa1f8f..8fe2785d 100644 --- a/lib/rules/no-global-assertions.js +++ b/lib/rules/no-global-assertions.js @@ -22,33 +22,36 @@ module.exports = { docs: { description: "disallow global QUnit assertions", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-global-assertions.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-global-assertions.md", }, messages: { - unexpectedGlobalAssertion: "Unexpected global `{{ assertion }}` assertion." + unexpectedGlobalAssertion: + "Unexpected global `{{ assertion }}` assertion.", }, - schema: [] + schema: [], }, create: function (context) { return { - "Program": function () { + Program: function () { const tracker = new ReferenceTracker(context.getScope()); const traceMap = {}; for (const assertionName of getAssertionNames()) { traceMap[assertionName] = { [ReferenceTracker.CALL]: true }; } - for (const { node } of tracker.iterateGlobalReferences(traceMap)) { + for (const { node } of tracker.iterateGlobalReferences( + traceMap, + )) { context.report({ node: node, messageId: "unexpectedGlobalAssertion", data: { - assertion: node.callee.name - } + assertion: node.callee.name, + }, }); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-global-expect.js b/lib/rules/no-global-expect.js index 55c667ba..5b5c6d36 100644 --- a/lib/rules/no-global-expect.js +++ b/lib/rules/no-global-expect.js @@ -21,27 +21,29 @@ module.exports = { docs: { description: "disallow global expect", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-global-expect.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-global-expect.md", }, messages: { - unexpectedGlobalExpect: "Unexpected global expect." + unexpectedGlobalExpect: "Unexpected global expect.", }, - schema: [] + schema: [], }, create: function (context) { return { - "Program": function () { + Program: function () { const tracker = new ReferenceTracker(context.getScope()); const traceMap = { expect: { [ReferenceTracker.CALL]: true } }; - for (const { node } of tracker.iterateGlobalReferences(traceMap)) { + for (const { node } of tracker.iterateGlobalReferences( + traceMap, + )) { context.report({ node: node, - messageId: "unexpectedGlobalExpect" + messageId: "unexpectedGlobalExpect", }); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-global-module-test.js b/lib/rules/no-global-module-test.js index 7b1cdb6e..bdb69bdf 100644 --- a/lib/rules/no-global-module-test.js +++ b/lib/rules/no-global-module-test.js @@ -21,34 +21,36 @@ module.exports = { docs: { description: "disallow global module/test/asyncTest", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-global-module-test.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-global-module-test.md", }, messages: { - unexpectedGlobalModuleTest: "Unexpected global `{{ callee }}`." + unexpectedGlobalModuleTest: "Unexpected global `{{ callee }}`.", }, - schema: [] + schema: [], }, create: function (context) { return { - "Program": function () { + Program: function () { const tracker = new ReferenceTracker(context.getScope()); const traceMap = { asyncTest: { [ReferenceTracker.CALL]: true }, module: { [ReferenceTracker.CALL]: true }, - test: { [ReferenceTracker.CALL]: true } + test: { [ReferenceTracker.CALL]: true }, }; - for (const { node } of tracker.iterateGlobalReferences(traceMap)) { + for (const { node } of tracker.iterateGlobalReferences( + traceMap, + )) { context.report({ node: node, messageId: "unexpectedGlobalModuleTest", data: { - callee: node.callee.name - } + callee: node.callee.name, + }, }); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-global-stop-start.js b/lib/rules/no-global-stop-start.js index 0d5b002e..1ca23b5e 100644 --- a/lib/rules/no-global-stop-start.js +++ b/lib/rules/no-global-stop-start.js @@ -19,12 +19,12 @@ module.exports = { docs: { description: "disallow global stop/start", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-global-stop-start.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-global-stop-start.md", }, messages: { - unexpectedGlobalStopStart: "Unexpected global {{callee}}() call." + unexpectedGlobalStopStart: "Unexpected global {{callee}}() call.", }, - schema: [] + schema: [], }, create: function (context) { @@ -33,23 +33,25 @@ module.exports = { //-------------------------------------------------------------------------- return { - "Program": function () { + Program: function () { const tracker = new ReferenceTracker(context.getScope()); const traceMap = { start: { [ReferenceTracker.CALL]: true }, - stop: { [ReferenceTracker.CALL]: true } + stop: { [ReferenceTracker.CALL]: true }, }; - for (const { node } of tracker.iterateGlobalReferences(traceMap)) { + for (const { node } of tracker.iterateGlobalReferences( + traceMap, + )) { context.report({ node: node, messageId: "unexpectedGlobalStopStart", data: { - callee: node.callee.name - } + callee: node.callee.name, + }, }); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-hooks-from-ancestor-modules.js b/lib/rules/no-hooks-from-ancestor-modules.js index e268dd85..608d972f 100644 --- a/lib/rules/no-hooks-from-ancestor-modules.js +++ b/lib/rules/no-hooks-from-ancestor-modules.js @@ -24,13 +24,14 @@ module.exports = { description: "disallow the use of hooks from ancestor modules", category: "Possible Errors", recommended: false, - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-hooks-from-ancestor-modules.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-hooks-from-ancestor-modules.md", }, fixable: null, messages: { - "noHooksFromAncestorModules": "Do not call {{usedHooksIdentifierName}}.{{invokedMethodName}} from an ancestor module." + noHooksFromAncestorModules: + "Do not call {{usedHooksIdentifierName}}.{{invokedMethodName}} from an ancestor module.", }, - schema: [] + schema: [], }, create: function (context) { @@ -41,35 +42,52 @@ module.exports = { //---------------------------------------------------------------------- function isInModuleCallbackBody(callExpressionNode) { - return callExpressionNode && + return ( + callExpressionNode && callExpressionNode.parent && callExpressionNode.parent.type === "ExpressionStatement" && callExpressionNode.parent.parent && callExpressionNode.parent.parent.type === "BlockStatement" && callExpressionNode.parent.parent.parent && - ["FunctionExpression", "ArrowFunctionExpression"].includes(callExpressionNode.parent.parent.parent.type) && + ["FunctionExpression", "ArrowFunctionExpression"].includes( + callExpressionNode.parent.parent.parent.type, + ) && callExpressionNode.parent.parent.parent.parent && - callExpressionNode.parent.parent.parent.parent.type === "CallExpression" && - utils.isModule(callExpressionNode.parent.parent.parent.parent.callee); + callExpressionNode.parent.parent.parent.parent.type === + "CallExpression" && + utils.isModule( + callExpressionNode.parent.parent.parent.parent.callee, + ) + ); } function isHookInvocation(node) { - return node.callee.type === "MemberExpression" && + return ( + node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && NESTABLE_HOOK_NAMES.has(node.callee.property.name) && - isInModuleCallbackBody(node); + isInModuleCallbackBody(node) + ); } function getCallbackArg(args) { // Callback can be either args[1] or args[2] // https://api.qunitjs.com/QUnit/module/ - return args.slice(1, 3).find(arg => ["FunctionExpression", "ArrowFunctionExpression"].includes(arg.type)); + return args + .slice(1, 3) + .find((arg) => + ["FunctionExpression", "ArrowFunctionExpression"].includes( + arg.type, + ), + ); } function getHooksIdentifierFromParams(params) { // In TypeScript, `this` can be passed as the first function parameter to add a type to it, // and we want to ignore that parameter since we're looking for the `hooks` variable. - return params.find(p => p.type === "Identifier" && p.name !== "this"); + return params.find( + (p) => p.type === "Identifier" && p.name !== "this", + ); } //---------------------------------------------------------------------- @@ -77,31 +95,39 @@ module.exports = { //---------------------------------------------------------------------- return { - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isModule(node.callee)) { const moduleStackInfo = { callExpression: node, - description: node.arguments[0].value + description: node.arguments[0].value, }; const callback = getCallbackArg(node.arguments); - const hooksParam = callback ? getHooksIdentifierFromParams(callback.params) : null; - moduleStackInfo.hookIdentifierName = hooksParam ? hooksParam.name : null; + const hooksParam = callback + ? getHooksIdentifierFromParams(callback.params) + : null; + moduleStackInfo.hookIdentifierName = hooksParam + ? hooksParam.name + : null; moduleStack.push(moduleStackInfo); } else if (isHookInvocation(node)) { - const containingModuleInfo = moduleStack[moduleStack.length - 1]; - const expectedHooksIdentifierName = containingModuleInfo.hookIdentifierName; + const containingModuleInfo = + moduleStack[moduleStack.length - 1]; + const expectedHooksIdentifierName = + containingModuleInfo.hookIdentifierName; const usedHooksIdentifierName = node.callee.object.name; const invokedMethodName = node.callee.property.name; - if (expectedHooksIdentifierName !== usedHooksIdentifierName) { + if ( + expectedHooksIdentifierName !== usedHooksIdentifierName + ) { context.report({ node: node.callee, messageId: "noHooksFromAncestorModules", data: { invokedMethodName, - usedHooksIdentifierName - } + usedHooksIdentifierName, + }, }); } } @@ -111,7 +137,7 @@ module.exports = { if (utils.isModule(node.callee)) { moduleStack.pop(); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-identical-names.js b/lib/rules/no-identical-names.js index 0ac4ca9e..46cc23df 100644 --- a/lib/rules/no-identical-names.js +++ b/lib/rules/no-identical-names.js @@ -15,7 +15,7 @@ const utils = require("../utils"); //------------------------------------------------------------------------------ function findLast(arr, callback) { - return [...arr].reverse().find(item => callback(item)); + return [...arr].reverse().find((item) => callback(item)); } /** @type {import('eslint').Rule.RuleModule} */ @@ -25,14 +25,17 @@ module.exports = { docs: { description: "disallow identical test and module names", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-identical-names.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-identical-names.md", }, messages: { - duplicateTest: "Test name is used on line {{ line }} in the same module.", - duplicateModule: "Module name is used by sibling on line {{ line }}.", - duplicateModuleAncestor: "Module name is used by ancestor on line {{ line }}." + duplicateTest: + "Test name is used on line {{ line }} in the same module.", + duplicateModule: + "Module name is used by sibling on line {{ line }}.", + duplicateModuleAncestor: + "Module name is used by ancestor on line {{ line }}.", }, - schema: [] + schema: [], }, create: function (context) { @@ -42,7 +45,7 @@ module.exports = { mapModuleNodeToInfo.set(TOP_LEVEL_MODULE_NODE, { modules: [], // Children module nodes. tests: [], // Children test nodes. - hasNestedTests: false // Whether this module has tests nested inside it. + hasNestedTests: false, // Whether this module has tests nested inside it. }); //---------------------------------------------------------------------- @@ -50,19 +53,33 @@ module.exports = { //---------------------------------------------------------------------- function isFirstArgLiteral(node) { - return node.arguments && node.arguments[0] && node.arguments[0].type === "Literal"; + return ( + node.arguments && + node.arguments[0] && + node.arguments[0].type === "Literal" + ); } function moduleHasNestedTests(node) { const moduleInfo = mapModuleNodeToInfo.get(node); - return moduleInfo.tests.length > 0 || moduleInfo.modules.some(moduleNode => moduleHasNestedTests(moduleNode)); + return ( + moduleInfo.tests.length > 0 || + moduleInfo.modules.some((moduleNode) => + moduleHasNestedTests(moduleNode), + ) + ); } function getCurrentModuleNode() { - const parentModule = mapModuleNodeToInfo.get(modulesStack[modulesStack.length - 1]); + const parentModule = mapModuleNodeToInfo.get( + modulesStack[modulesStack.length - 1], + ); if (parentModule.modules.length > 0) { // Find the last test-less module at the current level if one exists, i.e: module('foo'); - const lastTestLessModule = findLast(parentModule.modules, node => !mapModuleNodeToInfo.get(node).hasNestedTests); + const lastTestLessModule = findLast( + parentModule.modules, + (node) => !mapModuleNodeToInfo.get(node).hasNestedTests, + ); if (lastTestLessModule) { return lastTestLessModule; } @@ -74,17 +91,21 @@ module.exports = { if (utils.isTest(node.callee)) { const title = node.arguments[0].value; const currentModuleNode = getCurrentModuleNode(); - const currentModuleInfo = mapModuleNodeToInfo.get(currentModuleNode); + const currentModuleInfo = + mapModuleNodeToInfo.get(currentModuleNode); // Check if we have seen this test name in the current module yet. - const duplicateTestTitle = currentModuleInfo.tests.find(t => t.arguments[0].value === title); + const duplicateTestTitle = currentModuleInfo.tests.find( + (t) => t.arguments[0].value === title, + ); if (duplicateTestTitle) { context.report({ node: node.arguments[0], messageId: "duplicateTest", data: { - line: duplicateTestTitle.arguments[0].loc.start.line - } + line: duplicateTestTitle.arguments[0].loc.start + .line, + }, }); } @@ -97,29 +118,39 @@ module.exports = { if (utils.isModule(node.callee)) { const title = node.arguments[0].value; const currentModuleNode = modulesStack[modulesStack.length - 1]; - const currentModuleInfo = mapModuleNodeToInfo.get(currentModuleNode); + const currentModuleInfo = + mapModuleNodeToInfo.get(currentModuleNode); // Check if we have seen the same title in a sibling module. - const duplicateModuleTitle = currentModuleInfo.modules.find(moduleNode => moduleNode.arguments[0].value === title); + const duplicateModuleTitle = currentModuleInfo.modules.find( + (moduleNode) => moduleNode.arguments[0].value === title, + ); if (duplicateModuleTitle) { context.report({ node: node.arguments[0], messageId: "duplicateModule", data: { - line: duplicateModuleTitle.loc.start.line - } + line: duplicateModuleTitle.loc.start.line, + }, }); } // Check if we have seen the same title in any ancestor modules. - const duplicateAncestorModuleTitle = modulesStack.filter(moduleNode => moduleNode !== TOP_LEVEL_MODULE_NODE).find(moduleNode => moduleNode.arguments[0].value === title); + const duplicateAncestorModuleTitle = modulesStack + .filter( + (moduleNode) => moduleNode !== TOP_LEVEL_MODULE_NODE, + ) + .find( + (moduleNode) => moduleNode.arguments[0].value === title, + ); if (duplicateAncestorModuleTitle) { context.report({ node: node.arguments[0], messageId: "duplicateModuleAncestor", data: { - line: duplicateAncestorModuleTitle.arguments[0].loc.start.line - } + line: duplicateAncestorModuleTitle.arguments[0].loc + .start.line, + }, }); } @@ -128,7 +159,7 @@ module.exports = { mapModuleNodeToInfo.set(node, { modules: [], tests: [], - hasNestedTests: false + hasNestedTests: false, }); currentModuleInfo.modules.push(node); // Add to parent module's list of children modules. } @@ -139,7 +170,7 @@ module.exports = { //---------------------------------------------------------------------- return { - "CallExpression": function (node) { + CallExpression: function (node) { if (!isFirstArgLiteral(node)) { return; } @@ -149,14 +180,18 @@ module.exports = { }, "CallExpression:exit": function (node) { - if (modulesStack.length > 0 && modulesStack[modulesStack.length - 1] === node) { + if ( + modulesStack.length > 0 && + modulesStack[modulesStack.length - 1] === node + ) { // Exiting a module so pop it from the stack. modulesStack.pop(); // Record if we saw any nested tests in this module. - mapModuleNodeToInfo.get(node).hasNestedTests = moduleHasNestedTests(node); + mapModuleNodeToInfo.get(node).hasNestedTests = + moduleHasNestedTests(node); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-init.js b/lib/rules/no-init.js index 1eddae9d..8bad428c 100644 --- a/lib/rules/no-init.js +++ b/lib/rules/no-init.js @@ -17,12 +17,12 @@ module.exports = { docs: { description: "disallow use of QUnit.init", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-init.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-init.md", }, messages: { - noInit: "Do not use QUnit.init()." + noInit: "Do not use QUnit.init().", }, - schema: [] + schema: [], }, create: function (context) { @@ -31,12 +31,13 @@ module.exports = { //-------------------------------------------------------------------------- return { - "CallExpression[callee.object.name='QUnit'][callee.property.name='init']": function (node) { - context.report({ - node: node, - messageId: "noInit" - }); - } + "CallExpression[callee.object.name='QUnit'][callee.property.name='init']": + function (node) { + context.report({ + node: node, + messageId: "noInit", + }); + }, }; - } + }, }; diff --git a/lib/rules/no-jsdump.js b/lib/rules/no-jsdump.js index bf79a440..151c8b51 100644 --- a/lib/rules/no-jsdump.js +++ b/lib/rules/no-jsdump.js @@ -15,12 +15,12 @@ module.exports = { docs: { description: "disallow use of QUnit.jsDump", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-jsdump.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-jsdump.md", }, messages: { - noJsDump: "Use QUnit.dump() instead of QUnit.jsDump()." + noJsDump: "Use QUnit.dump() instead of QUnit.jsDump().", }, - schema: [] + schema: [], }, create: function (context) { @@ -29,12 +29,13 @@ module.exports = { //-------------------------------------------------------------------------- return { - "CallExpression[callee.object.name='QUnit'][callee.property.name='jsDump']": function (node) { - context.report({ - node: node, - messageId: "noJsDump" - }); - } + "CallExpression[callee.object.name='QUnit'][callee.property.name='jsDump']": + function (node) { + context.report({ + node: node, + messageId: "noJsDump", + }); + }, }; - } + }, }; diff --git a/lib/rules/no-loose-assertions.js b/lib/rules/no-loose-assertions.js index 0aae403c..d08d5a91 100644 --- a/lib/rules/no-loose-assertions.js +++ b/lib/rules/no-loose-assertions.js @@ -19,22 +19,34 @@ const LOCAL_ERROR_MESSAGE_ID = "unexpectedLocalLooseAssertion"; const DEFAULT_ASSERTIONS = ["equal", "ok", "notEqual", "notOk"]; const ERROR_MESSAGE_CONFIG = { - equal: { unexpectedGlobalAssertionMessageId: GLOBAL_ERROR_MESSAGE_ID, - unexpectedLocalAssertionMessageId: LOCAL_ERROR_MESSAGE_ID }, - ok: { unexpectedGlobalAssertionMessageId: GLOBAL_ERROR_MESSAGE_ID, - unexpectedLocalAssertionMessageId: LOCAL_ERROR_MESSAGE_ID }, - notEqual: { unexpectedGlobalAssertionMessageId: GLOBAL_ERROR_MESSAGE_ID, - unexpectedLocalAssertionMessageId: LOCAL_ERROR_MESSAGE_ID }, - notOk: { unexpectedGlobalAssertionMessageId: GLOBAL_ERROR_MESSAGE_ID, - unexpectedLocalAssertionMessageId: LOCAL_ERROR_MESSAGE_ID } + equal: { + unexpectedGlobalAssertionMessageId: GLOBAL_ERROR_MESSAGE_ID, + unexpectedLocalAssertionMessageId: LOCAL_ERROR_MESSAGE_ID, + }, + ok: { + unexpectedGlobalAssertionMessageId: GLOBAL_ERROR_MESSAGE_ID, + unexpectedLocalAssertionMessageId: LOCAL_ERROR_MESSAGE_ID, + }, + notEqual: { + unexpectedGlobalAssertionMessageId: GLOBAL_ERROR_MESSAGE_ID, + unexpectedLocalAssertionMessageId: LOCAL_ERROR_MESSAGE_ID, + }, + notOk: { + unexpectedGlobalAssertionMessageId: GLOBAL_ERROR_MESSAGE_ID, + unexpectedLocalAssertionMessageId: LOCAL_ERROR_MESSAGE_ID, + }, }; function buildErrorMessage(disallowed) { - const globalMessage = `Unexpected {{assertion}}. Use ${disallowed.join(", ")}.`; - const localMessage = `Unexpected {{assertVar}}.{{assertion}}. Use ${disallowed.map((ass) => `{{assertVar}}.${ass}`).join(", ")}.`; + const globalMessage = `Unexpected {{assertion}}. Use ${disallowed.join( + ", ", + )}.`; + const localMessage = `Unexpected {{assertVar}}.{{assertion}}. Use ${disallowed + .map((ass) => `{{assertVar}}.${ass}`) + .join(", ")}.`; return { unexpectedGlobalAssertionMessage: globalMessage, - unexpectedLocalAssertionMessage: localMessage + unexpectedLocalAssertionMessage: localMessage, }; } @@ -56,7 +68,9 @@ function parseOptions(options) { continue; } assertions.push(assertion.disallowed); - errorMessageConfig[assertion.disallowed] = buildErrorMessage(assertion.recommended); + errorMessageConfig[assertion.disallowed] = buildErrorMessage( + assertion.recommended, + ); } } return [assertions, errorMessageConfig]; @@ -69,46 +83,56 @@ module.exports = { meta: { type: "suggestion", docs: { - description: "disallow the use of assert.equal/assert.ok/assert.notEqual/assert.notOk", + description: + "disallow the use of assert.equal/assert.ok/assert.notEqual/assert.notOk", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-loose-assertions.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-loose-assertions.md", }, messages: { - [GLOBAL_ERROR_MESSAGE_ID]: "Unexpected {{assertion}}. Use strictEqual, notStrictEqual, deepEqual, or propEqual.", - [LOCAL_ERROR_MESSAGE_ID]: "Unexpected {{assertVar}}.{{assertion}}. Use {{assertVar}}.strictEqual, {{assertVar}}.notStrictEqual, {{assertVar}}.deepEqual, or {{assertVar}}.propEqual." + [GLOBAL_ERROR_MESSAGE_ID]: + "Unexpected {{assertion}}. Use strictEqual, notStrictEqual, deepEqual, or propEqual.", + [LOCAL_ERROR_MESSAGE_ID]: + "Unexpected {{assertVar}}.{{assertion}}. Use {{assertVar}}.strictEqual, {{assertVar}}.notStrictEqual, {{assertVar}}.deepEqual, or {{assertVar}}.propEqual.", }, - schema: [{ - type: "array", - minItems: 1, - items: { - oneOf: [{ - type: "object", - properties: { - disallowed: { + schema: [ + { + type: "array", + minItems: 1, + items: { + oneOf: [ + { + type: "object", + properties: { + disallowed: { + type: "string", + enum: DEFAULT_ASSERTIONS, + }, + recommended: { + type: "array", + items: { + type: "string", + minItems: 1, + }, + }, + }, + required: ["disallowed", "recommended"], + additionalProperties: false, + }, + { type: "string", - enum: DEFAULT_ASSERTIONS + enum: DEFAULT_ASSERTIONS, }, - recommended: { - type: "array", - items: { - type: "string", - minItems: 1 - } - } - }, - required: ["disallowed", "recommended"], - additionalProperties: false - }, { - type: "string", - enum: DEFAULT_ASSERTIONS - }] + ], + }, + uniqueItems: true, }, - uniqueItems: true - }] + ], }, create: function (context) { const [assertions, errorMessageConfig] = parseOptions(context.options); - return utils.createAssertionCheck(assertions, errorMessageConfig).call(this, context); - } + return utils + .createAssertionCheck(assertions, errorMessageConfig) + .call(this, context); + }, }; diff --git a/lib/rules/no-negated-ok.js b/lib/rules/no-negated-ok.js index c729d20b..491a4d79 100644 --- a/lib/rules/no-negated-ok.js +++ b/lib/rules/no-negated-ok.js @@ -8,10 +8,10 @@ const assert = require("node:assert"), utils = require("../utils"); const ASSERTION_OPPOSITES = { - "false": "true", - "notOk": "ok", - "ok": "notOk", - "true": "false" + false: "true", + notOk: "ok", + ok: "notOk", + true: "false", }; //------------------------------------------------------------------------------ @@ -25,13 +25,13 @@ module.exports = { docs: { description: "disallow negation in assert.ok/assert.notOk", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-negated-ok.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-negated-ok.md", }, fixable: "code", messages: { - noNegationInOk: "Unexpected negation in {{callee}}() assertion." + noNegationInOk: "Unexpected negation in {{callee}}() assertion.", }, - schema: [] + schema: [], }, create: function (context) { @@ -41,7 +41,10 @@ module.exports = { // Declare a stack in case of nested test cases (not currently supported // in QUnit). const asyncStateStack = [], - ASSERTIONS_TO_CHECK = new Set([...POSITIVE_ASSERTIONS, ...NEGATIVE_ASSERTIONS]), + ASSERTIONS_TO_CHECK = new Set([ + ...POSITIVE_ASSERTIONS, + ...NEGATIVE_ASSERTIONS, + ]), sourceCode = context.getSourceCode(); function getAssertVar() { @@ -49,7 +52,9 @@ module.exports = { /* istanbul ignore else: correctly returns null */ if (asyncStateStack.length > 0) { - result = asyncStateStack[asyncStateStack.length - 1].assertContextVar; + result = + asyncStateStack[asyncStateStack.length - 1] + .assertContextVar; } return result; @@ -61,7 +66,8 @@ module.exports = { let result = false; if (calleeNode.type === "MemberExpression") { - result = calleeNode.object && + result = + calleeNode.object && calleeNode.object.type === "Identifier" && calleeNode.object.name === getAssertVar() && calleeNode.property && @@ -81,7 +87,11 @@ module.exports = { let negationDepth = 0, node = argNode; - while (node && node.type === "UnaryExpression" && node.operator === "!") { + while ( + node && + node.type === "UnaryExpression" && + node.operator === "!" + ) { ++negationDepth; node = node.argument; } @@ -92,7 +102,11 @@ module.exports = { function unwrapNegation(argNode) { let node = argNode; - while (node && node.type === "UnaryExpression" && node.operator === "!") { + while ( + node && + node.type === "UnaryExpression" && + node.operator === "!" + ) { node = node.argument; } @@ -109,31 +123,47 @@ module.exports = { node: callExprNode, messageId: "noNegationInOk", data: { - callee: sourceCode.getText(callExprNode.callee) + callee: sourceCode.getText(callExprNode.callee), }, fix(fixer) { // Conversions: // * assert.notOk(!foo) => assert.ok(foo) // * assert.ok(!foo) => assert.notOk(foo) - const assertionVariableName = callExprNode.callee.object.name; - const oppositeAssertionFunctionName = ASSERTION_OPPOSITES[callExprNode.callee.property.name]; - const newArgsTextArray = [unwrapNegation(firstArgNode), ...callExprNode.arguments.slice(1)].map(arg => sourceCode.getText(arg)); - const newArgsTextJoined = newArgsTextArray.join(", "); - return fixer.replaceText(callExprNode, `${assertionVariableName}.${oppositeAssertionFunctionName}(${newArgsTextJoined})`); - } + const assertionVariableName = + callExprNode.callee.object.name; + const oppositeAssertionFunctionName = + ASSERTION_OPPOSITES[ + callExprNode.callee.property.name + ]; + const newArgsTextArray = [ + unwrapNegation(firstArgNode), + ...callExprNode.arguments.slice(1), + ].map((arg) => sourceCode.getText(arg)); + const newArgsTextJoined = + newArgsTextArray.join(", "); + return fixer.replaceText( + callExprNode, + `${assertionVariableName}.${oppositeAssertionFunctionName}(${newArgsTextJoined})`, + ); + }, }); } } } return { - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isTest(node.callee)) { asyncStateStack.push({ - assertContextVar: utils.getAssertContextNameForTest(node.arguments) + assertContextVar: utils.getAssertContextNameForTest( + node.arguments, + ), }); - } else if (isAssertion(node.callee) && isOkOrNotOk(node.callee)) { + } else if ( + isAssertion(node.callee) && + isOkOrNotOk(node.callee) + ) { checkForNegation(node); } }, @@ -142,7 +172,7 @@ module.exports = { if (utils.isTest(node.callee)) { asyncStateStack.pop(); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-nested-tests.js b/lib/rules/no-nested-tests.js index 2f483061..63087a28 100644 --- a/lib/rules/no-nested-tests.js +++ b/lib/rules/no-nested-tests.js @@ -21,32 +21,36 @@ module.exports = { docs: { description: "disallow nested QUnit.test() calls", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-nested-tests.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-nested-tests.md", }, messages: { - noNestedTests: "Using QUnit.test inside of another QUnit.test is not allowed." + noNestedTests: + "Using QUnit.test inside of another QUnit.test is not allowed.", }, - schema: [] + schema: [], }, create: function (context) { return { - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isTest(node.callee)) { let currentNode = node; while (currentNode.parent) { const { parent } = currentNode; - if (parent.type === "CallExpression" && utils.isTest(parent.callee)) { + if ( + parent.type === "CallExpression" && + utils.isTest(parent.callee) + ) { context.report({ node, - messageId: "noNestedTests" + messageId: "noNestedTests", }); return; } currentNode = parent; } } - } + }, }; - } + }, }; diff --git a/lib/rules/no-ok-equality.js b/lib/rules/no-ok-equality.js index c9c93fc9..bad7150b 100644 --- a/lib/rules/no-ok-equality.js +++ b/lib/rules/no-ok-equality.js @@ -15,13 +15,15 @@ module.exports = { meta: { type: "suggestion", docs: { - description: "disallow equality comparisons in assert.ok/assert.notOk", + description: + "disallow equality comparisons in assert.ok/assert.notOk", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-ok-equality.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-ok-equality.md", }, fixable: "code", messages: { - noEqualityCheckInOk: "Unexpected equality comparison in {{assertion}} call. Use {{suggestion}}({{a}}, {{b}}) instead." + noEqualityCheckInOk: + "Unexpected equality comparison in {{assertion}} call. Use {{suggestion}}({{a}}, {{b}}) instead.", }, schema: [ { @@ -29,13 +31,14 @@ module.exports = { properties: { allowGlobal: { type: "boolean", - description: "Whether the rule should check global assertions.", - default: true - } + description: + "Whether the rule should check global assertions.", + default: true, + }, }, - additionalProperties: false - } - ] + additionalProperties: false, + }, + ], }, create: function (context) { @@ -43,7 +46,7 @@ module.exports = { // in QUnit). const asyncStateStack = [], DEFAULT_OPTIONS = { - allowGlobal: true + allowGlobal: true, }, options = context.options[0] || DEFAULT_OPTIONS, sourceCode = context.getSourceCode(); @@ -59,9 +62,12 @@ module.exports = { function isOk(calleeNode) { const assertContextVar = getAssertContextVar(); - const isOk = calleeNode.type === "Identifier" && POSITIVE_ASSERTIONS.has(calleeNode.name); + const isOk = + calleeNode.type === "Identifier" && + POSITIVE_ASSERTIONS.has(calleeNode.name); - const isAssertOk = calleeNode.type === "MemberExpression" && + const isAssertOk = + calleeNode.type === "MemberExpression" && calleeNode.object.type === "Identifier" && calleeNode.object.name === assertContextVar && calleeNode.property.type === "Identifier" && @@ -77,9 +83,12 @@ module.exports = { function isNotOk(calleeNode) { const assertContextVar = getAssertContextVar(); - const isNotOk = calleeNode.type === "Identifier" && NEGATIVE_ASSERTIONS.has(calleeNode.name); + const isNotOk = + calleeNode.type === "Identifier" && + NEGATIVE_ASSERTIONS.has(calleeNode.name); - const isAssertNotOk = calleeNode.type === "MemberExpression" && + const isAssertNotOk = + calleeNode.type === "MemberExpression" && calleeNode.object.type === "Identifier" && calleeNode.object.name === assertContextVar && calleeNode.property.type === "Identifier" && @@ -97,18 +106,24 @@ module.exports = { } function isEqual(arg) { - return arg.type === "BinaryExpression" && - ["===", "==", "!==", "!="].includes(arg.operator); + return ( + arg.type === "BinaryExpression" && + ["===", "==", "!==", "!="].includes(arg.operator) + ); } function isStrict(arg) { - return arg.type === "BinaryExpression" && - ["===", "!=="].includes(arg.operator); + return ( + arg.type === "BinaryExpression" && + ["===", "!=="].includes(arg.operator) + ); } function isNegative(arg) { - return arg.type === "BinaryExpression" && - ["!==", "!="].includes(arg.operator); + return ( + arg.type === "BinaryExpression" && + ["!==", "!="].includes(arg.operator) + ); } function getSuggestedAssertion(criteria) { @@ -116,7 +131,9 @@ module.exports = { let assertMethod; if (criteria.strict) { - assertMethod = criteria.negative ? "notStrictEqual" : "strictEqual"; + assertMethod = criteria.negative + ? "notStrictEqual" + : "strictEqual"; } else { assertMethod = criteria.negative ? "notEqual" : "equal"; } @@ -138,7 +155,7 @@ module.exports = { const suggestion = getSuggestedAssertion({ strict: isArgStrictEqual, - negative: isArgNegative !== isCalleeNegative + negative: isArgNegative !== isCalleeNegative, }); const a = sourceCode.getText(firstArg.left); @@ -152,27 +169,41 @@ module.exports = { assertion: sourceCode.getText(node.callee), suggestion, a, - b + b, }, fix(fixer) { const newArgs = [ - a, b, ...args.slice(1).map(arg => sourceCode.getText(arg)) + a, + b, + ...args + .slice(1) + .map((arg) => sourceCode.getText(arg)), ]; - return fixer.replaceText(node, `${suggestion}(${newArgs.join(", ")})`); - } + return fixer.replaceText( + node, + `${suggestion}(${newArgs.join(", ")})`, + ); + }, }); } } } return { - "CallExpression": function (node) { + CallExpression: function (node) { if (asyncStateStack.length > 0 && isOkOrNotOk(node.callee)) { const isGlobal = node.callee.type === "Identifier"; - checkArguments(node.arguments, isNotOk(node.callee), isGlobal, node); + checkArguments( + node.arguments, + isNotOk(node.callee), + isGlobal, + node, + ); } else if (utils.isTest(node.callee)) { asyncStateStack.push({ - assertContextVar: utils.getAssertContextNameForTest(node.arguments) + assertContextVar: utils.getAssertContextNameForTest( + node.arguments, + ), }); } }, @@ -181,7 +212,7 @@ module.exports = { if (utils.isTest(node.callee)) { asyncStateStack.pop(); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-only.js b/lib/rules/no-only.js index 788b91cf..7f518b98 100644 --- a/lib/rules/no-only.js +++ b/lib/rules/no-only.js @@ -21,24 +21,24 @@ module.exports = { docs: { description: "disallow QUnit.only", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-only.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-only.md", }, messages: { - noQUnitOnly: "Unexpected only() call." + noQUnitOnly: "Unexpected only() call.", }, - schema: [] + schema: [], }, create: function (context) { return { - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isOnly(node.callee)) { context.report({ node: node, - messageId: "noQUnitOnly" + messageId: "noQUnitOnly", }); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-qunit-push.js b/lib/rules/no-qunit-push.js index 0eb2387d..5d55b8b4 100644 --- a/lib/rules/no-qunit-push.js +++ b/lib/rules/no-qunit-push.js @@ -15,12 +15,12 @@ module.exports = { docs: { description: "disallow QUnit.push", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-qunit-push.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-qunit-push.md", }, messages: { - noQUnitPush: "Do not use QUnit.push()." + noQUnitPush: "Do not use QUnit.push().", }, - schema: [] + schema: [], }, create: function (context) { @@ -29,12 +29,13 @@ module.exports = { //-------------------------------------------------------------------------- return { - "CallExpression[callee.object.name='QUnit'][callee.property.name='push']": function (node) { - context.report({ - node: node, - messageId: "noQUnitPush" - }); - } + "CallExpression[callee.object.name='QUnit'][callee.property.name='push']": + function (node) { + context.report({ + node: node, + messageId: "noQUnitPush", + }); + }, }; - } + }, }; diff --git a/lib/rules/no-qunit-start-in-tests.js b/lib/rules/no-qunit-start-in-tests.js index b2f60f18..25e5d475 100644 --- a/lib/rules/no-qunit-start-in-tests.js +++ b/lib/rules/no-qunit-start-in-tests.js @@ -22,13 +22,14 @@ module.exports = { description: "disallow QUnit.start() within tests or test hooks", category: "Possible Errors", recommended: false, - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-qunit-start-in-tests.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-qunit-start-in-tests.md", }, fixable: null, messages: { - noQUnitStartInTests: "Do not use QUnit.start() inside a {{context}}." + noQUnitStartInTests: + "Do not use QUnit.start() inside a {{context}}.", }, - schema: [] + schema: [], }, create: function (context) { @@ -39,16 +40,20 @@ module.exports = { //---------------------------------------------------------------------- function isQUnitStart(calleeNode) { - return calleeNode.type === "MemberExpression" && - utils.isStart(calleeNode); + return ( + calleeNode.type === "MemberExpression" && + utils.isStart(calleeNode) + ); } function isInModule(propertyNode) { - return propertyNode && - propertyNode.parent && // ObjectExpression - propertyNode.parent.parent && // CallExpression? + return ( + propertyNode && + propertyNode.parent && // ObjectExpression + propertyNode.parent.parent && // CallExpression? propertyNode.parent.parent.type === "CallExpression" && - utils.isModule(propertyNode.parent.parent.callee); + utils.isModule(propertyNode.parent.parent.callee) + ); } //---------------------------------------------------------------------- @@ -56,24 +61,31 @@ module.exports = { //---------------------------------------------------------------------- return { - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isTest(node.callee)) { contextStack.push("test"); - } else if (contextStack.length > 0 && isQUnitStart(node.callee)) { - const currentContext = contextStack[contextStack.length - 1]; + } else if ( + contextStack.length > 0 && + isQUnitStart(node.callee) + ) { + const currentContext = + contextStack[contextStack.length - 1]; context.report({ node: node, messageId: "noQUnitStartInTests", data: { - context: currentContext - } + context: currentContext, + }, }); } }, - "Property": function (node) { - if (utils.isModuleHookPropertyKey(node.key) && isInModule(node)) { + Property: function (node) { + if ( + utils.isModuleHookPropertyKey(node.key) && + isInModule(node) + ) { contextStack.push(`${node.key.name} hook`); } }, @@ -85,10 +97,13 @@ module.exports = { }, "Property:exit": function (node) { - if (utils.isModuleHookPropertyKey(node.key) && isInModule(node)) { + if ( + utils.isModuleHookPropertyKey(node.key) && + isInModule(node) + ) { contextStack.pop(); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-qunit-stop.js b/lib/rules/no-qunit-stop.js index ad14f162..c5f963f6 100644 --- a/lib/rules/no-qunit-stop.js +++ b/lib/rules/no-qunit-stop.js @@ -21,19 +21,21 @@ module.exports = { docs: { description: "disallow QUnit.stop", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-qunit-stop.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-qunit-stop.md", }, messages: { - noQUnitStop: "Use assert.async() instead of QUnit.stop()." + noQUnitStop: "Use assert.async() instead of QUnit.stop().", }, - schema: [] + schema: [], }, create: function (context) { function isQUnitStop(calleeNode) { - return calleeNode && + return ( + calleeNode && calleeNode.type === "MemberExpression" && - utils.isStop(calleeNode); + utils.isStop(calleeNode) + ); } //-------------------------------------------------------------------------- @@ -41,14 +43,14 @@ module.exports = { //-------------------------------------------------------------------------- return { - "CallExpression": function (node) { + CallExpression: function (node) { if (isQUnitStop(node.callee)) { context.report({ node: node, - messageId: "noQUnitStop" + messageId: "noQUnitStop", }); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-reassign-log-callbacks.js b/lib/rules/no-reassign-log-callbacks.js index 0a5b05ea..6f8ebdd1 100644 --- a/lib/rules/no-reassign-log-callbacks.js +++ b/lib/rules/no-reassign-log-callbacks.js @@ -17,12 +17,12 @@ module.exports = { docs: { description: "disallow overwriting of QUnit logging callbacks", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-reassign-log-callbacks.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-reassign-log-callbacks.md", }, messages: { - noReassignLogCallbacks: "Do not reassign QUnit log callbacks." + noReassignLogCallbacks: "Do not reassign QUnit log callbacks.", }, - schema: [] + schema: [], }, create: function (context) { @@ -33,7 +33,7 @@ module.exports = { "moduleDone", "moduleStart", "testDone", - "testStart" + "testStart", ]; //-------------------------------------------------------------------------- @@ -43,14 +43,16 @@ module.exports = { const visitors = {}; for (const callbackName of LOG_CALLBACKS) { - visitors[`AssignmentExpression[left.object.name='QUnit'][left.property.name='${callbackName}']`] = function (node) { + visitors[ + `AssignmentExpression[left.object.name='QUnit'][left.property.name='${callbackName}']` + ] = function (node) { context.report({ node: node, - messageId: "noReassignLogCallbacks" + messageId: "noReassignLogCallbacks", }); }; } return visitors; - } + }, }; diff --git a/lib/rules/no-reset.js b/lib/rules/no-reset.js index 7b08e50d..73572ace 100644 --- a/lib/rules/no-reset.js +++ b/lib/rules/no-reset.js @@ -17,12 +17,12 @@ module.exports = { docs: { description: "disallow QUnit.reset", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-reset.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-reset.md", }, messages: { - noReset: "Do not use QUnit.reset()." + noReset: "Do not use QUnit.reset().", }, - schema: [] + schema: [], }, create: function (context) { @@ -31,12 +31,13 @@ module.exports = { //-------------------------------------------------------------------------- return { - "CallExpression[callee.object.name='QUnit'][callee.property.name='reset']": function (node) { - context.report({ - node: node, - messageId: "noReset" - }); - } + "CallExpression[callee.object.name='QUnit'][callee.property.name='reset']": + function (node) { + context.report({ + node: node, + messageId: "noReset", + }); + }, }; - } + }, }; diff --git a/lib/rules/no-setup-teardown.js b/lib/rules/no-setup-teardown.js index 9572395e..41ed89f1 100644 --- a/lib/rules/no-setup-teardown.js +++ b/lib/rules/no-setup-teardown.js @@ -19,19 +19,19 @@ module.exports = { docs: { description: "disallow setup/teardown module hooks", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-setup-teardown.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-setup-teardown.md", }, fixable: "code", messages: { - noSetupTeardown: "Use {{preferred}} instead of {{forbidden}}." + noSetupTeardown: "Use {{preferred}} instead of {{forbidden}}.", }, - schema: [] + schema: [], }, create: function (context) { const replacements = { setup: "beforeEach", - teardown: "afterEach" + teardown: "afterEach", }; function checkModuleHook(propertyNode) { @@ -41,29 +41,37 @@ module.exports = { messageId: "noSetupTeardown", data: { forbidden: propertyNode.key.name, - preferred: replacements[propertyNode.key.name] + preferred: replacements[propertyNode.key.name], }, fix(fixer) { - return fixer.replaceText(propertyNode.key, replacements[propertyNode.key.name]); - } + return fixer.replaceText( + propertyNode.key, + replacements[propertyNode.key.name], + ); + }, }); } } function isInModule(propertyNode) { - return propertyNode && - propertyNode.parent && // ObjectExpression - propertyNode.parent.parent && // CallExpression? + return ( + propertyNode && + propertyNode.parent && // ObjectExpression + propertyNode.parent.parent && // CallExpression? propertyNode.parent.parent.type === "CallExpression" && - utils.isModule(propertyNode.parent.parent.callee); + utils.isModule(propertyNode.parent.parent.callee) + ); } return { - "Property": function (node) { - if (utils.isModuleHookPropertyKey(node.key) && isInModule(node)) { + Property: function (node) { + if ( + utils.isModuleHookPropertyKey(node.key) && + isInModule(node) + ) { checkModuleHook(node); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-skip.js b/lib/rules/no-skip.js index 127b41b8..f4622210 100644 --- a/lib/rules/no-skip.js +++ b/lib/rules/no-skip.js @@ -22,24 +22,24 @@ module.exports = { description: "disallow QUnit.skip", category: "Best Practices", recommended: false, - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-skip.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-skip.md", }, messages: { - noQUnitSkip: "Unexpected skip() call." + noQUnitSkip: "Unexpected skip() call.", }, - schema: [] + schema: [], }, create: function (context) { return { - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isSkip(node.callee)) { context.report({ node: node, - messageId: "noQUnitSkip" + messageId: "noQUnitSkip", }); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-test-expect-argument.js b/lib/rules/no-test-expect-argument.js index 49395d42..0e4cdf3f 100644 --- a/lib/rules/no-test-expect-argument.js +++ b/lib/rules/no-test-expect-argument.js @@ -21,12 +21,12 @@ module.exports = { docs: { description: "disallow the expect argument in QUnit.test", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-test-expect-argument.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-test-expect-argument.md", }, messages: { - noExpectArgument: "Do not use expect argument in {{callee}}()." + noExpectArgument: "Do not use expect argument in {{callee}}().", }, - schema: [] + schema: [], }, create: function (context) { @@ -39,11 +39,11 @@ module.exports = { node: node, messageId: "noExpectArgument", data: { - callee: sourceCode.getText(node.callee) - } + callee: sourceCode.getText(node.callee), + }, }); } - } + }, }; - } + }, }; diff --git a/lib/rules/no-throws-string.js b/lib/rules/no-throws-string.js index 587f5a49..652a1435 100644 --- a/lib/rules/no-throws-string.js +++ b/lib/rules/no-throws-string.js @@ -26,7 +26,8 @@ function isThrows(calleeNode, assertVar) { /* istanbul ignore else: correctly returns false */ if (calleeNode.type === "MemberExpression") { - result = calleeNode.object.type === "Identifier" && + result = + calleeNode.object.type === "Identifier" && calleeNode.object.name === assertVar && calleeNode.property.type === "Identifier" && ["throws", "raises"].includes(calleeNode.property.name); @@ -46,14 +47,15 @@ module.exports = { meta: { type: "suggestion", docs: { - description: "disallow assert.throws() with block, string, and message args", + description: + "disallow assert.throws() with block, string, and message args", category: "Possible errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-throws-string.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-throws-string.md", }, messages: { - noThrowsWithString: "Do not use {{callee}}(block, string, string)." + noThrowsWithString: "Do not use {{callee}}(block, string, string).", }, - schema: [] + schema: [], }, create: function (context) { @@ -64,24 +66,33 @@ module.exports = { const args = callExprNode.arguments, argCount = args.length; - if (argCount > 2 && args[1].type === "Literal" && typeof args[1].value === "string") { + if ( + argCount > 2 && + args[1].type === "Literal" && + typeof args[1].value === "string" + ) { context.report({ node: callExprNode, messageId: "noThrowsWithString", data: { - callee: sourceCode.getText(callExprNode.callee) - } + callee: sourceCode.getText(callExprNode.callee), + }, }); } } return { - "CallExpression": function (node) { + CallExpression: function (node) { if (utils.isTest(node.callee)) { testStack.push({ - assertVar: utils.getAssertContextNameForTest(node.arguments) + assertVar: utils.getAssertContextNameForTest( + node.arguments, + ), }); - } else if (testStack.length > 0 && isThrows(node.callee, getAssertVar(testStack))) { + } else if ( + testStack.length > 0 && + isThrows(node.callee, getAssertVar(testStack)) + ) { checkAndReport(node); } }, @@ -90,8 +101,7 @@ module.exports = { if (utils.isTest(node.callee)) { testStack.pop(); } - } + }, }; - } - + }, }; diff --git a/lib/rules/require-expect.js b/lib/rules/require-expect.js index bb249952..a9687da4 100644 --- a/lib/rules/require-expect.js +++ b/lib/rules/require-expect.js @@ -18,18 +18,19 @@ module.exports = { docs: { description: "enforce that `expect` is called", category: "Best Practices", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/require-expect.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/require-expect.md", }, messages: { expectRequired: "Test is missing `{{expect}}()` call.", expectForbidden: "Unexpected use of `{{expect}}()` call.", - expectRequiredComplexTest: "Should use `{{expect}}()` when using assertions outside of the top-level test callback." + expectRequiredComplexTest: + "Should use `{{expect}}()` when using assertions outside of the top-level test callback.", }, schema: [ { - "enum": ["always", "except-simple", "never", "never-except-zero"] - } - ] + enum: ["always", "except-simple", "never", "never-except-zero"], + }, + ], }, create: function (context) { @@ -40,10 +41,12 @@ module.exports = { } function isAssertExpectCall(callee) { - return callee.object && - callee.object.type === "Identifier" && - callee.object.name === currentTest.assertName && - callee.property.name === "expect"; + return ( + callee.object && + callee.object.type === "Identifier" && + callee.object.name === currentTest.assertName && + callee.property.name === "expect" + ); } function isExpectCall(callee) { @@ -51,10 +54,13 @@ module.exports = { } function isNonZeroExpectCall(node) { - return isExpectCall(node.callee) && !( - node.arguments.length === 1 && - node.arguments[0].type === "Literal" && - node.arguments[0].raw === "0" + return ( + isExpectCall(node.callee) && + !( + node.arguments.length === 1 && + node.arguments[0].type === "Literal" && + node.arguments[0].raw === "0" + ) ); } @@ -63,7 +69,10 @@ module.exports = { } function isUsingAssertInNestedBlock(node) { - return currentTest.blockDepth > 1 && utils.isAssertion(node.callee, currentTest.assertName); + return ( + currentTest.blockDepth > 1 && + utils.isAssertion(node.callee, currentTest.assertName) + ); } function isPassingAssertAsArgument(node) { @@ -80,8 +89,11 @@ module.exports = { } function isViolatingExceptSimpleRule(node) { - return !currentTest.isExpectUsed && - (isUsingAssertInNestedBlock(node) || isPassingAssertAsArgument(node)); + return ( + !currentTest.isExpectUsed && + (isUsingAssertInNestedBlock(node) || + isPassingAssertAsArgument(node)) + ); } function captureTestContext(node) { @@ -90,7 +102,7 @@ module.exports = { node: node, blockDepth: 0, isExpectUsed: false, - didReport: false + didReport: false, }; } @@ -100,12 +112,14 @@ module.exports = { function assertionMessageData() { return { - expect: currentTest.assertName ? `${currentTest.assertName}.expect` : "expect" + expect: currentTest.assertName + ? `${currentTest.assertName}.expect` + : "expect", }; } const ExceptSimpleStrategy = { - "CallExpression": function (node) { + CallExpression: function (node) { if (currentTest && !currentTest.didReport) { if (isTopLevelExpectCall(node.callee)) { currentTest.isExpectUsed = true; @@ -113,7 +127,7 @@ module.exports = { context.report({ node: currentTest.node, messageId: "expectRequiredComplexTest", - data: assertionMessageData() + data: assertionMessageData(), }); currentTest.didReport = true; } @@ -128,21 +142,23 @@ module.exports = { } }, - "BlockStatement, ArrowFunctionExpression[body.type!='BlockStatement']": function () { - if (currentTest) { - currentTest.blockDepth++; - } - }, + "BlockStatement, ArrowFunctionExpression[body.type!='BlockStatement']": + function () { + if (currentTest) { + currentTest.blockDepth++; + } + }, - "BlockStatement, ArrowFunctionExpression[body.type!='BlockStatement']:exit": function () { - if (currentTest) { - currentTest.blockDepth--; - } - } + "BlockStatement, ArrowFunctionExpression[body.type!='BlockStatement']:exit": + function () { + if (currentTest) { + currentTest.blockDepth--; + } + }, }; const AlwaysStrategy = { - "CallExpression": function (node) { + CallExpression: function (node) { if (currentTest && isExpectCall(node.callee)) { currentTest.isExpectUsed = true; } else if (utils.isTest(node.callee)) { @@ -156,17 +172,17 @@ module.exports = { context.report({ node: currentTest.node, messageId: "expectRequired", - data: assertionMessageData() + data: assertionMessageData(), }); } releaseTestContext(); } - } + }, }; const NeverStrategy = { - "CallExpression": function (node) { + CallExpression: function (node) { if (currentTest && isExpectCall(node.callee)) { currentTest.isExpectUsed = true; } else if (utils.isTest(node.callee)) { @@ -179,16 +195,16 @@ module.exports = { context.report({ node: currentTest.node, messageId: "expectForbidden", - data: assertionMessageData() + data: assertionMessageData(), }); } releaseTestContext(); } - } + }, }; const NeverExceptZeroStrategy = { - "CallExpression": function (node) { + CallExpression: function (node) { if (currentTest && isNonZeroExpectCall(node)) { currentTest.isNonZeroExpectUsed = true; } else if (utils.isTest(node.callee)) { @@ -201,19 +217,21 @@ module.exports = { context.report({ node: currentTest.node, messageId: "expectForbidden", - data: assertionMessageData() + data: assertionMessageData(), }); } releaseTestContext(); } - } + }, }; - return { - "always": AlwaysStrategy, - "except-simple": ExceptSimpleStrategy, - "never": NeverStrategy, - "never-except-zero": NeverExceptZeroStrategy - }[context.options[0]] || NeverExceptZeroStrategy; - } + return ( + { + always: AlwaysStrategy, + "except-simple": ExceptSimpleStrategy, + never: NeverStrategy, + "never-except-zero": NeverExceptZeroStrategy, + }[context.options[0]] || NeverExceptZeroStrategy + ); + }, }; diff --git a/lib/rules/require-object-in-propequal.js b/lib/rules/require-object-in-propequal.js index 98795a71..7b723f14 100644 --- a/lib/rules/require-object-in-propequal.js +++ b/lib/rules/require-object-in-propequal.js @@ -20,14 +20,16 @@ module.exports = { meta: { type: "problem", docs: { - description: "enforce use of objects as expected value in `assert.propEqual`", + description: + "enforce use of objects as expected value in `assert.propEqual`", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/require-object-in-propequal.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/require-object-in-propequal.md", }, messages: { - useObject: "Use object as propEqual expected value (found: {{ value }})." + useObject: + "Use object as propEqual expected value (found: {{ value }}).", }, - schema: [] + schema: [], }, create: function (context) { @@ -42,22 +44,28 @@ module.exports = { } function isGlobalPropEqual(calleeNode) { - return calleeNode && + return ( + calleeNode && calleeNode.type === "Identifier" && - calleeNode.name === "propEqual"; + calleeNode.name === "propEqual" + ); } function isAssertPropEqual(calleeNode) { - return calleeNode && + return ( + calleeNode && calleeNode.type === "MemberExpression" && calleeNode.property.type === "Identifier" && calleeNode.property.name === "propEqual" && calleeNode.object.type === "Identifier" && - calleeNode.object.name === getCurrentAssertContextVariable(); + calleeNode.object.name === getCurrentAssertContextVariable() + ); } function isPropEqual(calleeNode) { - return isAssertPropEqual(calleeNode) || isGlobalPropEqual(calleeNode); + return ( + isAssertPropEqual(calleeNode) || isGlobalPropEqual(calleeNode) + ); } function isValidExpectedValue(argNode) { @@ -76,36 +84,50 @@ module.exports = { } function hasNonObjectExpectedValue(callExpressionNode) { - return callExpressionNode && + return ( + callExpressionNode && callExpressionNode.arguments && callExpressionNode.arguments.length >= 2 && - !isValidExpectedValue(callExpressionNode.arguments[1]); + !isValidExpectedValue(callExpressionNode.arguments[1]) + ); } return { - "CallExpression": function (node) { + CallExpression: function (node) { /* istanbul ignore else: correctly does nothing */ - if (utils.isTest(node.callee) || utils.isAsyncTest(node.callee)) { + if ( + utils.isTest(node.callee) || + utils.isAsyncTest(node.callee) + ) { testStack.push({ - assertVar: utils.getAssertContextNameForTest(node.arguments) + assertVar: utils.getAssertContextNameForTest( + node.arguments, + ), }); - } else if (testStack.length > 0 && isPropEqual(node.callee) && hasNonObjectExpectedValue(node)) { + } else if ( + testStack.length > 0 && + isPropEqual(node.callee) && + hasNonObjectExpectedValue(node) + ) { context.report({ node, messageId: "useObject", data: { - value: sourceCode.getText(node.arguments[1]) - } + value: sourceCode.getText(node.arguments[1]), + }, }); } }, "CallExpression:exit": function (node) { /* istanbul ignore else: correctly does nothing */ - if (utils.isTest(node.callee) || utils.isAsyncTest(node.callee)) { + if ( + utils.isTest(node.callee) || + utils.isAsyncTest(node.callee) + ) { testStack.pop(); } - } + }, }; - } + }, }; diff --git a/lib/rules/resolve-async.js b/lib/rules/resolve-async.js index 66c4b6eb..1b95826e 100644 --- a/lib/rules/resolve-async.js +++ b/lib/rules/resolve-async.js @@ -17,13 +17,15 @@ module.exports = { docs: { description: "require that async calls are resolved", category: "Possible Errors", - url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/resolve-async.md" + url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/resolve-async.md", }, messages: { - needMoreStartCalls: "Need {{semaphore}} more start() {{callOrCalls}}.", - asyncCallbackNotCalled: "Async callback \"{{asyncVar}}\" is not called." + needMoreStartCalls: + "Need {{semaphore}} more start() {{callOrCalls}}.", + asyncCallbackNotCalled: + 'Async callback "{{asyncVar}}" is not called.', }, - schema: [] + schema: [], }, create: function (context) { @@ -37,7 +39,10 @@ module.exports = { const asyncState = asyncStateStack[asyncStateStack.length - 1]; const assertContextVar = asyncState && asyncState.assertContextVar; - return utils.isAsyncCallExpression(callExpressionNode, assertContextVar); + return utils.isAsyncCallExpression( + callExpressionNode, + assertContextVar, + ); } function getAsyncCallbackVarOrNull(calleeNode) { @@ -45,12 +50,17 @@ module.exports = { let result = null; if (asyncState) { - if (calleeNode.type === "Identifier" && calleeNode.name in asyncState.asyncCallbackVars) { + if ( + calleeNode.type === "Identifier" && + calleeNode.name in asyncState.asyncCallbackVars + ) { result = calleeNode.name; } else if (calleeNode.type === "MemberExpression") { - const isCallOrApply = calleeNode.property.type === "Identifier" && + const isCallOrApply = + calleeNode.property.type === "Identifier" && ["call", "apply"].includes(calleeNode.property.name); - const isCallbackVar = calleeNode.object.name in asyncState.asyncCallbackVars; + const isCallbackVar = + calleeNode.object.name in asyncState.asyncCallbackVars; if (isCallOrApply && isCallbackVar) { result = calleeNode.object.name; @@ -95,8 +105,8 @@ module.exports = { messageId: "needMoreStartCalls", data: { semaphore: asyncState.stopSemaphoreCount, - callOrCalls: singular ? "call" : "calls" - } + callOrCalls: singular ? "call" : "calls", + }, }); } @@ -106,32 +116,38 @@ module.exports = { node: node, messageId: "asyncCallbackNotCalled", data: { - asyncVar: callbackVar - } + asyncVar: callbackVar, + }, }); } } } function isInModule(propertyNode) { - return propertyNode && - propertyNode.parent && // ObjectExpression - propertyNode.parent.parent && // CallExpression? + return ( + propertyNode && + propertyNode.parent && // ObjectExpression + propertyNode.parent.parent && // CallExpression? propertyNode.parent.parent.type === "CallExpression" && - utils.isModule(propertyNode.parent.parent.callee); + utils.isModule(propertyNode.parent.parent.callee) + ); } return { - "CallExpression": function (node) { + CallExpression: function (node) { const callbackVar = getAsyncCallbackVarOrNull(node.callee); let delta; if (utils.isTest(node.callee)) { - const assertContextVar = utils.getAssertContextNameForTest(node.arguments); + const assertContextVar = utils.getAssertContextNameForTest( + node.arguments, + ); asyncStateStack.push({ - stopSemaphoreCount: utils.isAsyncTest(node.callee) ? 1 : 0, + stopSemaphoreCount: utils.isAsyncTest(node.callee) + ? 1 + : 0, asyncCallbackVars: {}, - assertContextVar: assertContextVar + assertContextVar: assertContextVar, }); } else if (callbackVar) { markAsyncCallbackVarCalled(callbackVar); @@ -151,35 +167,43 @@ module.exports = { } }, - "Property": function (node) { - if (utils.isModuleHookPropertyKey(node.key) && isInModule(node)) { - const assertContextVar = utils.getAssertContextName(node.value); + Property: function (node) { + if ( + utils.isModuleHookPropertyKey(node.key) && + isInModule(node) + ) { + const assertContextVar = utils.getAssertContextName( + node.value, + ); asyncStateStack.push({ stopSemaphoreCount: 0, asyncCallbackVars: {}, - assertContextVar: assertContextVar + assertContextVar: assertContextVar, }); } }, "Property:exit": function (node) { - if (utils.isModuleHookPropertyKey(node.key) && isInModule(node)) { + if ( + utils.isModuleHookPropertyKey(node.key) && + isInModule(node) + ) { const asyncState = asyncStateStack.pop(); verifyAsyncState(asyncState, node); } }, - "AssignmentExpression": function (node) { + AssignmentExpression: function (node) { if (isAsyncCallExpression(node.right)) { addAsyncCallbackVar(node.left); } }, - "VariableDeclarator": function (node) { + VariableDeclarator: function (node) { if (isAsyncCallExpression(node.init)) { addAsyncCallbackVar(node.id); } - } + }, }; - } + }, }; diff --git a/lib/utils.js b/lib/utils.js index 82deda8f..b462b533 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -10,59 +10,62 @@ const SUPPORTED_TEST_IDENTIFIERS = new Set(["test", "asyncTest", "only"]); const OLD_MODULE_HOOK_IDENTIFIERS = ["setup", "teardown"]; const NEW_MODULE_HOOK_IDENTIFIERS = ["beforeEach", "afterEach"]; -const ALL_MODULE_HOOK_IDENTIFIERS = new Set([...OLD_MODULE_HOOK_IDENTIFIERS, ...NEW_MODULE_HOOK_IDENTIFIERS]); +const ALL_MODULE_HOOK_IDENTIFIERS = new Set([ + ...OLD_MODULE_HOOK_IDENTIFIERS, + ...NEW_MODULE_HOOK_IDENTIFIERS, +]); const ASSERTION_METADATA = { deepEqual: { allowedArities: [2], - compareActualFirst: true + compareActualFirst: true, }, equal: { allowedArities: [2], - compareActualFirst: true + compareActualFirst: true, }, false: { - allowedArities: [1] + allowedArities: [1], }, notDeepEqual: { allowedArities: [2], - compareActualFirst: true + compareActualFirst: true, }, notEqual: { allowedArities: [2], - compareActualFirst: true + compareActualFirst: true, }, notOk: { - allowedArities: [1] + allowedArities: [1], }, notPropEqual: { allowedArities: [2], - compareActualFirst: true + compareActualFirst: true, }, notStrictEqual: { allowedArities: [2], - compareActualFirst: true + compareActualFirst: true, }, ok: { - allowedArities: [1] + allowedArities: [1], }, propEqual: { allowedArities: [2], - compareActualFirst: true + compareActualFirst: true, }, strictEqual: { allowedArities: [2], - compareActualFirst: true + compareActualFirst: true, }, raises: { - allowedArities: [1, 2] + allowedArities: [1, 2], }, throws: { - allowedArities: [1, 2] + allowedArities: [1, 2], }, true: { - allowedArities: [1] - } + allowedArities: [1], + }, }; function getAssertionNames() { @@ -73,15 +76,22 @@ exports.getAssertionNames = getAssertionNames; function getAssertionMetadata(calleeNode, assertVar) { if (calleeNode.type === "MemberExpression") { - return calleeNode.object && + return ( + calleeNode.object && calleeNode.object.type === "Identifier" && calleeNode.object.name === assertVar && calleeNode.property && - Object.hasOwnProperty.call(ASSERTION_METADATA, calleeNode.property.name) && - ASSERTION_METADATA[calleeNode.property.name]; + Object.hasOwnProperty.call( + ASSERTION_METADATA, + calleeNode.property.name, + ) && + ASSERTION_METADATA[calleeNode.property.name] + ); } else if (calleeNode.type === "Identifier") { - return Object.hasOwnProperty.call(ASSERTION_METADATA, calleeNode.name) && - ASSERTION_METADATA[calleeNode.name]; + return ( + Object.hasOwnProperty.call(ASSERTION_METADATA, calleeNode.name) && + ASSERTION_METADATA[calleeNode.name] + ); } return null; @@ -92,13 +102,15 @@ exports.isAsyncCallExpression = function (callExpressionNode, assertVar) { assertVar = "assert"; } - return callExpressionNode && + return ( + callExpressionNode && callExpressionNode.type === "CallExpression" && callExpressionNode.callee.type === "MemberExpression" && callExpressionNode.callee.object.type === "Identifier" && callExpressionNode.callee.object.name === assertVar && callExpressionNode.callee.property.type === "Identifier" && - callExpressionNode.callee.property.name === "async"; + callExpressionNode.callee.property.name === "async" + ); }; exports.isStop = function (calleeNode) { @@ -108,7 +120,8 @@ exports.isStop = function (calleeNode) { if (calleeNode.type === "Identifier") { result = calleeNode.name === "stop"; } else if (calleeNode.type === "MemberExpression") { - result = calleeNode.object.type === "Identifier" && + result = + calleeNode.object.type === "Identifier" && calleeNode.object.name === "QUnit" && calleeNode.property.type === "Identifier" && calleeNode.property.name === "stop"; @@ -124,7 +137,8 @@ exports.isStart = function (calleeNode) { if (calleeNode.type === "Identifier") { result = calleeNode.name === "start"; } else if (calleeNode.type === "MemberExpression") { - result = calleeNode.object.type === "Identifier" && + result = + calleeNode.object.type === "Identifier" && calleeNode.object.name === "QUnit" && calleeNode.property.type === "Identifier" && calleeNode.property.name === "start"; @@ -140,7 +154,8 @@ exports.isTest = function (calleeNode) { if (calleeNode.type === "Identifier") { result = SUPPORTED_TEST_IDENTIFIERS.has(calleeNode.name); } else if (calleeNode.type === "MemberExpression") { - result = calleeNode.object.type === "Identifier" && + result = + calleeNode.object.type === "Identifier" && calleeNode.object.name === "QUnit" && calleeNode.property.type === "Identifier" && SUPPORTED_TEST_IDENTIFIERS.has(calleeNode.property.name); @@ -156,7 +171,8 @@ exports.isModule = function (calleeNode) { if (calleeNode.type === "Identifier") { result = calleeNode.name === "module"; } else if (calleeNode.type === "MemberExpression") { - result = calleeNode.object.type === "Identifier" && + result = + calleeNode.object.type === "Identifier" && calleeNode.object.name === "QUnit" && calleeNode.property.type === "Identifier" && calleeNode.property.name === "module"; @@ -166,9 +182,11 @@ exports.isModule = function (calleeNode) { }; exports.isModuleHookPropertyKey = function (identifierNode) { - return identifierNode && + return ( + identifierNode && identifierNode.type === "Identifier" && - ALL_MODULE_HOOK_IDENTIFIERS.has(identifierNode.name); + ALL_MODULE_HOOK_IDENTIFIERS.has(identifierNode.name) + ); }; exports.isAsyncTest = function (calleeNode) { @@ -178,7 +196,8 @@ exports.isAsyncTest = function (calleeNode) { if (calleeNode.type === "Identifier") { result = calleeNode.name === "asyncTest"; } else if (calleeNode.type === "MemberExpression") { - result = calleeNode.object.type === "Identifier" && + result = + calleeNode.object.type === "Identifier" && calleeNode.object.name === "QUnit" && calleeNode.property.type === "Identifier" && calleeNode.property.name === "asyncTest"; @@ -194,13 +213,21 @@ function isQUnitMethod(calleeNode, qunitMethod) { if (calleeNode.type === "Identifier") { // () result = calleeNode.name === qunitMethod; - } else if (calleeNode.type === "MemberExpression" && calleeNode.property.type === "Identifier" && calleeNode.property.name === qunitMethod) { + } else if ( + calleeNode.type === "MemberExpression" && + calleeNode.property.type === "Identifier" && + calleeNode.property.name === qunitMethod + ) { if (calleeNode.object.type === "Identifier") { // QUnit.() or module.(), or test.() - result = calleeNode.object.name === "QUnit" || calleeNode.object.name === "module" || calleeNode.object.name === "test"; + result = + calleeNode.object.name === "QUnit" || + calleeNode.object.name === "module" || + calleeNode.object.name === "test"; } else if (calleeNode.object.type === "MemberExpression") { // QUnit.*.() - result = calleeNode.object.object.type === "Identifier" && + result = + calleeNode.object.object.type === "Identifier" && calleeNode.object.object.name === "QUnit"; } } @@ -218,7 +245,10 @@ exports.isSkip = function (calleeNode) { exports.getAssertContextNameForTest = function (argumentsNodes) { const functionExpr = argumentsNodes.find(function (argNode) { - return argNode.type === "FunctionExpression" || argNode.type === "ArrowFunctionExpression"; + return ( + argNode.type === "FunctionExpression" || + argNode.type === "ArrowFunctionExpression" + ); }); return this.getAssertContextName(functionExpr); @@ -230,7 +260,9 @@ exports.getAssertContextName = function (functionExpr) { if (functionExpr && functionExpr.params) { // In TypeScript, `this` can be passed as the first function parameter to add a type to it, // and we want to ignore that parameter since we're looking for the `hooks` variable. - const hooksParam = functionExpr.params.find(p => p.type === "Identifier" && p.name !== "this"); + const hooksParam = functionExpr.params.find( + (p) => p.type === "Identifier" && p.name !== "this", + ); if (hooksParam) { result = hooksParam.name; } @@ -246,7 +278,10 @@ exports.isAssertion = function (calleeNode, assertVar) { exports.getAllowedArities = function (calleeNode, assertVar) { const assertionMetadata = getAssertionMetadata(calleeNode, assertVar); - return assertionMetadata && assertionMetadata.allowedArities || /* istanbul ignore next */[]; + return ( + (assertionMetadata && assertionMetadata.allowedArities) || + /* istanbul ignore next */ [] + ); }; exports.isComparativeAssertion = function (calleeNode, assertVar) { @@ -268,9 +303,11 @@ exports.createAssertionCheck = function (assertions, errorMessageConfig) { const testStack = []; function isGlobalAssertion(calleeNode) { - return calleeNode && + return ( + calleeNode && calleeNode.type === "Identifier" && - assertions.includes(calleeNode.name); + assertions.includes(calleeNode.name) + ); } function getCurrentAssertContextVariable() { @@ -280,58 +317,83 @@ exports.createAssertionCheck = function (assertions, errorMessageConfig) { } function isMethodCalledOnLocalAssertObject(calleeNode) { - return calleeNode && + return ( + calleeNode && calleeNode.type === "MemberExpression" && calleeNode.property.type === "Identifier" && assertions.includes(calleeNode.property.name) && calleeNode.object.type === "Identifier" && - calleeNode.object.name === getCurrentAssertContextVariable(); + calleeNode.object.name === getCurrentAssertContextVariable() + ); } function isExpectedAssertion(calleeNode) { - return isGlobalAssertion(calleeNode) || - isMethodCalledOnLocalAssertObject(calleeNode); + return ( + isGlobalAssertion(calleeNode) || + isMethodCalledOnLocalAssertObject(calleeNode) + ); } function reportError(node) { const assertVar = getCurrentAssertContextVariable(); const isGlobal = isGlobalAssertion(node.callee); - const assertion = isGlobal ? node.callee.name : node.callee.property.name; + const assertion = isGlobal + ? node.callee.name + : node.callee.property.name; const reportErrorObject = { node, data: { assertVar, - assertion - } + assertion, + }, }; - const errorMessageConfigForAssertion = errorMessageConfig[assertion]; - if (errorMessageConfigForAssertion.unexpectedGlobalAssertionMessageId && errorMessageConfigForAssertion.unexpectedLocalAssertionMessageId) { - reportErrorObject.messageId = isGlobal ? errorMessageConfigForAssertion.unexpectedGlobalAssertionMessageId : errorMessageConfigForAssertion.unexpectedLocalAssertionMessageId; + const errorMessageConfigForAssertion = + errorMessageConfig[assertion]; + if ( + errorMessageConfigForAssertion.unexpectedGlobalAssertionMessageId && + errorMessageConfigForAssertion.unexpectedLocalAssertionMessageId + ) { + reportErrorObject.messageId = isGlobal + ? errorMessageConfigForAssertion.unexpectedGlobalAssertionMessageId + : errorMessageConfigForAssertion.unexpectedLocalAssertionMessageId; } else { - reportErrorObject.message = isGlobal ? errorMessageConfigForAssertion.unexpectedGlobalAssertionMessage : errorMessageConfigForAssertion.unexpectedLocalAssertionMessage; + reportErrorObject.message = isGlobal + ? errorMessageConfigForAssertion.unexpectedGlobalAssertionMessage + : errorMessageConfigForAssertion.unexpectedLocalAssertionMessage; } context.report(reportErrorObject); } return { - "CallExpression": function (node) { + CallExpression: function (node) { /* istanbul ignore else: correctly does nothing */ - if (exports.isTest(node.callee) || exports.isAsyncTest(node.callee)) { + if ( + exports.isTest(node.callee) || + exports.isAsyncTest(node.callee) + ) { testStack.push({ - assertVar: exports.getAssertContextNameForTest(node.arguments) + assertVar: exports.getAssertContextNameForTest( + node.arguments, + ), }); - } else if (testStack.length > 0 && isExpectedAssertion(node.callee)) { + } else if ( + testStack.length > 0 && + isExpectedAssertion(node.callee) + ) { reportError(node); } }, "CallExpression:exit": function (node) { /* istanbul ignore else: correctly does nothing */ - if (exports.isTest(node.callee) || exports.isAsyncTest(node.callee)) { + if ( + exports.isTest(node.callee) || + exports.isAsyncTest(node.callee) + ) { testStack.pop(); } - } + }, }; }; }; diff --git a/package-lock.json b/package-lock.json index 12dabca8..faa6a063 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,12 +21,14 @@ "chai": "^4.3.10", "coveralls": "^3.1.1", "eslint": "^8.55.0", + "eslint-config-prettier": "^9.1.0", "eslint-doc-generator": "^1.5.1", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-eslint-plugin": "^5.1.1", "eslint-plugin-markdown": "^3.0.1", "eslint-plugin-mocha": "^10.2.0", "eslint-plugin-node": "^11.1.0", + "eslint-plugin-prettier": "^5.0.1", "eslint-plugin-qunit": "file:./", "eslint-plugin-unicorn": "^51.0.1", "eslint-remote-tester": "^3.0.1", @@ -37,6 +39,7 @@ "npm-run-all": "^4.1.5", "nyc": "^15.1.0", "outdent": "^0.8.0", + "prettier": "^3.1.0", "release-it": "^16.2.1", "semver": "^7.5.4", "typescript": "^5.2.2" @@ -1159,6 +1162,26 @@ "node": ">=14" } }, + "node_modules/@pkgr/utils": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/@pkgr/utils/-/utils-2.4.2.tgz", + "integrity": "sha512-POgTXhjrTfbTV63DiFXav4lBHiICLKKwDeaKn9Nphwj7WH6m0hMMCaJkMyRWjgtPFyRKRVoMXXjczsTQRDEhYw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.3", + "fast-glob": "^3.3.0", + "is-glob": "^4.0.3", + "open": "^9.1.0", + "picocolors": "^1.0.0", + "tslib": "^2.6.0" + }, + "engines": { + "node": "^12.20.0 || ^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/@pnpm/config.env-replace": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@pnpm/config.env-replace/-/config.env-replace-1.1.0.tgz", @@ -1645,6 +1668,22 @@ "prettier": "^2" } }, + "node_modules/all-contributors-cli/node_modules/prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true, + "optional": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/ansi-align": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz", @@ -3763,6 +3802,18 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint-config-prettier": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", + "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", + "dev": true, + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, "node_modules/eslint-doc-generator": { "version": "1.6.2", "resolved": "https://registry.npmjs.org/eslint-doc-generator/-/eslint-doc-generator-1.6.2.tgz", @@ -4012,6 +4063,35 @@ "semver": "bin/semver.js" } }, + "node_modules/eslint-plugin-prettier": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.0.1.tgz", + "integrity": "sha512-m3u5RnR56asrwV/lDC4GHorlW75DsFfmUcjfCYylTUs85dBRnB7VM6xG8eCMJdeDRnppzmxZVf1GEPJvl1JmNg==", + "dev": true, + "dependencies": { + "prettier-linter-helpers": "^1.0.0", + "synckit": "^0.8.5" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/prettier" + }, + "peerDependencies": { + "@types/eslint": ">=8.0.0", + "eslint": ">=8.0.0", + "prettier": ">=3.0.0" + }, + "peerDependenciesMeta": { + "@types/eslint": { + "optional": true + }, + "eslint-config-prettier": { + "optional": true + } + } + }, "node_modules/eslint-plugin-qunit": { "resolved": "", "link": true @@ -4457,6 +4537,12 @@ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, + "node_modules/fast-diff": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", + "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", + "dev": true + }, "node_modules/fast-glob": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz", @@ -8646,21 +8732,32 @@ } }, "node_modules/prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.0.tgz", + "integrity": "sha512-TQLvXjq5IAibjh8EpBIkNKxO749UEWABoiIZehEPiY4GNpVdhaFKqSTu+QrlU6D2dPAfubRmtJTi4K4YkQ5eXw==", "dev": true, - "optional": true, "bin": { - "prettier": "bin-prettier.js" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": ">=10.13.0" + "node": ">=14" }, "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "dependencies": { + "fast-diff": "^1.1.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/pretty-format": { "version": "29.5.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.5.0.tgz", @@ -10667,6 +10764,22 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/synckit": { + "version": "0.8.6", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.6.tgz", + "integrity": "sha512-laHF2savN6sMeHCjLRkheIU4wo3Zg9Ln5YOjOo7sZ5dVQW8yF5pPE5SIw1dsPhq3TRp1jisKRCdPhfs/1WMqDA==", + "dev": true, + "dependencies": { + "@pkgr/utils": "^2.4.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -10801,9 +10914,9 @@ } }, "node_modules/tslib": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.0.tgz", - "integrity": "sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==", + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", "dev": true }, "node_modules/tsutils": { diff --git a/package.json b/package.json index a9413226..ae079128 100644 --- a/package.json +++ b/package.json @@ -37,12 +37,14 @@ "chai": "^4.3.10", "coveralls": "^3.1.1", "eslint": "^8.55.0", + "eslint-config-prettier": "^9.1.0", "eslint-doc-generator": "^1.5.1", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-eslint-plugin": "^5.1.1", "eslint-plugin-markdown": "^3.0.1", "eslint-plugin-mocha": "^10.2.0", "eslint-plugin-node": "^11.1.0", + "eslint-plugin-prettier": "^5.0.1", "eslint-plugin-qunit": "file:./", "eslint-plugin-unicorn": "^51.0.1", "eslint-remote-tester": "^3.0.1", @@ -53,6 +55,7 @@ "npm-run-all": "^4.1.5", "nyc": "^15.1.0", "outdent": "^0.8.0", + "prettier": "^3.1.0", "release-it": "^16.2.1", "semver": "^7.5.4", "typescript": "^5.2.2" diff --git a/tests/index.js b/tests/index.js index b921b39f..d2654930 100644 --- a/tests/index.js +++ b/tests/index.js @@ -19,21 +19,30 @@ const assert = require("chai").assert, // Tests //------------------------------------------------------------------------------ -const ruleNames = fs.readdirSync("./lib/rules").map(rawFileName => path.basename(rawFileName, ".js")); +const ruleNames = fs + .readdirSync("./lib/rules") + .map((rawFileName) => path.basename(rawFileName, ".js")); describe("index.js", function () { describe("rules", function () { for (const ruleName of ruleNames) { describe(ruleName, function () { it("should appear in rule exports", function () { - assert.property(rules, ruleName, `Rule export for ${ruleName} not present`); + assert.property( + rules, + ruleName, + `Rule export for ${ruleName} not present`, + ); }); it("should appear in tests", function (done) { const path = `./tests/lib/rules/${ruleName}.js`; fs.access(path, function (err) { - assert.notOk(err, `tests/lib/rules/${ruleName}.js should exist`); + assert.notOk( + err, + `tests/lib/rules/${ruleName}.js should exist`, + ); done(); }); }); @@ -42,7 +51,10 @@ describe("index.js", function () { const path = `./docs/rules/${ruleName}.md`; fs.access(path, function (err) { - assert.notOk(err, `docs/rules/${ruleName}.md should exist`); + assert.notOk( + err, + `docs/rules/${ruleName}.md should exist`, + ); done(); }); }); @@ -52,8 +64,10 @@ describe("index.js", function () { const fileContents = fs.readFileSync(path, "utf8"); assert.ok( - fileContents.includes("/** @type {import('eslint').Rule.RuleModule} */"), - "includes jsdoc comment for rule type" + fileContents.includes( + "/** @type {import('eslint').Rule.RuleModule} */", + ), + "includes jsdoc comment for rule type", ); }); }); @@ -74,10 +88,15 @@ describe("index.js", function () { describe("flat", function () { // eslint-disable-next-line mocha/no-setup-in-describe -- rule doesn't like function calls like `Object.entries()` - for (const [configName, config] of Object.entries(requireIndex(`${__dirname}/../lib/configs`))) { + for (const [configName, config] of Object.entries( + // eslint-disable-next-line mocha/no-setup-in-describe -- rule doesn't like function calls like `Object.entries()` + requireIndex(`${__dirname}/../lib/configs`), + )) { describe(configName, function () { it("has the right plugins", function () { - assert.deepStrictEqual(config.plugins, { qunit: plugin }); + assert.deepStrictEqual(config.plugins, { + qunit: plugin, + }); }); }); } diff --git a/tests/lib/rules/assert-args.js b/tests/lib/rules/assert-args.js index 49e32616..cf973039 100644 --- a/tests/lib/rules/assert-args.js +++ b/tests/lib/rules/assert-args.js @@ -31,10 +31,14 @@ ruleTester.run("assert-args", rule, { // equal testUtils.wrapInTest("equal(result, expected);"), testUtils.wrapInTest("equal(result, expected, 'Message');"), - testUtils.wrapInTest("equal(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "equal(obj[key], expected, key + ' value is true');", + ), testUtils.wrapInTest("assert.equal(result, expected);"), testUtils.wrapInTest("assert.equal(result, expected, 'Message');"), - testUtils.wrapInTest("assert.equal(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "assert.equal(obj[key], expected, key + ' value is true');", + ), // false testUtils.wrapInTest("assert.false(result);"), @@ -43,26 +47,40 @@ ruleTester.run("assert-args", rule, { // strictEqual testUtils.wrapInTest("strictEqual(result, expected);"), testUtils.wrapInTest("strictEqual(result, expected, 'Message');"), - testUtils.wrapInTest("strictEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "strictEqual(obj[key], expected, key + ' value is true');", + ), testUtils.wrapInTest("assert.strictEqual(result, expected);"), - testUtils.wrapInTest("assert.strictEqual(result, expected, 'Message');"), - testUtils.wrapInTest("assert.strictEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "assert.strictEqual(result, expected, 'Message');", + ), + testUtils.wrapInTest( + "assert.strictEqual(obj[key], expected, key + ' value is true');", + ), // deepEqual testUtils.wrapInTest("deepEqual(result, expected);"), testUtils.wrapInTest("deepEqual(result, expected, 'Message');"), - testUtils.wrapInTest("deepEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "deepEqual(obj[key], expected, key + ' value is true');", + ), testUtils.wrapInTest("assert.deepEqual(result, expected);"), testUtils.wrapInTest("assert.deepEqual(result, expected, 'Message');"), - testUtils.wrapInTest("assert.deepEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "assert.deepEqual(obj[key], expected, key + ' value is true');", + ), // propEqual testUtils.wrapInTest("propEqual(result, expected);"), testUtils.wrapInTest("propEqual(result, expected, 'Message');"), - testUtils.wrapInTest("propEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "propEqual(obj[key], expected, key + ' value is true');", + ), testUtils.wrapInTest("assert.propEqual(result, expected);"), testUtils.wrapInTest("assert.propEqual(result, expected, 'Message');"), - testUtils.wrapInTest("assert.propEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "assert.propEqual(obj[key], expected, key + ' value is true');", + ), // raises testUtils.wrapInTest("raises(function () {});"), @@ -71,13 +89,23 @@ ruleTester.run("assert-args", rule, { testUtils.wrapInTest("raises(function () {}, TypeError, 'Message');"), testUtils.wrapInTest("raises(function () {}, /error/, 'Message');"), testUtils.wrapInTest("raises(function () {}, 'Error', 'Message');"), - testUtils.wrapInTest("raises(function () {}, TypeError, expectedMessage);"), + testUtils.wrapInTest( + "raises(function () {}, TypeError, expectedMessage);", + ), testUtils.wrapInTest("assert.raises(function () {}, 'Message');"), - testUtils.wrapInTest("assert.raises(function () {}, TypeError, 'Message');"), + testUtils.wrapInTest( + "assert.raises(function () {}, TypeError, 'Message');", + ), testUtils.wrapInTest("assert.raises(function () {}, expectedMessage);"), - testUtils.wrapInTest("assert.raises(function () {}, /error/, 'Message');"), - testUtils.wrapInTest("assert.raises(function () {}, 'Error', 'Message');"), - testUtils.wrapInTest("assert.raises(function () {}, TypeError, expectedMessage);"), + testUtils.wrapInTest( + "assert.raises(function () {}, /error/, 'Message');", + ), + testUtils.wrapInTest( + "assert.raises(function () {}, 'Error', 'Message');", + ), + testUtils.wrapInTest( + "assert.raises(function () {}, TypeError, expectedMessage);", + ), // throws testUtils.wrapInTest("throws(function () {});"), @@ -86,13 +114,23 @@ ruleTester.run("assert-args", rule, { testUtils.wrapInTest("throws(function () {}, TypeError, 'Message');"), testUtils.wrapInTest("throws(function () {}, /error/, 'Message');"), testUtils.wrapInTest("throws(function () {}, 'Error', 'Message');"), - testUtils.wrapInTest("throws(function () {}, TypeError, expectedMessage);"), + testUtils.wrapInTest( + "throws(function () {}, TypeError, expectedMessage);", + ), testUtils.wrapInTest("assert.throws(function () {}, 'Message');"), - testUtils.wrapInTest("assert.throws(function () {}, TypeError, 'Message');"), + testUtils.wrapInTest( + "assert.throws(function () {}, TypeError, 'Message');", + ), testUtils.wrapInTest("assert.throws(function () {}, expectedMessage);"), - testUtils.wrapInTest("assert.throws(function () {}, /error/, 'Message');"), - testUtils.wrapInTest("assert.throws(function () {}, 'Error', 'Message');"), - testUtils.wrapInTest("assert.throws(function () {}, TypeError, expectedMessage);"), + testUtils.wrapInTest( + "assert.throws(function () {}, /error/, 'Message');", + ), + testUtils.wrapInTest( + "assert.throws(function () {}, 'Error', 'Message');", + ), + testUtils.wrapInTest( + "assert.throws(function () {}, TypeError, expectedMessage);", + ), // true testUtils.wrapInTest("assert.true(result);"), @@ -109,34 +147,56 @@ ruleTester.run("assert-args", rule, { // notEqual testUtils.wrapInTest("notEqual(result, expected);"), testUtils.wrapInTest("notEqual(result, expected, 'Message');"), - testUtils.wrapInTest("notEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "notEqual(obj[key], expected, key + ' value is true');", + ), testUtils.wrapInTest("assert.notEqual(result, expected);"), testUtils.wrapInTest("assert.notEqual(result, expected, 'Message');"), - testUtils.wrapInTest("assert.notEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "assert.notEqual(obj[key], expected, key + ' value is true');", + ), // notStrictEqual testUtils.wrapInTest("notStrictEqual(result, expected);"), testUtils.wrapInTest("notStrictEqual(result, expected, 'Message');"), - testUtils.wrapInTest("notStrictEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "notStrictEqual(obj[key], expected, key + ' value is true');", + ), testUtils.wrapInTest("assert.notStrictEqual(result, expected);"), - testUtils.wrapInTest("assert.notStrictEqual(result, expected, 'Message');"), - testUtils.wrapInTest("assert.notStrictEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "assert.notStrictEqual(result, expected, 'Message');", + ), + testUtils.wrapInTest( + "assert.notStrictEqual(obj[key], expected, key + ' value is true');", + ), // notDeepEqual testUtils.wrapInTest("notDeepEqual(result, expected);"), testUtils.wrapInTest("notDeepEqual(result, expected, 'Message');"), - testUtils.wrapInTest("notDeepEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "notDeepEqual(obj[key], expected, key + ' value is true');", + ), testUtils.wrapInTest("assert.notDeepEqual(result, expected);"), - testUtils.wrapInTest("assert.notDeepEqual(result, expected, 'Message');"), - testUtils.wrapInTest("assert.notDeepEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "assert.notDeepEqual(result, expected, 'Message');", + ), + testUtils.wrapInTest( + "assert.notDeepEqual(obj[key], expected, key + ' value is true');", + ), // notPropEqual testUtils.wrapInTest("notPropEqual(result, expected);"), testUtils.wrapInTest("notPropEqual(result, expected, 'Message');"), - testUtils.wrapInTest("notPropEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "notPropEqual(obj[key], expected, key + ' value is true');", + ), testUtils.wrapInTest("assert.notPropEqual(result, expected);"), - testUtils.wrapInTest("assert.notPropEqual(result, expected, 'Message');"), - testUtils.wrapInTest("assert.notPropEqual(obj[key], expected, key + ' value is true');"), + testUtils.wrapInTest( + "assert.notPropEqual(result, expected, 'Message');", + ), + testUtils.wrapInTest( + "assert.notPropEqual(obj[key], expected, key + ' value is true');", + ), // not actually assertions testUtils.wrapInTest("notAnAssertion(result, expected);"), @@ -147,20 +207,22 @@ ruleTester.run("assert-args", rule, { testUtils.wrapInTest("assert.hasOwnProperty('prop');"), // unwrapped - "notAnAssertion(result, expected);" + "notAnAssertion(result, expected);", ], invalid: [ // ok { code: testUtils.wrapInTest("ok();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "ok", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "ok", + argCount: 0, + }, + }, + ], }, /* Allowed for now. { @@ -170,35 +232,41 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("ok(a, b, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "ok", - argCount: 3 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "ok", + argCount: 3, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.ok();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.ok", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.ok", + argCount: 0, + }, + }, + ], }, { // TypeScript: test callback is adding a type to `this` code: "QUnit.test('test', (this: LocalTestContext, assert) => { assert.ok(); });", parser: require.resolve("@typescript-eslint/parser"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.ok", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.ok", + argCount: 0, + }, + }, + ], }, /* Allowed for now. { @@ -208,35 +276,41 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("assert.ok(a, b, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.ok", - argCount: 3 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.ok", + argCount: 3, + }, + }, + ], }, // equal { code: testUtils.wrapInTest("equal();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "equal", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "equal", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("equal(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "equal", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "equal", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -246,33 +320,39 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("equal(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "equal", - argCount: 4 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "equal", + argCount: 4, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.equal();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.equal", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.equal", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.equal(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.equal", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.equal", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -282,79 +362,93 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("assert.equal(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.equal", - argCount: 4 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.equal", + argCount: 4, + }, + }, + ], }, // false { code: testUtils.wrapInTest("assert.false();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.false", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.false", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.false(a, b, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.false", - argCount: 3 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.false", + argCount: 3, + }, + }, + ], }, // true { code: testUtils.wrapInTest("assert.true();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.true", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.true", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.true(a, b, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.true", - argCount: 3 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.true", + argCount: 3, + }, + }, + ], }, // strictEqual { code: testUtils.wrapInTest("strictEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "strictEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "strictEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("strictEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "strictEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "strictEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -364,44 +458,52 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("strictEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "strictEqual", - argCount: 4 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "strictEqual", + argCount: 4, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.strictEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.strictEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.strictEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInArrowTest("assert.strictEqual();"), parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.strictEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.strictEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.strictEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.strictEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.strictEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -410,36 +512,44 @@ ruleTester.run("assert-args", rule, { }, */ { - code: testUtils.wrapInTest("assert.strictEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.strictEqual", - argCount: 4 - } - }] + code: testUtils.wrapInTest( + "assert.strictEqual(a, b, c, 'Message');", + ), + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.strictEqual", + argCount: 4, + }, + }, + ], }, // deepEqual { code: testUtils.wrapInTest("deepEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "deepEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "deepEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("deepEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "deepEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "deepEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -449,33 +559,39 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("deepEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "deepEqual", - argCount: 4 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "deepEqual", + argCount: 4, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.deepEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.deepEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.deepEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.deepEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.deepEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.deepEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -485,35 +601,41 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("assert.deepEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.deepEqual", - argCount: 4 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.deepEqual", + argCount: 4, + }, + }, + ], }, // propEqual { code: testUtils.wrapInTest("propEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "propEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "propEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("propEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "propEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "propEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -523,33 +645,39 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("propEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "propEqual", - argCount: 4 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "propEqual", + argCount: 4, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.propEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.propEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.propEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.propEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.propEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.propEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -559,25 +687,29 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("assert.propEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.propEqual", - argCount: 4 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.propEqual", + argCount: 4, + }, + }, + ], }, // raises { code: testUtils.wrapInTest("raises();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "raises", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "raises", + argCount: 0, + }, + }, + ], }, /* Allowed for now. { @@ -586,24 +718,30 @@ ruleTester.run("assert-args", rule, { }, */ { - code: testUtils.wrapInTest("raises(function () {}, TypeError, blah, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "raises", - argCount: 4 - } - }] + code: testUtils.wrapInTest( + "raises(function () {}, TypeError, blah, 'Message');", + ), + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "raises", + argCount: 4, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.raises();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.raises", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.raises", + argCount: 0, + }, + }, + ], }, /* Allowed for now. { @@ -612,26 +750,32 @@ ruleTester.run("assert-args", rule, { }, */ { - code: testUtils.wrapInTest("assert.raises(function () {}, TypeError, blah, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.raises", - argCount: 4 - } - }] + code: testUtils.wrapInTest( + "assert.raises(function () {}, TypeError, blah, 'Message');", + ), + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.raises", + argCount: 4, + }, + }, + ], }, // throws { code: testUtils.wrapInTest("throws();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "throws", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "throws", + argCount: 0, + }, + }, + ], }, /* Allowed for now. { @@ -640,24 +784,30 @@ ruleTester.run("assert-args", rule, { }, */ { - code: testUtils.wrapInTest("throws(function () {}, TypeError, blah, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "throws", - argCount: 4 - } - }] + code: testUtils.wrapInTest( + "throws(function () {}, TypeError, blah, 'Message');", + ), + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "throws", + argCount: 4, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.throws();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.throws", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.throws", + argCount: 0, + }, + }, + ], }, /* Allowed for now. { @@ -666,26 +816,32 @@ ruleTester.run("assert-args", rule, { }, */ { - code: testUtils.wrapInTest("assert.throws(function () {}, TypeError, blah, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.throws", - argCount: 4 - } - }] + code: testUtils.wrapInTest( + "assert.throws(function () {}, TypeError, blah, 'Message');", + ), + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.throws", + argCount: 4, + }, + }, + ], }, // notOk { code: testUtils.wrapInTest("notOk();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "notOk", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "notOk", + argCount: 0, + }, + }, + ], }, /* Allowed for now. { @@ -695,23 +851,27 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("notOk(a, b, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "notOk", - argCount: 3 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "notOk", + argCount: 3, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.notOk();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.notOk", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.notOk", + argCount: 0, + }, + }, + ], }, /* Allowed for now. { @@ -721,35 +881,41 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("assert.notOk(a, b, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.notOk", - argCount: 3 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.notOk", + argCount: 3, + }, + }, + ], }, // notEqual { code: testUtils.wrapInTest("notEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "notEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "notEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("notEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "notEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "notEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -759,33 +925,39 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("notEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "notEqual", - argCount: 4 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "notEqual", + argCount: 4, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.notEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.notEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.notEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.notEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.notEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.notEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -795,35 +967,41 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("assert.notEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.notEqual", - argCount: 4 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.notEqual", + argCount: 4, + }, + }, + ], }, // notStrictEqual { code: testUtils.wrapInTest("notStrictEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "notStrictEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "notStrictEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("notStrictEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "notStrictEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "notStrictEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -833,33 +1011,39 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("notStrictEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "notStrictEqual", - argCount: 4 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "notStrictEqual", + argCount: 4, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.notStrictEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.notStrictEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.notStrictEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.notStrictEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.notStrictEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.notStrictEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -868,36 +1052,44 @@ ruleTester.run("assert-args", rule, { }, */ { - code: testUtils.wrapInTest("assert.notStrictEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.notStrictEqual", - argCount: 4 - } - }] + code: testUtils.wrapInTest( + "assert.notStrictEqual(a, b, c, 'Message');", + ), + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.notStrictEqual", + argCount: 4, + }, + }, + ], }, // notDeepEqual { code: testUtils.wrapInTest("notDeepEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "notDeepEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "notDeepEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("notDeepEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "notDeepEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "notDeepEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -907,33 +1099,39 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("notDeepEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "notDeepEqual", - argCount: 4 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "notDeepEqual", + argCount: 4, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.notDeepEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.notDeepEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.notDeepEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.notDeepEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.notDeepEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.notDeepEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -942,36 +1140,44 @@ ruleTester.run("assert-args", rule, { }, */ { - code: testUtils.wrapInTest("assert.notDeepEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.notDeepEqual", - argCount: 4 - } - }] + code: testUtils.wrapInTest( + "assert.notDeepEqual(a, b, c, 'Message');", + ), + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.notDeepEqual", + argCount: 4, + }, + }, + ], }, // notPropEqual { code: testUtils.wrapInTest("notPropEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "notPropEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "notPropEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("notPropEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "notPropEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "notPropEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -981,33 +1187,39 @@ ruleTester.run("assert-args", rule, { */ { code: testUtils.wrapInTest("notPropEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "notPropEqual", - argCount: 4 - } - }] + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "notPropEqual", + argCount: 4, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.notPropEqual();"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.notPropEqual", - argCount: 0 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.notPropEqual", + argCount: 0, + }, + }, + ], }, { code: testUtils.wrapInTest("assert.notPropEqual(a);"), - errors: [{ - messageId: "unexpectedArgCountNoMessage", - data: { - callee: "assert.notPropEqual", - argCount: 1 - } - }] + errors: [ + { + messageId: "unexpectedArgCountNoMessage", + data: { + callee: "assert.notPropEqual", + argCount: 1, + }, + }, + ], }, /* Allowed for now. { @@ -1016,14 +1228,18 @@ ruleTester.run("assert-args", rule, { }, */ { - code: testUtils.wrapInTest("assert.notPropEqual(a, b, c, 'Message');"), - errors: [{ - messageId: "unexpectedArgCount", - data: { - callee: "assert.notPropEqual", - argCount: 4 - } - }] - } - ] + code: testUtils.wrapInTest( + "assert.notPropEqual(a, b, c, 'Message');", + ), + errors: [ + { + messageId: "unexpectedArgCount", + data: { + callee: "assert.notPropEqual", + argCount: 4, + }, + }, + ], + }, + ], }); diff --git a/tests/lib/rules/literal-compare-order.js b/tests/lib/rules/literal-compare-order.js index 4af347aa..42e8186f 100644 --- a/tests/lib/rules/literal-compare-order.js +++ b/tests/lib/rules/literal-compare-order.js @@ -32,439 +32,621 @@ ruleTester.run("literal-compare-order", rule, { testUtils.wrapInTest("strictEqual(variable, 'Literal');"), testUtils.wrapInTest("strictEqual(variable, 'Literal', 'Message');"), testUtils.wrapInTest("assert.strictEqual(variable, 'Literal');"), - testUtils.wrapInTest("assert.strictEqual(variable, 'Literal', 'Message');"), + testUtils.wrapInTest( + "assert.strictEqual(variable, 'Literal', 'Message');", + ), // deepEqual testUtils.wrapInTest("deepEqual(variable, 'Literal');"), testUtils.wrapInTest("deepEqual(variable, 'Literal', 'Message');"), testUtils.wrapInTest("assert.deepEqual(variable, 'Literal');"), - testUtils.wrapInTest("assert.deepEqual(variable, 'Literal', 'Message');"), + testUtils.wrapInTest( + "assert.deepEqual(variable, 'Literal', 'Message');", + ), // propEqual testUtils.wrapInTest("propEqual(variable, 'Literal');"), testUtils.wrapInTest("propEqual(variable, 'Literal', 'Message');"), testUtils.wrapInTest("assert.propEqual(variable, 'Literal');"), - testUtils.wrapInTest("assert.propEqual(variable, 'Literal', 'Message');"), + testUtils.wrapInTest( + "assert.propEqual(variable, 'Literal', 'Message');", + ), // notEqual testUtils.wrapInTest("notEqual(variable, 'Literal');"), testUtils.wrapInTest("notEqual(variable, 'Literal', 'Message');"), testUtils.wrapInTest("assert.notEqual(variable, 'Literal');"), - testUtils.wrapInTest("assert.notEqual(variable, 'Literal', 'Message');"), + testUtils.wrapInTest( + "assert.notEqual(variable, 'Literal', 'Message');", + ), // notStrictEqual testUtils.wrapInTest("notStrictEqual(variable, 'Literal');"), testUtils.wrapInTest("notStrictEqual(variable, 'Literal', 'Message');"), testUtils.wrapInTest("assert.notStrictEqual(variable, 'Literal');"), - testUtils.wrapInTest("assert.notStrictEqual(variable, 'Literal', 'Message');"), + testUtils.wrapInTest( + "assert.notStrictEqual(variable, 'Literal', 'Message');", + ), // notDeepEqual testUtils.wrapInTest("notDeepEqual(variable, 'Literal');"), testUtils.wrapInTest("notDeepEqual(variable, 'Literal', 'Message');"), testUtils.wrapInTest("assert.notDeepEqual(variable, 'Literal');"), - testUtils.wrapInTest("assert.notDeepEqual(variable, 'Literal', 'Message');"), + testUtils.wrapInTest( + "assert.notDeepEqual(variable, 'Literal', 'Message');", + ), // notPropEqual testUtils.wrapInTest("notPropEqual(variable, 'Literal');"), testUtils.wrapInTest("notPropEqual(variable, 'Literal', 'Message');"), testUtils.wrapInTest("assert.notPropEqual(variable, 'Literal');"), - testUtils.wrapInTest("assert.notPropEqual(variable, 'Literal', 'Message');"), + testUtils.wrapInTest( + "assert.notPropEqual(variable, 'Literal', 'Message');", + ), // avoid crash in BDD-style assertions - "QUnit.test('Name', function() { expect(variable).to.equal('Literal'); });" + "QUnit.test('Name', function() { expect(variable).to.equal('Literal'); });", ], invalid: [ // equal { code: testUtils.wrapInTest("equal('Literal', variable);"), output: testUtils.wrapInTest("equal(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], }, { // TypeScript: test callback is adding a type to `this` - code: testUtils.wrapInTest("QUnit.test('test', (this: LocalTestContext) => { equal('Literal', variable); });"), - output: testUtils.wrapInTest("QUnit.test('test', (this: LocalTestContext) => { equal(variable, 'Literal'); });"), + code: testUtils.wrapInTest( + "QUnit.test('test', (this: LocalTestContext) => { equal('Literal', variable); });", + ), + output: testUtils.wrapInTest( + "QUnit.test('test', (this: LocalTestContext) => { equal(variable, 'Literal'); });", + ), parser: require.resolve("@typescript-eslint/parser"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("equal('Literal', variable, 'message');"), - output: testUtils.wrapInTest("equal(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "equal('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "equal(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], }, { code: testUtils.wrapInTest("assert.equal('Literal', variable);"), output: testUtils.wrapInTest("assert.equal(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInArrowTest("assert.equal('Literal', variable);"), - output: testUtils.wrapInArrowTest("assert.equal(variable, 'Literal');"), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInArrowTest( + "assert.equal('Literal', variable);", + ), + output: testUtils.wrapInArrowTest( + "assert.equal(variable, 'Literal');", + ), parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.equal('Literal', variable, 'message');"), - output: testUtils.wrapInTest("assert.equal(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.equal('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "assert.equal(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], }, // strictEqual { code: testUtils.wrapInTest("strictEqual('Literal', variable);"), output: testUtils.wrapInTest("strictEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("strictEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("strictEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.strictEqual('Literal', variable);"), - output: testUtils.wrapInTest("assert.strictEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.strictEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("assert.strictEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "strictEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "strictEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.strictEqual('Literal', variable);", + ), + output: testUtils.wrapInTest( + "assert.strictEqual(variable, 'Literal');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.strictEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "assert.strictEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], }, // deepEqual { code: testUtils.wrapInTest("deepEqual('Literal', variable);"), output: testUtils.wrapInTest("deepEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("deepEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("deepEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.deepEqual('Literal', variable);"), - output: testUtils.wrapInTest("assert.deepEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.deepEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("assert.deepEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "deepEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "deepEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.deepEqual('Literal', variable);", + ), + output: testUtils.wrapInTest( + "assert.deepEqual(variable, 'Literal');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.deepEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "assert.deepEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], }, // propEqual { code: testUtils.wrapInTest("propEqual('Literal', variable);"), output: testUtils.wrapInTest("propEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("propEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("propEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.propEqual('Literal', variable);"), - output: testUtils.wrapInTest("assert.propEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.propEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("assert.propEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "propEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "propEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.propEqual('Literal', variable);", + ), + output: testUtils.wrapInTest( + "assert.propEqual(variable, 'Literal');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.propEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "assert.propEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], }, // notEqual { code: testUtils.wrapInTest("notEqual('Literal', variable);"), output: testUtils.wrapInTest("notEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("notEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("notEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "notEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "notEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], }, { code: testUtils.wrapInTest("assert.notEqual('Literal', variable);"), - output: testUtils.wrapInTest("assert.notEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.notEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("assert.notEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] + output: testUtils.wrapInTest( + "assert.notEqual(variable, 'Literal');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.notEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "assert.notEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], }, // notStrictEqual { code: testUtils.wrapInTest("notStrictEqual('Literal', variable);"), - output: testUtils.wrapInTest("notStrictEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("notStrictEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("notStrictEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.notStrictEqual('Literal', variable);"), - output: testUtils.wrapInTest("assert.notStrictEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.notStrictEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("assert.notStrictEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] + output: testUtils.wrapInTest( + "notStrictEqual(variable, 'Literal');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "notStrictEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "notStrictEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.notStrictEqual('Literal', variable);", + ), + output: testUtils.wrapInTest( + "assert.notStrictEqual(variable, 'Literal');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.notStrictEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "assert.notStrictEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], }, // notDeepEqual { code: testUtils.wrapInTest("notDeepEqual('Literal', variable);"), output: testUtils.wrapInTest("notDeepEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("notDeepEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("notDeepEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.notDeepEqual('Literal', variable);"), - output: testUtils.wrapInTest("assert.notDeepEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.notDeepEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("assert.notDeepEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "notDeepEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "notDeepEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.notDeepEqual('Literal', variable);", + ), + output: testUtils.wrapInTest( + "assert.notDeepEqual(variable, 'Literal');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.notDeepEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "assert.notDeepEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], }, // notPropEqual { code: testUtils.wrapInTest("notPropEqual('Literal', variable);"), output: testUtils.wrapInTest("notPropEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("notPropEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("notPropEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.notPropEqual('Literal', variable);"), - output: testUtils.wrapInTest("assert.notPropEqual(variable, 'Literal');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - }, - { - code: testUtils.wrapInTest("assert.notPropEqual('Literal', variable, 'message');"), - output: testUtils.wrapInTest("assert.notPropEqual(variable, 'Literal', 'message');"), - errors: [{ - messageId: "actualFirst", - data: { - expected: "'Literal'", - actual: "variable" - } - }] - } - ] + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "notPropEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "notPropEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.notPropEqual('Literal', variable);", + ), + output: testUtils.wrapInTest( + "assert.notPropEqual(variable, 'Literal');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + { + code: testUtils.wrapInTest( + "assert.notPropEqual('Literal', variable, 'message');", + ), + output: testUtils.wrapInTest( + "assert.notPropEqual(variable, 'Literal', 'message');", + ), + errors: [ + { + messageId: "actualFirst", + data: { + expected: "'Literal'", + actual: "variable", + }, + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-arrow-tests.js b/tests/lib/rules/no-arrow-tests.js index 88b137e4..4816678a 100644 --- a/tests/lib/rules/no-arrow-tests.js +++ b/tests/lib/rules/no-arrow-tests.js @@ -14,16 +14,14 @@ const rule = require("../../../lib/rules/no-arrow-tests"), RuleTester = require("eslint").RuleTester, outdent = require("outdent"); - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ const ruleTester = new RuleTester({ - parserOptions: { ecmaVersion: 2017 } + parserOptions: { ecmaVersion: 2017 }, }); ruleTester.run("no-arrow-tests", rule, { - valid: [ // tests "QUnit.test('test', function (assert) { assert.ok(true); });", @@ -53,7 +51,7 @@ ruleTester.run("no-arrow-tests", rule, { beforeEach: () => {}, afterEach: () => {} }; - ` + `, ], invalid: [ @@ -61,228 +59,282 @@ ruleTester.run("no-arrow-tests", rule, { { code: "QUnit.test('test', (assert) => { assert.ok(true); });", output: "QUnit.test('test', function(assert) { assert.ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { // TypeScript: test callback is adding a type to `this` code: "QUnit.test('test', (this: LocalTestContext, assert) => { assert.ok(true); });", output: "QUnit.test('test', function(this: LocalTestContext, assert) { assert.ok(true); });", parser: require.resolve("@typescript-eslint/parser"), - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "QUnit.test('test', () => { ok(true); });", output: "QUnit.test('test', function() { ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "QUnit.asyncTest('test', (assert) => { assert.ok(true); });", output: "QUnit.asyncTest('test', function(assert) { assert.ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "QUnit.asyncTest('test', () => { ok(true); });", output: "QUnit.asyncTest('test', function() { ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "test('test', (assert) => { assert.ok(true); });", output: "test('test', function(assert) { assert.ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "test('test', () => { ok(true); });", output: "test('test', function() { ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "asyncTest('test', (assert) => { assert.ok(true); });", output: "asyncTest('test', function(assert) { assert.ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "asyncTest('test', () => { ok(true); });", output: "asyncTest('test', function() { ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, // modules { code: "QUnit.module('module', { setup: () => {} });", output: "QUnit.module('module', { setup: function() {} });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "QUnit.module('module', { teardown: () => {} });", output: "QUnit.module('module', { teardown: function() {} });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "QUnit.module('module', { beforeEach: () => {} });", output: "QUnit.module('module', { beforeEach: function() {} });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "QUnit.module('module', { afterEach: () => {} });", output: "QUnit.module('module', { afterEach: function() {} });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "module('module', { setup: () => {} });", output: "module('module', { setup: function() {} });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "module('module', { teardown: () => {} });", output: "module('module', { teardown: function() {} });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "module('module', { beforeEach: () => {} });", output: "module('module', { beforeEach: function() {} });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "module('module', { afterEach: () => {} });", output: "module('module', { afterEach: function() {} });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, // No function body { code: "QUnit.test('test', () => ok(true));", output: "QUnit.test('test', function() { return ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, // Async function { code: "QUnit.test('test', async () => { assert.ok(false) })", output: "QUnit.test('test', async function() { assert.ok(false) })", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, // Comment placement { code: "QUnit.test('a test 1', /* comment */ assert => { assert.ok(true); });", output: "QUnit.test('a test 1', /* comment */ function(assert) { assert.ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "QUnit.test('a test 2', (assert /* comment */) => { assert.ok(true); });", output: "QUnit.test('a test 2', function(assert /* comment */) { assert.ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "QUnit.test('a test 3', (assert) /* comment */ => { assert.ok(true); });", output: "QUnit.test('a test 3', function(assert)/* comment */ { assert.ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "QUnit.test('a test 4', (assert) => /* comment */ { assert.ok(true); });", output: "QUnit.test('a test 4', function(assert)/* comment */ { assert.ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "QUnit.test('a test 5', (/* assert */) => { noop(); });", output: "QUnit.test('a test 5', function(/* assert */) { noop(); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "QUnit.test('a test 6', assert /* comment */ =>\n{ assert.ok(true); }\n);", output: "QUnit.test('a test 6', function(assert/* comment */) { assert.ok(true); }\n);", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "QUnit.test('a test 7', assert /* comment */ => { assert.ok(true); });", output: "QUnit.test('a test 7', function(assert/* comment */) { assert.ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], }, { code: "QUnit.test('a test 8', assert => /* comment */ { assert.ok(true); });", output: "QUnit.test('a test 8', function(assert)/* comment */ { assert.ok(true); });", - errors: [{ - messageId: "noArrowFunction", - type: "ArrowFunctionExpression" - }] - } - ] + errors: [ + { + messageId: "noArrowFunction", + type: "ArrowFunctionExpression", + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-assert-equal-boolean.js b/tests/lib/rules/no-assert-equal-boolean.js index 6d0aad27..5534a58b 100644 --- a/tests/lib/rules/no-assert-equal-boolean.js +++ b/tests/lib/rules/no-assert-equal-boolean.js @@ -52,7 +52,7 @@ ruleTester.run("no-assert-equal-boolean", rule, { "QUnit.test('Name', function (assert) { assert.propEqual(a, true); });", // not within test context - "equal(a, true);" + "equal(a, true);", ], invalid: [ @@ -60,94 +60,94 @@ ruleTester.run("no-assert-equal-boolean", rule, { { code: "QUnit.test('Name', function (assert) { assert.equal(a, true); });", output: "QUnit.test('Name', function (assert) { assert.true(a); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, { code: "QUnit.test('Name', (assert) => { assert.equal(a, true); });", output: "QUnit.test('Name', (assert) => { assert.true(a); });", parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, { code: "QUnit.test('Name', function (assert) { assert.equal(a, false); });", output: "QUnit.test('Name', function (assert) { assert.false(a); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, // deepEqual { code: "QUnit.test('Name', function (assert) { assert.deepEqual(a, true); });", output: "QUnit.test('Name', function (assert) { assert.true(a); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, // strictEqual { code: "QUnit.test('Name', function (assert) { assert.strictEqual(a, true); });", output: "QUnit.test('Name', function (assert) { assert.true(a); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, // with message param { code: "QUnit.test('Name', function (assert) { assert.equal(a, true, 'msg'); });", output: "QUnit.test('Name', function (assert) { assert.true(a, 'msg'); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, // Boolean as first parameter { code: "QUnit.test('Name', function (assert) { assert.equal(true, b); });", output: "QUnit.test('Name', function (assert) { assert.true(b); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, { code: "QUnit.test('Name', function (assert) { assert.equal(false, b); });", output: "QUnit.test('Name', function (assert) { assert.false(b); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, // multiple booleans { code: "QUnit.test('Name', function (assert) { assert.equal(true, true); });", output: "QUnit.test('Name', function (assert) { assert.true(true); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, { code: "QUnit.test('Name', function (assert) { assert.equal(false, true); });", output: "QUnit.test('Name', function (assert) { assert.false(true); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, { code: "QUnit.test('Name', function (assert) { assert.equal(true, false); });", output: "QUnit.test('Name', function (assert) { assert.true(false); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, { code: "QUnit.test('Name', function (assert) { assert.equal(false, false); });", output: "QUnit.test('Name', function (assert) { assert.false(false); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, // non-standard assert param { code: "QUnit.test('Name', function (foo) { foo.equal(true, b); });", output: "QUnit.test('Name', function (foo) { foo.true(b); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, // assert param but using global assert { code: "QUnit.test('Name', function (assert) { equal(a, true); });", output: "QUnit.test('Name', function (assert) { true(a); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, // using global assert { code: "QUnit.test('Name', function () { equal(a, true); });", output: "QUnit.test('Name', function () { true(a); });", - errors: [{ messageId: "useAssertTrueOrFalse" }] + errors: [{ messageId: "useAssertTrueOrFalse" }], }, // TypeScript: test callback is adding a type to `this` @@ -155,7 +155,7 @@ ruleTester.run("no-assert-equal-boolean", rule, { code: "QUnit.test('Name', function (this: LocalTestContext, assert) { assert.equal(a, true); });", output: "QUnit.test('Name', function (this: LocalTestContext, assert) { assert.true(a); });", parser: require.resolve("@typescript-eslint/parser"), - errors: [{ messageId: "useAssertTrueOrFalse" }] - } - ] + errors: [{ messageId: "useAssertTrueOrFalse" }], + }, + ], }); diff --git a/tests/lib/rules/no-assert-equal.js b/tests/lib/rules/no-assert-equal.js index 603e2251..c9598f7a 100644 --- a/tests/lib/rules/no-assert-equal.js +++ b/tests/lib/rules/no-assert-equal.js @@ -36,142 +36,154 @@ ruleTester.run("no-assert-equal", rule, { // global `equal` but not within test context { code: "equal(a, b);", - globals: { equal: true } + globals: { equal: true }, }, // `equal` but not the global - "function equal(a,b) {}; QUnit.test('Name', function () { equal(a, b); });" + "function equal(a,b) {}; QUnit.test('Name', function () { equal(a, b); });", ], invalid: [ { code: "QUnit.test('Name', function (assert) { assert.equal(a, b); });", - errors: [{ - messageId: "unexpectedAssertEqual", - data: { assertVar: "assert" }, - suggestions: [ - { - messageId: "switchToDeepEqual", - output: "QUnit.test('Name', function (assert) { assert.deepEqual(a, b); });" - }, - { - messageId: "switchToPropEqual", - output: "QUnit.test('Name', function (assert) { assert.propEqual(a, b); });" - }, - { - messageId: "switchToStrictEqual", - output: "QUnit.test('Name', function (assert) { assert.strictEqual(a, b); });" - } - ] - }] + errors: [ + { + messageId: "unexpectedAssertEqual", + data: { assertVar: "assert" }, + suggestions: [ + { + messageId: "switchToDeepEqual", + output: "QUnit.test('Name', function (assert) { assert.deepEqual(a, b); });", + }, + { + messageId: "switchToPropEqual", + output: "QUnit.test('Name', function (assert) { assert.propEqual(a, b); });", + }, + { + messageId: "switchToStrictEqual", + output: "QUnit.test('Name', function (assert) { assert.strictEqual(a, b); });", + }, + ], + }, + ], }, { code: "QUnit.test('Name', (assert) => { assert.equal(a, b); });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedAssertEqual", - data: { assertVar: "assert" }, - suggestions: [ - { - messageId: "switchToDeepEqual", - output: "QUnit.test('Name', (assert) => { assert.deepEqual(a, b); });" - }, - { - messageId: "switchToPropEqual", - output: "QUnit.test('Name', (assert) => { assert.propEqual(a, b); });" - }, - { - messageId: "switchToStrictEqual", - output: "QUnit.test('Name', (assert) => { assert.strictEqual(a, b); });" - } - ] - }] + errors: [ + { + messageId: "unexpectedAssertEqual", + data: { assertVar: "assert" }, + suggestions: [ + { + messageId: "switchToDeepEqual", + output: "QUnit.test('Name', (assert) => { assert.deepEqual(a, b); });", + }, + { + messageId: "switchToPropEqual", + output: "QUnit.test('Name', (assert) => { assert.propEqual(a, b); });", + }, + { + messageId: "switchToStrictEqual", + output: "QUnit.test('Name', (assert) => { assert.strictEqual(a, b); });", + }, + ], + }, + ], }, { code: "QUnit.test('Name', function (foo) { foo.equal(a, b); });", - errors: [{ - messageId: "unexpectedAssertEqual", - data: { assertVar: "foo" }, - suggestions: [ - { - messageId: "switchToDeepEqual", - output: "QUnit.test('Name', function (foo) { foo.deepEqual(a, b); });" - }, - { - messageId: "switchToPropEqual", - output: "QUnit.test('Name', function (foo) { foo.propEqual(a, b); });" - }, - { - messageId: "switchToStrictEqual", - output: "QUnit.test('Name', function (foo) { foo.strictEqual(a, b); });" - } - ] - }] + errors: [ + { + messageId: "unexpectedAssertEqual", + data: { assertVar: "foo" }, + suggestions: [ + { + messageId: "switchToDeepEqual", + output: "QUnit.test('Name', function (foo) { foo.deepEqual(a, b); });", + }, + { + messageId: "switchToPropEqual", + output: "QUnit.test('Name', function (foo) { foo.propEqual(a, b); });", + }, + { + messageId: "switchToStrictEqual", + output: "QUnit.test('Name', function (foo) { foo.strictEqual(a, b); });", + }, + ], + }, + ], }, { code: "QUnit.test('Name', function (assert) { equal(a, b); });", globals: { equal: true }, - errors: [{ - messageId: "unexpectedGlobalEqual", - suggestions: [ - { - messageId: "switchToDeepEqual", - output: "QUnit.test('Name', function (assert) { deepEqual(a, b); });" - }, - { - messageId: "switchToPropEqual", - output: "QUnit.test('Name', function (assert) { propEqual(a, b); });" - }, - { - messageId: "switchToStrictEqual", - output: "QUnit.test('Name', function (assert) { strictEqual(a, b); });" - } - ] - }] + errors: [ + { + messageId: "unexpectedGlobalEqual", + suggestions: [ + { + messageId: "switchToDeepEqual", + output: "QUnit.test('Name', function (assert) { deepEqual(a, b); });", + }, + { + messageId: "switchToPropEqual", + output: "QUnit.test('Name', function (assert) { propEqual(a, b); });", + }, + { + messageId: "switchToStrictEqual", + output: "QUnit.test('Name', function (assert) { strictEqual(a, b); });", + }, + ], + }, + ], }, { code: "QUnit.test('Name', function () { equal(a, b); });", globals: { equal: true }, - errors: [{ - messageId: "unexpectedGlobalEqual", - suggestions: [ - { - messageId: "switchToDeepEqual", - output: "QUnit.test('Name', function () { deepEqual(a, b); });" - }, - { - messageId: "switchToPropEqual", - output: "QUnit.test('Name', function () { propEqual(a, b); });" - }, - { - messageId: "switchToStrictEqual", - output: "QUnit.test('Name', function () { strictEqual(a, b); });" - } - ] - }] + errors: [ + { + messageId: "unexpectedGlobalEqual", + suggestions: [ + { + messageId: "switchToDeepEqual", + output: "QUnit.test('Name', function () { deepEqual(a, b); });", + }, + { + messageId: "switchToPropEqual", + output: "QUnit.test('Name', function () { propEqual(a, b); });", + }, + { + messageId: "switchToStrictEqual", + output: "QUnit.test('Name', function () { strictEqual(a, b); });", + }, + ], + }, + ], }, { // TypeScript: test callback is adding a type to `this` code: "QUnit.test('Name', function (this: LocalTestContext, assert) { assert.equal(a, b); });", parser: require.resolve("@typescript-eslint/parser"), - errors: [{ - messageId: "unexpectedAssertEqual", - data: { assertVar: "assert" }, - suggestions: [ - { - messageId: "switchToDeepEqual", - output: "QUnit.test('Name', function (this: LocalTestContext, assert) { assert.deepEqual(a, b); });" - }, - { - messageId: "switchToPropEqual", - output: "QUnit.test('Name', function (this: LocalTestContext, assert) { assert.propEqual(a, b); });" - }, - { - messageId: "switchToStrictEqual", - output: "QUnit.test('Name', function (this: LocalTestContext, assert) { assert.strictEqual(a, b); });" - } - ] - }] - } - ] + errors: [ + { + messageId: "unexpectedAssertEqual", + data: { assertVar: "assert" }, + suggestions: [ + { + messageId: "switchToDeepEqual", + output: "QUnit.test('Name', function (this: LocalTestContext, assert) { assert.deepEqual(a, b); });", + }, + { + messageId: "switchToPropEqual", + output: "QUnit.test('Name', function (this: LocalTestContext, assert) { assert.propEqual(a, b); });", + }, + { + messageId: "switchToStrictEqual", + output: "QUnit.test('Name', function (this: LocalTestContext, assert) { assert.strictEqual(a, b); });", + }, + ], + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-assert-logical-expression.js b/tests/lib/rules/no-assert-logical-expression.js index c3f9d2d7..6338f9b4 100644 --- a/tests/lib/rules/no-assert-logical-expression.js +++ b/tests/lib/rules/no-assert-logical-expression.js @@ -18,7 +18,6 @@ const rule = require("../../../lib/rules/no-assert-logical-expression"), const ruleTester = new RuleTester(); ruleTester.run("no-assert-logical-expression", rule, { - valid: [ // Simple assertions testUtils.wrapInTest("assert.ok(foo);"), @@ -37,438 +36,538 @@ ruleTester.run("no-assert-logical-expression", rule, { testUtils.wrapInTest("assert.true(foo);"), // Logical expressions inside raises/throw blocks are fine - testUtils.wrapInTest("assert.raises(function () { throw (foo || bar); });"), - testUtils.wrapInTest("assert.throws(function () { throw (foo || bar); });"), + testUtils.wrapInTest( + "assert.raises(function () { throw (foo || bar); });", + ), + testUtils.wrapInTest( + "assert.throws(function () { throw (foo || bar); });", + ), // Messages can have logical expressions. - testUtils.wrapInTest("assert.ok(foo, message || 'alternative message');"), - testUtils.wrapInTest("assert.equal(foo, bar, message || 'alternative message');"), + testUtils.wrapInTest( + "assert.ok(foo, message || 'alternative message');", + ), + testUtils.wrapInTest( + "assert.equal(foo, bar, message || 'alternative message');", + ), // Not an assertion, not in a test - "doSomething(foo && bar);" + "doSomething(foo && bar);", ], invalid: [ { code: testUtils.wrapInTest("assert.ok(foo && bar);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 50 - }] + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 50, + }, + ], }, { // TypeScript: test callback is adding a type to `this` code: "QUnit.test('test', (this: LocalTestContext, assert) => { assert.ok(foo && bar); });", parser: require.resolve("@typescript-eslint/parser"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 68 - }] + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 68, + }, + ], }, { code: testUtils.wrapInArrowTest("assert.ok(foo && bar);"), parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 44 - }] + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 44, + }, + ], }, { code: testUtils.wrapInTest("assert.ok(foo || bar);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 50 - }] + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 50, + }, + ], }, { code: testUtils.wrapInTest("assert.notOk(foo && bar);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 53 - }] + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 53, + }, + ], }, { code: testUtils.wrapInTest("assert.notOk(foo || bar);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 53 - }] + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 53, + }, + ], }, { code: testUtils.wrapInTest("assert.equal(foo && bar, baz && lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 53 - }, { - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 65 - }] + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 53, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 65, + }, + ], }, { code: testUtils.wrapInTest("assert.equal(foo || bar, baz || lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 53 - }, { - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 65 - }] + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 53, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 65, + }, + ], }, { - code: testUtils.wrapInTest("assert.strictEqual(foo && bar, baz && lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 59 - }, { - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 71 - }] + code: testUtils.wrapInTest( + "assert.strictEqual(foo && bar, baz && lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 59, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 71, + }, + ], }, { - code: testUtils.wrapInTest("assert.strictEqual(foo || bar, baz || lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 59 - }, { - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 71 - }] + code: testUtils.wrapInTest( + "assert.strictEqual(foo || bar, baz || lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 59, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 71, + }, + ], }, { - code: testUtils.wrapInTest("assert.deepEqual(foo && bar, baz && lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 57 - }, { - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 69 - }] + code: testUtils.wrapInTest( + "assert.deepEqual(foo && bar, baz && lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 57, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 69, + }, + ], }, { - code: testUtils.wrapInTest("assert.deepEqual(foo || bar, baz || lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 57 - }, { - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 69 - }] + code: testUtils.wrapInTest( + "assert.deepEqual(foo || bar, baz || lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 57, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 69, + }, + ], }, { - code: testUtils.wrapInTest("assert.propEqual(foo && bar, baz && lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 57 - }, { - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 69 - }] + code: testUtils.wrapInTest( + "assert.propEqual(foo && bar, baz && lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 57, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 69, + }, + ], }, { - code: testUtils.wrapInTest("assert.propEqual(foo || bar, baz || lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 57 - }, { - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 69 - }] + code: testUtils.wrapInTest( + "assert.propEqual(foo || bar, baz || lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 57, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 69, + }, + ], }, { - code: testUtils.wrapInTest("assert.notEqual(foo && bar, baz && lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 56 - }, { - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 68 - }] + code: testUtils.wrapInTest( + "assert.notEqual(foo && bar, baz && lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 56, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 68, + }, + ], }, { - code: testUtils.wrapInTest("assert.notEqual(foo || bar, baz || lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 56 - }, { - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 68 - }] + code: testUtils.wrapInTest( + "assert.notEqual(foo || bar, baz || lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 56, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 68, + }, + ], }, { - code: testUtils.wrapInTest("assert.notStrictEqual(foo && bar, baz && lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 62 - }, { - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 74 - }] + code: testUtils.wrapInTest( + "assert.notStrictEqual(foo && bar, baz && lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 62, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 74, + }, + ], }, { - code: testUtils.wrapInTest("assert.notStrictEqual(foo || bar, baz || lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 62 - }, { - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 74 - }] + code: testUtils.wrapInTest( + "assert.notStrictEqual(foo || bar, baz || lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 62, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 74, + }, + ], }, { - code: testUtils.wrapInTest("assert.notDeepEqual(foo && bar, baz && lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 60 - }, { - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 72 - }] + code: testUtils.wrapInTest( + "assert.notDeepEqual(foo && bar, baz && lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 60, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 72, + }, + ], }, { - code: testUtils.wrapInTest("assert.notDeepEqual(foo || bar, baz || lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 60 - }, { - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 72 - }] + code: testUtils.wrapInTest( + "assert.notDeepEqual(foo || bar, baz || lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 60, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 72, + }, + ], }, { - code: testUtils.wrapInTest("assert.notPropEqual(foo && bar, baz && lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 60 - }, { - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 72 - }] + code: testUtils.wrapInTest( + "assert.notPropEqual(foo && bar, baz && lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 60, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 72, + }, + ], }, { - code: testUtils.wrapInTest("assert.notPropEqual(foo || bar, baz || lol);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 60 - }, { - messageId: "noLogicalOperator", - data: { - operator: "||" - }, - type: "LogicalExpression", - line: 1, - column: 72 - }] + code: testUtils.wrapInTest( + "assert.notPropEqual(foo || bar, baz || lol);", + ), + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 60, + }, + { + messageId: "noLogicalOperator", + data: { + operator: "||", + }, + type: "LogicalExpression", + line: 1, + column: 72, + }, + ], }, // Boolean assertions { code: testUtils.wrapInTest("assert.true(foo && bar);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 52 - }] + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 52, + }, + ], }, { code: testUtils.wrapInTest("assert.false(foo && bar);"), - errors: [{ - messageId: "noLogicalOperator", - data: { - operator: "&&" - }, - type: "LogicalExpression", - line: 1, - column: 53 - }] - } - ] + errors: [ + { + messageId: "noLogicalOperator", + data: { + operator: "&&", + }, + type: "LogicalExpression", + line: 1, + column: 53, + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-assert-ok.js b/tests/lib/rules/no-assert-ok.js index 66545168..7c85b99c 100644 --- a/tests/lib/rules/no-assert-ok.js +++ b/tests/lib/rules/no-assert-ok.js @@ -33,88 +33,106 @@ ruleTester.run("no-assert-ok", rule, { "QUnit.test('Name', function () { propEqual(a, b); });", // equal is not within test context - "equal(a, b);" + "equal(a, b);", ], invalid: [ { code: "QUnit.test('Name', function (assert) { assert.ok(a); });", - errors: [{ - messageId: "unexpectedLocalOkNotOk", - data: { - assertVar: "assert", - assertion: "ok" - } - }] + errors: [ + { + messageId: "unexpectedLocalOkNotOk", + data: { + assertVar: "assert", + assertion: "ok", + }, + }, + ], }, { code: "QUnit.test('Name', (assert) => { assert.ok(a); });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedLocalOkNotOk", - data: { - assertVar: "assert", - assertion: "ok" - } - }] + errors: [ + { + messageId: "unexpectedLocalOkNotOk", + data: { + assertVar: "assert", + assertion: "ok", + }, + }, + ], }, { code: "QUnit.test('Name', function (foo) { foo.ok(a); });", - errors: [{ - messageId: "unexpectedLocalOkNotOk", - data: { - assertVar: "foo", - assertion: "ok" - } - }] + errors: [ + { + messageId: "unexpectedLocalOkNotOk", + data: { + assertVar: "foo", + assertion: "ok", + }, + }, + ], }, { code: "QUnit.test('Name', function (assert) { assert.notOk(a); });", - errors: [{ - messageId: "unexpectedLocalOkNotOk", - data: { - assertVar: "assert", - assertion: "notOk" - } - }] + errors: [ + { + messageId: "unexpectedLocalOkNotOk", + data: { + assertVar: "assert", + assertion: "notOk", + }, + }, + ], }, { code: "QUnit.test('Name', function (foo) { foo.notOk(a); });", - errors: [{ - messageId: "unexpectedLocalOkNotOk", - data: { - assertVar: "foo", - assertion: "notOk" - } - }] + errors: [ + { + messageId: "unexpectedLocalOkNotOk", + data: { + assertVar: "foo", + assertion: "notOk", + }, + }, + ], }, { code: "QUnit.test('Name', function (assert) { ok(a, b); });", - errors: [{ - messageId: "unexpectedGlobalOkNotOk", - data: { assertion: "ok" } - }] + errors: [ + { + messageId: "unexpectedGlobalOkNotOk", + data: { assertion: "ok" }, + }, + ], }, { code: "QUnit.test('Name', function (assert) { notOk(a, b); });", - errors: [{ - messageId: "unexpectedGlobalOkNotOk", - data: { assertion: "notOk" } - }] + errors: [ + { + messageId: "unexpectedGlobalOkNotOk", + data: { assertion: "notOk" }, + }, + ], }, { code: "QUnit.test('Name', function () { ok(a, b); });", - errors: [{ - messageId: "unexpectedGlobalOkNotOk", - data: { assertion: "ok" } - }] + errors: [ + { + messageId: "unexpectedGlobalOkNotOk", + data: { assertion: "ok" }, + }, + ], }, { code: "QUnit.test('Name', function () { notOk(a, b); });", - errors: [{ - messageId: "unexpectedGlobalOkNotOk", - data: { assertion: "notOk" } - }] - } - ] + errors: [ + { + messageId: "unexpectedGlobalOkNotOk", + data: { assertion: "notOk" }, + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-async-in-loops.js b/tests/lib/rules/no-async-in-loops.js index 598a05f5..dc1a0756 100644 --- a/tests/lib/rules/no-async-in-loops.js +++ b/tests/lib/rules/no-async-in-loops.js @@ -18,7 +18,6 @@ const rule = require("../../../lib/rules/no-async-in-loops"), const ruleTester = new RuleTester(); ruleTester.run("no-async-in-loops", rule, { - valid: [ // stop()/start() "test('name', function () { stop(); start(); });", @@ -26,639 +25,748 @@ ruleTester.run("no-async-in-loops", rule, { // assert.async() "test('name', function (assert) { var done = assert.async(); });", - "asyncTest('name', function (assert) { var done = assert.async(); });" + "asyncTest('name', function (assert) { var done = assert.async(); });", ], invalid: [ // stop() { code: "test('name', function () { while (false) stop(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { while (false) { stop(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { do stop(); while (false); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "do-while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "do-while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { do { stop(); } while (false); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "do-while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "do-while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (;;) stop(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "for loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "for loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (;;) { stop(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "for loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "for loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i in x) stop(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "for-in loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "for-in loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i in x) { stop(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "for-in loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "for-in loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i of x) stop(); });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "for-of loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "for-of loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i of x) { stop(); } });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "for-of loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "for-of loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, // QUnit.stop() { code: "test('name', function () { while (false) QUnit.stop(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { while (false) { QUnit.stop(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { do QUnit.stop(); while (false); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "do-while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "do-while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { do { QUnit.stop(); } while (false); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "do-while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "do-while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (;;) QUnit.stop(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "for loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "for loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (;;) { QUnit.stop(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "for loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "for loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i in x) QUnit.stop(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "for-in loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "for-in loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i in x) { QUnit.stop(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "for-in loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "for-in loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i of x) QUnit.stop(); });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "for-of loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "for-of loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i of x) { QUnit.stop(); } });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "stop()", - loopTypeText: "for-of loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "stop()", + loopTypeText: "for-of loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, // start() { code: "test('name', function () { while (false) start(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { while (false) { start(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { do start(); while (false); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "do-while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "do-while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { do { start(); } while (false); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "do-while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "do-while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (;;) start(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "for loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "for loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (;;) { start(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "for loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "for loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i in x) start(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "for-in loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "for-in loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i in x) { start(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "for-in loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "for-in loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i of x) start(); });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "for-of loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "for-of loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i of x) { start(); } });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "for-of loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "for-of loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, // QUnit.start() { code: "test('name', function () { while (false) QUnit.start(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { while (false) { QUnit.start(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { do QUnit.start(); while (false); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "do-while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "do-while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { do { QUnit.start(); } while (false); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "do-while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "do-while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (;;) QUnit.start(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "for loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "for loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (;;) { QUnit.start(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "for loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "for loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i in x) QUnit.start(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "for-in loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "for-in loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i in x) { QUnit.start(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "for-in loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "for-in loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i of x) QUnit.start(); });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "for-of loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "for-of loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function () { for (i of x) { QUnit.start(); } });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "start()", - loopTypeText: "for-of loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "start()", + loopTypeText: "for-of loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, // assert.async() { code: "test('name', function (assert) { while (false) assert.async(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "assert.async()", - loopTypeText: "while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "assert.async()", + loopTypeText: "while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { // TypeScript: test callback is adding a type to `this` code: "test('name', function (this: LocalTestContext, assert) { while (false) assert.async(); });", parser: require.resolve("@typescript-eslint/parser"), - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "assert.async()", - loopTypeText: "while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "assert.async()", + loopTypeText: "while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', (assert) => { while (false) assert.async(); });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "assert.async()", - loopTypeText: "while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "assert.async()", + loopTypeText: "while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function (assert) { while (false) { assert.async(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "assert.async()", - loopTypeText: "while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "assert.async()", + loopTypeText: "while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function (assert) { do assert.async(); while (false); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "assert.async()", - loopTypeText: "do-while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "assert.async()", + loopTypeText: "do-while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function (assert) { do { assert.async(); } while (false); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "assert.async()", - loopTypeText: "do-while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "assert.async()", + loopTypeText: "do-while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function (assert) { for (;;) assert.async(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "assert.async()", - loopTypeText: "for loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "assert.async()", + loopTypeText: "for loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function (assert) { for (;;) { assert.async(); } });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "assert.async()", - loopTypeText: "for loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "assert.async()", + loopTypeText: "for loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function (assert) { for (i in x) assert.async(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "assert.async()", - loopTypeText: "for-in loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "assert.async()", + loopTypeText: "for-in loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function (assert) { for (i of x) assert.async(); });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "assert.async()", - loopTypeText: "for-of loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "assert.async()", + loopTypeText: "for-of loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, // assert.async() with other assert context variable { code: "test('name', function (foo) { while (false) foo.async(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "foo.async()", - loopTypeText: "while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "foo.async()", + loopTypeText: "while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function (foo) { do foo.async(); while (false); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "foo.async()", - loopTypeText: "do-while loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "foo.async()", + loopTypeText: "do-while loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function (foo) { for (;;) foo.async(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "foo.async()", - loopTypeText: "for loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "foo.async()", + loopTypeText: "for loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function (foo) { for (i in {}) foo.async(); });", - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "foo.async()", - loopTypeText: "for-in loop" + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "foo.async()", + loopTypeText: "for-in loop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test('name', function (foo) { for (i of {}) foo.async(); });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedAsyncInLoop", - data: { - call: "foo.async()", - loopTypeText: "for-of loop" - }, - type: "CallExpression" - }] - } - ] - + errors: [ + { + messageId: "unexpectedAsyncInLoop", + data: { + call: "foo.async()", + loopTypeText: "for-of loop", + }, + type: "CallExpression", + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-async-module-callbacks.js b/tests/lib/rules/no-async-module-callbacks.js index 89170ab7..787bc3bb 100644 --- a/tests/lib/rules/no-async-module-callbacks.js +++ b/tests/lib/rules/no-async-module-callbacks.js @@ -23,7 +23,6 @@ const messageId = "noAsyncModuleCallbacks"; const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2017 } }); ruleTester.run("no-async-module-callbacks", rule, { - valid: [ "QUnit.module('single argument');", "module('single argument');", @@ -32,33 +31,41 @@ ruleTester.run("no-async-module-callbacks", rule, { "module('module-a', function() { });", "module('module-a', function(hooks) { hooks.beforeEach(function() {}); });", "QUnit.module('module-a', () => { });", - "module('module-a', () => { });" + "module('module-a', () => { });", ], invalid: [ { code: "QUnit.module('module-a', async function () {});", - errors: [{ - messageId - }] + errors: [ + { + messageId, + }, + ], }, { code: "module('module-a', async function () {});", - errors: [{ - messageId - }] + errors: [ + { + messageId, + }, + ], }, { code: "QUnit.module('module-a', async () => {});", - errors: [{ - messageId - }] + errors: [ + { + messageId, + }, + ], }, { code: "module('module-a', async () => {});", - errors: [{ - messageId - }] - } - ] + errors: [ + { + messageId, + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-async-test.js b/tests/lib/rules/no-async-test.js index 10b70221..97dd836f 100644 --- a/tests/lib/rules/no-async-test.js +++ b/tests/lib/rules/no-async-test.js @@ -20,23 +20,27 @@ const ruleTester = new RuleTester(); ruleTester.run("no-async-test", rule, { valid: [ "QUnit.test('a test', function () { });", - "QUnit.test('a test', function () { var done = assert.async(); done(); });" + "QUnit.test('a test', function () { var done = assert.async(); done(); });", ], invalid: [ { code: "asyncTest('a test', function () { });", - errors: [{ - messageId: "unexpectedAsyncTest", - type: "CallExpression" - }] + errors: [ + { + messageId: "unexpectedAsyncTest", + type: "CallExpression", + }, + ], }, { code: "QUnit.asyncTest('a test', function () { });", - errors: [{ - messageId: "unexpectedAsyncTest", - type: "CallExpression" - }] - } - ] + errors: [ + { + messageId: "unexpectedAsyncTest", + type: "CallExpression", + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-commented-tests.js b/tests/lib/rules/no-commented-tests.js index a567e8fe..b0139b66 100644 --- a/tests/lib/rules/no-commented-tests.js +++ b/tests/lib/rules/no-commented-tests.js @@ -18,7 +18,6 @@ const rule = require("../../../lib/rules/no-commented-tests"), const ruleTester = new RuleTester(); ruleTester.run("no-commented-tests", rule, { - valid: [ "QUnit.skip('Name', function () { ok(true); });", @@ -27,7 +26,7 @@ ruleTester.run("no-commented-tests", rule, { // Allow test, parentheses, no quote (https://github.com/platinumazure/eslint-plugin-qunit/issues/61) "// TODO: refactor with a Component test (instead of an Acceptance test)", - "// Run actual test (without context)." + "// Run actual test (without context).", ], invalid: [ @@ -38,12 +37,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "test" + callee: "test", }, line: 1, - column: 4 - } - ] + column: 4, + }, + ], }, { code: "// asyncTest('Name', function () { ok(true); });", @@ -51,12 +50,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "asyncTest" + callee: "asyncTest", }, line: 1, - column: 4 - } - ] + column: 4, + }, + ], }, { code: "// QUnit.test('Name', function () { ok(true); });", @@ -64,12 +63,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.test" + callee: "QUnit.test", }, line: 1, - column: 4 - } - ] + column: 4, + }, + ], }, { code: "// QUnit.asyncTest('Name', function () { ok(true); });", @@ -77,12 +76,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.asyncTest" + callee: "QUnit.asyncTest", }, line: 1, - column: 4 - } - ] + column: 4, + }, + ], }, { code: "// QUnit.skip('Name', function () { ok(true); });", @@ -90,12 +89,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.skip" + callee: "QUnit.skip", }, line: 1, - column: 4 - } - ] + column: 4, + }, + ], }, // Single-line block comments @@ -105,12 +104,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "test" + callee: "test", }, line: 1, - column: 4 - } - ] + column: 4, + }, + ], }, { code: "/* asyncTest('Name', function () { ok(true); }); */", @@ -118,12 +117,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "asyncTest" + callee: "asyncTest", }, line: 1, - column: 4 - } - ] + column: 4, + }, + ], }, { code: "/* QUnit.test('Name', function () { ok(true); }); */", @@ -131,12 +130,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.test" + callee: "QUnit.test", }, line: 1, - column: 4 - } - ] + column: 4, + }, + ], }, { code: "/* QUnit.asyncTest('Name', function () { ok(true); }); */", @@ -144,12 +143,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.asyncTest" + callee: "QUnit.asyncTest", }, line: 1, - column: 4 - } - ] + column: 4, + }, + ], }, { code: "/* QUnit.skip('Name', function () { ok(true); }); */", @@ -157,12 +156,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.skip" + callee: "QUnit.skip", }, line: 1, - column: 4 - } - ] + column: 4, + }, + ], }, // Block comments with line offset (\n) @@ -172,12 +171,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "test" + callee: "test", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, { code: "/**\n\tasyncTest('Name', function () { ok(true); }); */", @@ -185,12 +184,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "asyncTest" + callee: "asyncTest", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, { code: "/**\n\tQUnit.test('Name', function () { ok(true); }); */", @@ -198,12 +197,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.test" + callee: "QUnit.test", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, { code: "/**\n\tQUnit.asyncTest('Name', function () { ok(true); }); */", @@ -211,12 +210,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.asyncTest" + callee: "QUnit.asyncTest", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, { code: "/**\n\tQUnit.skip('Name', function () { ok(true); }); */", @@ -224,12 +223,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.skip" + callee: "QUnit.skip", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, // Block comments with line offset (\r) @@ -239,12 +238,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "test" + callee: "test", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, { code: "/**\r\tasyncTest('Name', function () { ok(true); }); */", @@ -252,12 +251,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "asyncTest" + callee: "asyncTest", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, { code: "/**\r\tQUnit.test('Name', function () { ok(true); }); */", @@ -265,12 +264,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.test" + callee: "QUnit.test", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, { code: "/**\r\tQUnit.asyncTest('Name', function () { ok(true); }); */", @@ -278,12 +277,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.asyncTest" + callee: "QUnit.asyncTest", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, { code: "/**\r\tQUnit.skip('Name', function () { ok(true); }); */", @@ -291,12 +290,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.skip" + callee: "QUnit.skip", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, // Block comments with line offset (\r\n) @@ -306,12 +305,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "test" + callee: "test", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, { code: "/**\r\n\tasyncTest('Name', function () { ok(true); }); */", @@ -319,12 +318,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "asyncTest" + callee: "asyncTest", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, { code: "/**\r\n\tQUnit.test('Name', function () { ok(true); }); */", @@ -332,12 +331,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.test" + callee: "QUnit.test", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, { code: "/**\r\n\tQUnit.asyncTest('Name', function () { ok(true); }); */", @@ -345,12 +344,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.asyncTest" + callee: "QUnit.asyncTest", }, line: 2, - column: 2 - } - ] + column: 2, + }, + ], }, { code: "/**\r\n\tQUnit.skip('Name', function () { ok(true); }); */", @@ -358,13 +357,12 @@ ruleTester.run("no-commented-tests", rule, { { messageId: "unexpectedTestInComment", data: { - callee: "QUnit.skip" + callee: "QUnit.skip", }, line: 2, - column: 2 - } - ] - } - ] - + column: 2, + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-compare-relation-boolean.js b/tests/lib/rules/no-compare-relation-boolean.js index b6689225..7dc4ffc7 100644 --- a/tests/lib/rules/no-compare-relation-boolean.js +++ b/tests/lib/rules/no-compare-relation-boolean.js @@ -17,12 +17,17 @@ const rule = require("../../../lib/rules/no-compare-relation-boolean"), //------------------------------------------------------------------------------ function addErrors(testCase) { - return Object.assign({ - errors: [{ - messageId: "redundantComparison", - type: "CallExpression" - }] - }, testCase); + return Object.assign( + { + errors: [ + { + messageId: "redundantComparison", + type: "CallExpression", + }, + ], + }, + testCase, + ); } //------------------------------------------------------------------------------ @@ -49,182 +54,194 @@ ruleTester.run("no-compare-relation-boolean", rule, { // Not enough arguments "assert.strictEqual();", - "assert.strictEqual(a);" - ].map(code => testUtils.wrapInTest(code)), + "assert.strictEqual(a);", + ].map((code) => testUtils.wrapInTest(code)), invalid: [ { code: testUtils.wrapInTest("assert.equal(a === b, true);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { // TypeScript: test callback is adding a type to `this` code: "QUnit.test('test', (this: LocalTestContext, assert) => { assert.equal(a === b, true); });", output: "QUnit.test('test', (this: LocalTestContext, assert) => { assert.ok(a === b); });", - parser: require.resolve("@typescript-eslint/parser") + parser: require.resolve("@typescript-eslint/parser"), }, { code: testUtils.wrapInArrowTest("assert.equal(a === b, true);"), output: testUtils.wrapInArrowTest("assert.ok(a === b);"), - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { code: testUtils.wrapInTest("assert.equal(a === b, false);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { - code: testUtils.wrapInTest("assert.equal(a === b, true, 'message');"), // With message - output: testUtils.wrapInTest("assert.ok(a === b, 'message');") + code: testUtils.wrapInTest( + "assert.equal(a === b, true, 'message');", + ), // With message + output: testUtils.wrapInTest("assert.ok(a === b, 'message');"), }, { - code: testUtils.wrapInTest("assert.equal(a === b, false, 'message');"), // With message - output: testUtils.wrapInTest("assert.notOk(a === b, 'message');") + code: testUtils.wrapInTest( + "assert.equal(a === b, false, 'message');", + ), // With message + output: testUtils.wrapInTest("assert.notOk(a === b, 'message');"), }, { code: testUtils.wrapInTest("assert.strictEqual(a === b, true);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { code: testUtils.wrapInTest("assert.strictEqual(a === b, false);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { code: testUtils.wrapInTest("assert.deepEqual(a === b, true);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { code: testUtils.wrapInTest("assert.deepEqual(a === b, false);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { code: testUtils.wrapInTest("assert.propEqual(a === b, true);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { code: testUtils.wrapInTest("assert.propEqual(a === b, false);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { code: testUtils.wrapInTest("assert.notEqual(a === b, true);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { code: testUtils.wrapInTest("assert.notEqual(a === b, false);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { code: testUtils.wrapInTest("assert.notStrictEqual(a === b, true);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { - code: testUtils.wrapInTest("assert.notStrictEqual(a === b, false);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + code: testUtils.wrapInTest( + "assert.notStrictEqual(a === b, false);", + ), + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { code: testUtils.wrapInTest("assert.notDeepEqual(a === b, true);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { code: testUtils.wrapInTest("assert.notDeepEqual(a === b, false);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { code: testUtils.wrapInTest("assert.notPropEqual(a === b, true);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { code: testUtils.wrapInTest("assert.notPropEqual(a === b, false);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + output: testUtils.wrapInTest("assert.ok(a === b);"), }, // Argument order does not matter for this rule { code: testUtils.wrapInTest("assert.equal(true, a === b);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { code: testUtils.wrapInTest("assert.equal(false, a === b);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { - code: testUtils.wrapInTest("assert.equal(true, a === b, 'message');"), // With message - output: testUtils.wrapInTest("assert.ok(a === b, 'message');") + code: testUtils.wrapInTest( + "assert.equal(true, a === b, 'message');", + ), // With message + output: testUtils.wrapInTest("assert.ok(a === b, 'message');"), }, { - code: testUtils.wrapInTest("assert.equal(false, a === b, 'message');"), // With message - output: testUtils.wrapInTest("assert.notOk(a === b, 'message');") + code: testUtils.wrapInTest( + "assert.equal(false, a === b, 'message');", + ), // With message + output: testUtils.wrapInTest("assert.notOk(a === b, 'message');"), }, { code: testUtils.wrapInTest("assert.strictEqual(true, a === b);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { code: testUtils.wrapInTest("assert.strictEqual(false, a === b);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { code: testUtils.wrapInTest("assert.deepEqual(true, a === b);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { code: testUtils.wrapInTest("assert.deepEqual(false, a === b);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { code: testUtils.wrapInTest("assert.propEqual(true, a === b);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { code: testUtils.wrapInTest("assert.propEqual(false, a === b);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { code: testUtils.wrapInTest("assert.notEqual(true, a === b);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { code: testUtils.wrapInTest("assert.notEqual(false, a === b);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { code: testUtils.wrapInTest("assert.notStrictEqual(true, a === b);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { - code: testUtils.wrapInTest("assert.notStrictEqual(false, a === b);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + code: testUtils.wrapInTest( + "assert.notStrictEqual(false, a === b);", + ), + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { code: testUtils.wrapInTest("assert.notDeepEqual(true, a === b);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { code: testUtils.wrapInTest("assert.notDeepEqual(false, a === b);"), - output: testUtils.wrapInTest("assert.ok(a === b);") + output: testUtils.wrapInTest("assert.ok(a === b);"), }, { code: testUtils.wrapInTest("assert.notPropEqual(true, a === b);"), - output: testUtils.wrapInTest("assert.notOk(a === b);") + output: testUtils.wrapInTest("assert.notOk(a === b);"), }, { code: testUtils.wrapInTest("assert.notPropEqual(false, a === b);"), - output: testUtils.wrapInTest("assert.ok(a === b);") - } - ].map(testCase => addErrors(testCase)) + output: testUtils.wrapInTest("assert.ok(a === b);"), + }, + ].map((testCase) => addErrors(testCase)), }); diff --git a/tests/lib/rules/no-conditional-assertions.js b/tests/lib/rules/no-conditional-assertions.js index 2423791f..95e22606 100644 --- a/tests/lib/rules/no-conditional-assertions.js +++ b/tests/lib/rules/no-conditional-assertions.js @@ -19,10 +19,12 @@ const rule = require("../../../lib/rules/no-conditional-assertions"), function wrapInInvalidTestObject(code) { return { code: code, - errors: [{ - messageId: "noAssertionInsideConditional", - type: "CallExpression" - }] + errors: [ + { + messageId: "noAssertionInsideConditional", + type: "CallExpression", + }, + ], }; } @@ -32,7 +34,6 @@ function wrapInInvalidTestObject(code) { const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); ruleTester.run("no-conditional-assertions", rule, { - valid: [ ...[ // Unconditional assertions are good @@ -58,11 +59,11 @@ ruleTester.run("no-conditional-assertions", rule, { // Conditions around non-assertions are okay "if (foo) doSomething();", "foo ? doSomething() : false;", - "foo ? false : doSomething();" - ].map(code => testUtils.wrapInTest(code)), + "foo ? false : doSomething();", + ].map((code) => testUtils.wrapInTest(code)), // Conditional tests are okay - "if (foo) QUnit.test('test', function (assert) { assert.ok(true); });" + "if (foo) QUnit.test('test', function (assert) { assert.ok(true); });", ], invalid: [ @@ -73,6 +74,6 @@ ruleTester.run("no-conditional-assertions", rule, { testUtils.wrapInTest("if (foo) {} else if (bar) assert.ok(true);"), testUtils.wrapInTest("if (foo) {} else assert.ok(true);"), testUtils.wrapInTest("foo ? assert.ok(true) : false"), - testUtils.wrapInTest("foo ? false : assert.ok(true)") - ].map(code => wrapInInvalidTestObject(code)) + testUtils.wrapInTest("foo ? false : assert.ok(true)"), + ].map((code) => wrapInInvalidTestObject(code)), }); diff --git a/tests/lib/rules/no-early-return.js b/tests/lib/rules/no-early-return.js index 093caea7..eb6b8cdc 100644 --- a/tests/lib/rules/no-early-return.js +++ b/tests/lib/rules/no-early-return.js @@ -11,7 +11,6 @@ const rule = require("../../../lib/rules/no-early-return"), RuleTester = require("eslint").RuleTester; - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ @@ -24,7 +23,7 @@ ruleTester.run("no-early-return", rule, { "QUnit.test('a test', function (assert) { (function () { return; })(); assert.ok(true); });", { code: "QUnit.test('a test', function (assert) { () => { return; }; assert.ok(true); });", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, // Inside nested function (assertions inside nested function before return) @@ -32,7 +31,7 @@ ruleTester.run("no-early-return", rule, { "QUnit.test('a test', function (assert) { (function () { assert.ok(true); return; })(); });", { code: "QUnit.test('a test', function (assert) { () => { assert.ok(true); return; }; });", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, // Conditionally run tests are okay @@ -40,67 +39,80 @@ ruleTester.run("no-early-return", rule, { "if (shouldRunTest()) { QUnit.test('a test', function (assert) { assert.ok(true); }); }", // Return statement outside of test is fine - "(function () { return true; }());" + "(function () { return true; }());", ], invalid: [ { code: "QUnit.test('a test', function (assert) { if (true) return; assert.ok(true); });", - errors: [{ - messageId: "noEarlyReturn", - type: "ReturnStatement" - }] + errors: [ + { + messageId: "noEarlyReturn", + type: "ReturnStatement", + }, + ], }, { // TypeScript: test callback is adding a type to `this` code: "QUnit.test('a test', function (this: LocalTestContext, assert) { if (true) return; assert.ok(true); });", parser: require.resolve("@typescript-eslint/parser"), - errors: [{ - messageId: "noEarlyReturn", - type: "ReturnStatement" - }] + errors: [ + { + messageId: "noEarlyReturn", + type: "ReturnStatement", + }, + ], }, { code: "QUnit.test('a test', (assert) => { if (true) return; assert.ok(true); });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "noEarlyReturn", - type: "ReturnStatement" - }] + errors: [ + { + messageId: "noEarlyReturn", + type: "ReturnStatement", + }, + ], }, // Return in nested function before assertion is considered early return { code: "QUnit.test('a test', function (assert) { setTimeout(function () { if (true) return; assert.ok(true); }, 0); });", - errors: [{ - messageId: "noEarlyReturn", - type: "ReturnStatement" - }] + errors: [ + { + messageId: "noEarlyReturn", + type: "ReturnStatement", + }, + ], }, { code: "QUnit.test('a test', function (assert) { setTimeout(function () { assert.ok(true); if (true) return; assert.ok(true); }, 0); });", - errors: [{ - messageId: "noEarlyReturn", - type: "ReturnStatement" - }] + errors: [ + { + messageId: "noEarlyReturn", + type: "ReturnStatement", + }, + ], }, // Report errors in multiple scopes with assertions { code: "QUnit.test('a test', function (assert) { setTimeout(function () { return; assert.ok(true); }, 0); return; assert.ok(true); });", - errors: [{ - messageId: "noEarlyReturn", - type: "ReturnStatement", - line: 1, - column: 67 - }, { - messageId: "noEarlyReturn", - type: "ReturnStatement", - line: 1, - column: 99 - }] - } - ] + errors: [ + { + messageId: "noEarlyReturn", + type: "ReturnStatement", + line: 1, + column: 67, + }, + { + messageId: "noEarlyReturn", + type: "ReturnStatement", + line: 1, + column: 99, + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-global-assertions.js b/tests/lib/rules/no-global-assertions.js index abddf9ff..d1680d03 100644 --- a/tests/lib/rules/no-global-assertions.js +++ b/tests/lib/rules/no-global-assertions.js @@ -12,7 +12,6 @@ const rule = require("../../../lib/rules/no-global-assertions"), RuleTester = require("eslint").RuleTester, testUtils = require("../../testUtils"); - //------------------------------------------------------------------------------ // Helpers //------------------------------------------------------------------------------ @@ -21,8 +20,8 @@ function createError(assertion) { return { messageId: "unexpectedGlobalAssertion", data: { - assertion - } + assertion, + }, }; } @@ -52,68 +51,68 @@ ruleTester.run("no-global-assertions", rule, { // Global overridden by local import/declaration. { code: "var strictEqual = require('foo'); strictEqual();", - globals: { strictEqual: true } + globals: { strictEqual: true }, }, // Intentionally not covered by this rule - testUtils.wrapInTest("expect(1);") + testUtils.wrapInTest("expect(1);"), ], invalid: [ { code: testUtils.wrapInTest("ok(true);"), globals: { ok: true }, - errors: [createError("ok")] + errors: [createError("ok")], }, { code: testUtils.wrapInTest("equal(a, b);"), globals: { equal: true }, - errors: [createError("equal")] + errors: [createError("equal")], }, { code: testUtils.wrapInTest("strictEqual(a, b);"), globals: { strictEqual: true }, - errors: [createError("strictEqual")] + errors: [createError("strictEqual")], }, { code: testUtils.wrapInTest("deepEqual(a, b);"), globals: { deepEqual: true }, - errors: [createError("deepEqual")] + errors: [createError("deepEqual")], }, { code: testUtils.wrapInTest("propEqual(a, b);"), globals: { propEqual: true }, - errors: [createError("propEqual")] + errors: [createError("propEqual")], }, { code: testUtils.wrapInTest("notEqual(a, b);"), globals: { notEqual: true }, - errors: [createError("notEqual")] + errors: [createError("notEqual")], }, { code: testUtils.wrapInTest("notStrictEqual(a, b);"), globals: { notStrictEqual: true }, - errors: [createError("notStrictEqual")] + errors: [createError("notStrictEqual")], }, { code: testUtils.wrapInTest("notDeepEqual(a, b);"), globals: { notDeepEqual: true }, - errors: [createError("notDeepEqual")] + errors: [createError("notDeepEqual")], }, { code: testUtils.wrapInTest("notPropEqual(a, b);"), globals: { notPropEqual: true }, - errors: [createError("notPropEqual")] + errors: [createError("notPropEqual")], }, { code: testUtils.wrapInTest("raises(function () {}, TypeError);"), globals: { raises: true }, - errors: [createError("raises")] + errors: [createError("raises")], }, { code: testUtils.wrapInTest("throws(function () {}, TypeError);"), globals: { throws: true }, - errors: [createError("throws")] - } - ] + errors: [createError("throws")], + }, + ], }); diff --git a/tests/lib/rules/no-global-expect.js b/tests/lib/rules/no-global-expect.js index 643ceec9..93117f5c 100644 --- a/tests/lib/rules/no-global-expect.js +++ b/tests/lib/rules/no-global-expect.js @@ -12,7 +12,6 @@ const rule = require("../../../lib/rules/no-global-expect"), RuleTester = require("eslint").RuleTester, testUtils = require("../../testUtils"); - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ @@ -20,8 +19,8 @@ const rule = require("../../../lib/rules/no-global-expect"), const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015, - sourceType: "module" - } + sourceType: "module", + }, }); ruleTester.run("no-global-expect", rule, { @@ -29,40 +28,50 @@ ruleTester.run("no-global-expect", rule, { testUtils.wrapInTest("assert.expect(1);"), { code: testUtils.wrapInTest("assert.expect(1);"), - globals: { expect: true } + globals: { expect: true }, }, // Global overridden by local import/declaration. { - code: `import expect from 'foo'; ${testUtils.wrapInTest("expect(1);")}`, - globals: { expect: true } + code: `import expect from 'foo'; ${testUtils.wrapInTest( + "expect(1);", + )}`, + globals: { expect: true }, }, { - code: `import { expect } from 'foo'; ${testUtils.wrapInTest("expect(1);")}`, - globals: { expect: true } + code: `import { expect } from 'foo'; ${testUtils.wrapInTest( + "expect(1);", + )}`, + globals: { expect: true }, }, { - code: `var expect = require('foo'); ${testUtils.wrapInTest("expect(1);")}`, - globals: { expect: true } + code: `var expect = require('foo'); ${testUtils.wrapInTest( + "expect(1);", + )}`, + globals: { expect: true }, }, { - code: `var expect = () => {}; ${testUtils.wrapInTest("expect(1);")}`, - globals: { expect: true } + code: `var expect = () => {}; ${testUtils.wrapInTest( + "expect(1);", + )}`, + globals: { expect: true }, }, { code: `function expect() {}; ${testUtils.wrapInTest("expect(1);")}`, - globals: { expect: true } - } + globals: { expect: true }, + }, ], invalid: [ { code: testUtils.wrapInTest("expect(1)"), globals: { expect: true }, - errors: [{ - messageId: "unexpectedGlobalExpect", - type: "CallExpression" - }] - } - ] + errors: [ + { + messageId: "unexpectedGlobalExpect", + type: "CallExpression", + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-global-module-test.js b/tests/lib/rules/no-global-module-test.js index 53682be6..251b8348 100644 --- a/tests/lib/rules/no-global-module-test.js +++ b/tests/lib/rules/no-global-module-test.js @@ -29,43 +29,49 @@ ruleTester.run("no-global-module-test", rule, { // Global overridden by local import/declaration. { code: "var module = require('foo'); module();", - globals: { module: true } - } + globals: { module: true }, + }, ], invalid: [ { code: "module();", globals: { module: true }, - errors: [{ - messageId: "unexpectedGlobalModuleTest", - data: { - callee: "module" + errors: [ + { + messageId: "unexpectedGlobalModuleTest", + data: { + callee: "module", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "test();", globals: { test: true }, - errors: [{ - messageId: "unexpectedGlobalModuleTest", - data: { - callee: "test" + errors: [ + { + messageId: "unexpectedGlobalModuleTest", + data: { + callee: "test", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "asyncTest();", globals: { asyncTest: true }, - errors: [{ - messageId: "unexpectedGlobalModuleTest", - data: { - callee: "asyncTest" + errors: [ + { + messageId: "unexpectedGlobalModuleTest", + data: { + callee: "asyncTest", + }, + type: "CallExpression", }, - type: "CallExpression" - }] - } - ] + ], + }, + ], }); diff --git a/tests/lib/rules/no-global-stop-start.js b/tests/lib/rules/no-global-stop-start.js index e1c84dd4..c5facc8b 100644 --- a/tests/lib/rules/no-global-stop-start.js +++ b/tests/lib/rules/no-global-stop-start.js @@ -13,14 +13,12 @@ const rule = require("../../../lib/rules/no-global-stop-start"), RuleTester = require("eslint").RuleTester; - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ const ruleTester = new RuleTester(); ruleTester.run("no-global-stop-start", rule, { - valid: [ "QUnit.stop();", "QUnit.start();", @@ -28,32 +26,36 @@ ruleTester.run("no-global-stop-start", rule, { // Global overridden by local import/declaration. { code: "var start = require('foo'); start();", - globals: { start: true } - } + globals: { start: true }, + }, ], invalid: [ { code: "stop();", globals: { stop: true }, - errors: [{ - messageId: "unexpectedGlobalStopStart", - data: { - callee: "stop" + errors: [ + { + messageId: "unexpectedGlobalStopStart", + data: { + callee: "stop", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "start();", globals: { start: true }, - errors: [{ - messageId: "unexpectedGlobalStopStart", - data: { - callee: "start" + errors: [ + { + messageId: "unexpectedGlobalStopStart", + data: { + callee: "start", + }, + type: "CallExpression", }, - type: "CallExpression" - }] - } - ] + ], + }, + ], }); diff --git a/tests/lib/rules/no-hooks-from-ancestor-modules.js b/tests/lib/rules/no-hooks-from-ancestor-modules.js index f4e44787..d85dfed1 100644 --- a/tests/lib/rules/no-hooks-from-ancestor-modules.js +++ b/tests/lib/rules/no-hooks-from-ancestor-modules.js @@ -20,9 +20,9 @@ function createError({ invokedMethodName, usedHooksIdentifierName }) { messageId: "noHooksFromAncestorModules", data: { invokedMethodName, - usedHooksIdentifierName + usedHooksIdentifierName, }, - type: "MemberExpression" + type: "MemberExpression", }; } @@ -32,7 +32,6 @@ function createError({ invokedMethodName, usedHooksIdentifierName }) { const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: "latest" } }); ruleTester.run("no-hooks-from-ancestor-modules", rule, { - valid: [ "QUnit.testDone(function() {});", ` @@ -131,9 +130,9 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, { { // TypeScript: module callback is adding a type to `this` - code: "QUnit.module(\"module\", function(this: LocalTestContext, hooks) { hooks.afterEach(function() {}); });", - parser: require.resolve("@typescript-eslint/parser") - } + code: 'QUnit.module("module", function(this: LocalTestContext, hooks) { hooks.afterEach(function() {}); });', + parser: require.resolve("@typescript-eslint/parser"), + }, ], invalid: [ @@ -148,9 +147,9 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, { errors: [ createError({ invokedMethodName: "beforeEach", - usedHooksIdentifierName: "hooks" - }) - ] + usedHooksIdentifierName: "hooks", + }), + ], }, { code: ` @@ -163,9 +162,9 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, { errors: [ createError({ invokedMethodName: "beforeEach", - usedHooksIdentifierName: "hooks" - }) - ] + usedHooksIdentifierName: "hooks", + }), + ], }, { code: ` @@ -178,9 +177,9 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, { errors: [ createError({ invokedMethodName: "beforeEach", - usedHooksIdentifierName: "hooks" - }) - ] + usedHooksIdentifierName: "hooks", + }), + ], }, { code: ` @@ -193,9 +192,9 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, { errors: [ createError({ invokedMethodName: "afterEach", - usedHooksIdentifierName: "firstHooks" - }) - ] + usedHooksIdentifierName: "firstHooks", + }), + ], }, { code: ` @@ -208,9 +207,9 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, { errors: [ createError({ invokedMethodName: "afterEach", - usedHooksIdentifierName: "hooks" - }) - ] + usedHooksIdentifierName: "hooks", + }), + ], }, { code: ` @@ -223,9 +222,9 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, { errors: [ createError({ invokedMethodName: "afterEach", - usedHooksIdentifierName: "hooks" - }) - ] + usedHooksIdentifierName: "hooks", + }), + ], }, { code: ` @@ -245,9 +244,9 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, { errors: [ createError({ invokedMethodName: "beforeEach", - usedHooksIdentifierName: "firstHooks" - }) - ] + usedHooksIdentifierName: "firstHooks", + }), + ], }, // https://github.com/platinumazure/eslint-plugin-qunit/issues/246 @@ -262,9 +261,9 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, { errors: [ createError({ invokedMethodName: "beforeEach", - usedHooksIdentifierName: "hooks" - }) - ] + usedHooksIdentifierName: "hooks", + }), + ], }, { code: ` @@ -277,9 +276,9 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, { errors: [ createError({ invokedMethodName: "beforeEach", - usedHooksIdentifierName: "hooks" - }) - ] + usedHooksIdentifierName: "hooks", + }), + ], }, { @@ -295,9 +294,9 @@ ruleTester.run("no-hooks-from-ancestor-modules", rule, { errors: [ createError({ invokedMethodName: "afterEach", - usedHooksIdentifierName: "hooks" - }) - ] - } - ] + usedHooksIdentifierName: "hooks", + }), + ], + }, + ], }); diff --git a/tests/lib/rules/no-identical-names.js b/tests/lib/rules/no-identical-names.js index b467666e..c8067511 100644 --- a/tests/lib/rules/no-identical-names.js +++ b/tests/lib/rules/no-identical-names.js @@ -15,7 +15,6 @@ const rule = require("../../../lib/rules/no-identical-names"), const ruleTester = new RuleTester(); ruleTester.run("no-identical-title", rule, { - valid: [ outdent` module("module"); @@ -83,13 +82,13 @@ ruleTester.run("no-identical-title", rule, { }); `, { - code: outdent ` + code: outdent` test(\`it$\{n\}\`, function() {}); test(\`it$\{n\}\`, function() {}); `, parserOptions: { - ecmaVersion: 6 - } + ecmaVersion: 6, + }, }, // Tests with identical names are allowed if they are in different modules. @@ -139,86 +138,96 @@ ruleTester.run("no-identical-title", rule, { }); }); }); - ` + `, ], invalid: [ { - code: outdent ` + code: outdent` module("module1"); test("it1", function() {}); test("it1", function() {}); `, - errors: [{ - messageId: "duplicateTest", - data: { - line: 2 + errors: [ + { + messageId: "duplicateTest", + data: { + line: 2, + }, + column: 6, + line: 3, }, - column: 6, - line: 3 - }] + ], }, { - code: outdent ` + code: outdent` test("it1", function() {}); test("it1", function() {}); `, - errors: [{ - messageId: "duplicateTest", - data: { - line: 1 + errors: [ + { + messageId: "duplicateTest", + data: { + line: 1, + }, + column: 6, + line: 2, }, - column: 6, - line: 2 - }] + ], }, { - code: outdent ` + code: outdent` module("module1", function() { test("it1", function() {}); test("it1", function() {}); }); `, - errors: [{ - messageId: "duplicateTest", - data: { - line: 2 + errors: [ + { + messageId: "duplicateTest", + data: { + line: 2, + }, + column: 8, + line: 3, }, - column: 8, - line: 3 - }] + ], }, { - code: outdent ` + code: outdent` module("module1"); module("module1"); `, - errors: [{ - messageId: "duplicateModule", - data: { - line: 1 + errors: [ + { + messageId: "duplicateModule", + data: { + line: 1, + }, + column: 8, + line: 2, }, - column: 8, - line: 2 - }] + ], }, { - code: outdent ` + code: outdent` module("module1"); test("it", function() {}); module("module1"); `, - errors: [{ - messageId: "duplicateModule", - data: { - line: 1 + errors: [ + { + messageId: "duplicateModule", + data: { + line: 1, + }, + column: 8, + line: 3, }, - column: 8, - line: 3 - }] + ], }, { - code: outdent ` + code: outdent` module("module1", function() { module("module2", function() { test("it", function() {}); @@ -226,15 +235,17 @@ ruleTester.run("no-identical-title", rule, { }); }); `, - errors: [{ - messageId: "duplicateTest", - data: { line: 3 }, - column: 14, - line: 4 - }] + errors: [ + { + messageId: "duplicateTest", + data: { line: 3 }, + column: 14, + line: 4, + }, + ], }, { - code: outdent ` + code: outdent` test("it", function() {}); // Module with test deep inside it. @@ -246,26 +257,30 @@ ruleTester.run("no-identical-title", rule, { test("it", function() {}); `, - errors: [{ - messageId: "duplicateTest", - data: { line: 1 }, - column: 6, - line: 10 - }] + errors: [ + { + messageId: "duplicateTest", + data: { line: 1 }, + column: 6, + line: 10, + }, + ], }, { - code: outdent ` + code: outdent` module("module1", function() { module("submodule1", function() {}); module("submodule1", function() {}); }); `, - errors: [{ - messageId: "duplicateModule", - data: { line: 2 }, - column: 12, - line: 3 - }] + errors: [ + { + messageId: "duplicateModule", + data: { line: 2 }, + column: 12, + line: 3, + }, + ], }, { code: outdent` @@ -273,12 +288,14 @@ ruleTester.run("no-identical-title", rule, { module("name1", function() {}); }); `, - errors: [{ - messageId: "duplicateModuleAncestor", - data: { line: 1 }, - column: 12, - line: 2 - }] - } - ] + errors: [ + { + messageId: "duplicateModuleAncestor", + data: { line: 1 }, + column: 12, + line: 2, + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-init.js b/tests/lib/rules/no-init.js index 453b758d..816918af 100644 --- a/tests/lib/rules/no-init.js +++ b/tests/lib/rules/no-init.js @@ -13,29 +13,29 @@ const rule = require("../../../lib/rules/no-init"), RuleTester = require("eslint").RuleTester; - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ const ruleTester = new RuleTester(); ruleTester.run("no-init", rule, { - valid: [ // Only invocations are reported "QUnit.init", // Only QUnit.init() is reported - "QUnit.reset()" + "QUnit.reset()", ], invalid: [ { code: "QUnit.init();", - errors: [{ - messageId: "noInit", - type: "CallExpression" - }] - } - ] + errors: [ + { + messageId: "noInit", + type: "CallExpression", + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-jsdump.js b/tests/lib/rules/no-jsdump.js index a82e737b..e58d029e 100644 --- a/tests/lib/rules/no-jsdump.js +++ b/tests/lib/rules/no-jsdump.js @@ -17,18 +17,17 @@ const rule = require("../../../lib/rules/no-jsdump"), const ruleTester = new RuleTester(); ruleTester.run("no-jsdump", rule, { - - valid: [ - "QUnit.dump(obj);" - ], + valid: ["QUnit.dump(obj);"], invalid: [ { code: "QUnit.jsDump(obj);", - errors: [{ - messageId: "noJsDump", - type: "CallExpression" - }] - } - ] + errors: [ + { + messageId: "noJsDump", + type: "CallExpression", + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-loose-assertions.js b/tests/lib/rules/no-loose-assertions.js index 1c3eab56..02803cd6 100644 --- a/tests/lib/rules/no-loose-assertions.js +++ b/tests/lib/rules/no-loose-assertions.js @@ -33,115 +33,139 @@ ruleTester.run("no-loose-assertions", rule, { "QUnit.test('Name', function () { propEqual(a, b); });", // equal is not within test context - "equal(a, b);" + "equal(a, b);", ], invalid: [ { code: "QUnit.test('Name', function (assert) { assert.ok(a); });", - errors: [{ - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "assert", - assertion: "ok" - } - }] + errors: [ + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "assert", + assertion: "ok", + }, + }, + ], }, { code: "QUnit.test('Name', (assert) => { assert.ok(a); });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "assert", - assertion: "ok" - } - }] + errors: [ + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "assert", + assertion: "ok", + }, + }, + ], }, { code: "QUnit.test('Name', function (foo) { foo.ok(a); });", - errors: [{ - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "foo", - assertion: "ok" - } - }] + errors: [ + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "foo", + assertion: "ok", + }, + }, + ], }, { code: "QUnit.test('Name', function (assert) { assert.notOk(a); });", - errors: [{ - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "assert", - assertion: "notOk" - } - }] + errors: [ + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "assert", + assertion: "notOk", + }, + }, + ], }, { code: "QUnit.test('Name', function (foo) { foo.notOk(a); });", - errors: [{ - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "foo", - assertion: "notOk" - } - }] + errors: [ + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "foo", + assertion: "notOk", + }, + }, + ], }, { code: "QUnit.test('Name', function (assert) { ok(a, b); });", - errors: [{ - messageId: "unexpectedGlobalLooseAssertion", - data: { assertion: "ok" } - }] + errors: [ + { + messageId: "unexpectedGlobalLooseAssertion", + data: { assertion: "ok" }, + }, + ], }, { code: "QUnit.test('Name', function (assert) { notOk(a, b); });", - errors: [{ - messageId: "unexpectedGlobalLooseAssertion", - data: { assertion: "notOk" } - }] + errors: [ + { + messageId: "unexpectedGlobalLooseAssertion", + data: { assertion: "notOk" }, + }, + ], }, { code: "QUnit.test('Name', function () { ok(a, b); });", - errors: [{ - messageId: "unexpectedGlobalLooseAssertion", - data: { assertion: "ok" } - }] + errors: [ + { + messageId: "unexpectedGlobalLooseAssertion", + data: { assertion: "ok" }, + }, + ], }, { code: "QUnit.test('Name', function () { notOk(a, b); });", - errors: [{ - messageId: "unexpectedGlobalLooseAssertion", - data: { assertion: "notOk" } - }] + errors: [ + { + messageId: "unexpectedGlobalLooseAssertion", + data: { assertion: "notOk" }, + }, + ], }, { code: "QUnit.test('Name', function (assert) { assert.equal(a, b); });", - errors: [{ - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "assert", - assertion: "equal" - } - }] + errors: [ + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "assert", + assertion: "equal", + }, + }, + ], }, { code: "QUnit.test('Name', function (foo) { foo.equal(a, b); });", - errors: [{ - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "foo", - assertion: "equal" - } - }] + errors: [ + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "foo", + assertion: "equal", + }, + }, + ], }, { code: "QUnit.test('Name', function (assert) { equal(a, b); });", - errors: [{ - messageId: "unexpectedGlobalLooseAssertion", - data: { assertion: "equal" } - }] + errors: [ + { + messageId: "unexpectedGlobalLooseAssertion", + data: { assertion: "equal" }, + }, + ], }, { code: ` @@ -152,31 +176,36 @@ ruleTester.run("no-loose-assertions", rule, { assert.notEqual(a, b); }); `, - errors: [{ - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "assert", - assertion: "ok" - } - }, { - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "assert", - assertion: "notOk" - } - }, { - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "assert", - assertion: "equal" - } - }, { - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "assert", - assertion: "notEqual" - } - }] + errors: [ + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "assert", + assertion: "ok", + }, + }, + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "assert", + assertion: "notOk", + }, + }, + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "assert", + assertion: "equal", + }, + }, + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "assert", + assertion: "notEqual", + }, + }, + ], }, { code: ` @@ -187,31 +216,36 @@ ruleTester.run("no-loose-assertions", rule, { foo.notEqual(a, b); }); `, - errors: [{ - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "foo", - assertion: "ok" - } - }, { - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "foo", - assertion: "notOk" - } - }, { - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "foo", - assertion: "equal" - } - }, { - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "foo", - assertion: "notEqual" - } - }] + errors: [ + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "foo", + assertion: "ok", + }, + }, + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "foo", + assertion: "notOk", + }, + }, + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "foo", + assertion: "equal", + }, + }, + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "foo", + assertion: "notEqual", + }, + }, + ], }, { code: ` @@ -222,19 +256,24 @@ ruleTester.run("no-loose-assertions", rule, { notEqual(a, b); }); `, - errors: [{ - messageId: "unexpectedGlobalLooseAssertion", - data: { assertion: "ok" } - }, { - messageId: "unexpectedGlobalLooseAssertion", - data: { assertion: "notOk" } - }, { - messageId: "unexpectedGlobalLooseAssertion", - data: { assertion: "equal" } - }, { - messageId: "unexpectedGlobalLooseAssertion", - data: { assertion: "notEqual" } - }] + errors: [ + { + messageId: "unexpectedGlobalLooseAssertion", + data: { assertion: "ok" }, + }, + { + messageId: "unexpectedGlobalLooseAssertion", + data: { assertion: "notOk" }, + }, + { + messageId: "unexpectedGlobalLooseAssertion", + data: { assertion: "equal" }, + }, + { + messageId: "unexpectedGlobalLooseAssertion", + data: { assertion: "notEqual" }, + }, + ], }, { code: ` @@ -244,17 +283,19 @@ ruleTester.run("no-loose-assertions", rule, { assert.equal(a, b); }); `, - options: [["ok", { disallowed: "equal", - recommended: ["ab"] }]], - errors: [{ - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "assert", - assertion: "ok" - } - }, { - message: "Unexpected assert.equal. Use assert.ab." - }] + options: [["ok", { disallowed: "equal", recommended: ["ab"] }]], + errors: [ + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "assert", + assertion: "ok", + }, + }, + { + message: "Unexpected assert.equal. Use assert.ab.", + }, + ], }, { code: ` @@ -264,17 +305,19 @@ ruleTester.run("no-loose-assertions", rule, { foo.equal(a, b); }); `, - options: [["ok", { disallowed: "equal", - recommended: ["ab"] }]], - errors: [{ - messageId: "unexpectedLocalLooseAssertion", - data: { - assertVar: "foo", - assertion: "ok" - } - }, { - message: "Unexpected foo.equal. Use foo.ab." - }] + options: [["ok", { disallowed: "equal", recommended: ["ab"] }]], + errors: [ + { + messageId: "unexpectedLocalLooseAssertion", + data: { + assertVar: "foo", + assertion: "ok", + }, + }, + { + message: "Unexpected foo.equal. Use foo.ab.", + }, + ], }, { code: ` @@ -285,13 +328,16 @@ ruleTester.run("no-loose-assertions", rule, { }); `, options: [["ok", "equal"]], - errors: [{ - messageId: "unexpectedGlobalLooseAssertion", - data: { assertion: "ok" } - }, { - messageId: "unexpectedGlobalLooseAssertion", - data: { assertion: "equal" } - }] + errors: [ + { + messageId: "unexpectedGlobalLooseAssertion", + data: { assertion: "ok" }, + }, + { + messageId: "unexpectedGlobalLooseAssertion", + data: { assertion: "equal" }, + }, + ], }, { code: ` @@ -303,15 +349,23 @@ ruleTester.run("no-loose-assertions", rule, { `, // Extra "equal" and "ok" definitions to make sure they are properly ignored while parsing options - options: [["ok", { disallowed: "equal", - recommended: ["ab"] }, "equal", { disallowed: "ok", - recommended: ["ab"] }]], - errors: [{ - messageId: "unexpectedGlobalLooseAssertion", - data: { assertion: "ok" } - }, { - message: "Unexpected equal. Use ab." - }] - } - ] + options: [ + [ + "ok", + { disallowed: "equal", recommended: ["ab"] }, + "equal", + { disallowed: "ok", recommended: ["ab"] }, + ], + ], + errors: [ + { + messageId: "unexpectedGlobalLooseAssertion", + data: { assertion: "ok" }, + }, + { + message: "Unexpected equal. Use ab.", + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-negated-ok.js b/tests/lib/rules/no-negated-ok.js index dc7bd831..7df7fd27 100644 --- a/tests/lib/rules/no-negated-ok.js +++ b/tests/lib/rules/no-negated-ok.js @@ -20,8 +20,8 @@ function createError(callee) { return { messageId: "noNegationInOk", data: { - callee - } + callee, + }, }; } @@ -32,7 +32,6 @@ function createError(callee) { const ruleTester = new RuleTester(); ruleTester.run("no-negated-ok", rule, { - valid: [ // ok testUtils.wrapInTest("ok(foo)"), @@ -94,7 +93,7 @@ ruleTester.run("no-negated-ok", rule, { testUtils.wrapInTest("assert.true(foo)"), testUtils.wrapInTest("assert.true(foo, 'message')"), testUtils.wrapInTest("assert.false(foo)"), - testUtils.wrapInTest("assert.false(foo, 'message')") + testUtils.wrapInTest("assert.false(foo, 'message')"), ], invalid: [ @@ -102,75 +101,74 @@ ruleTester.run("no-negated-ok", rule, { { code: testUtils.wrapInTest("assert.ok(!foo)"), output: testUtils.wrapInTest("assert.notOk(foo)"), - errors: [createError("assert.ok")] + errors: [createError("assert.ok")], }, { // TypeScript: test callback is adding a type to `this` code: "QUnit.test('test', (this: LocalTestContext, assert) => { assert.ok(!foo); });", output: "QUnit.test('test', (this: LocalTestContext, assert) => { assert.notOk(foo); });", parser: require.resolve("@typescript-eslint/parser"), - errors: [createError("assert.ok")] + errors: [createError("assert.ok")], }, { code: testUtils.wrapInArrowTest("assert.ok(!foo)"), output: testUtils.wrapInArrowTest("assert.notOk(foo)"), parserOptions: { ecmaVersion: 6 }, - errors: [createError("assert.ok")] + errors: [createError("assert.ok")], }, // ok (with message) { code: testUtils.wrapInTest("assert.ok(!foo, 'message')"), output: testUtils.wrapInTest("assert.notOk(foo, 'message')"), - errors: [createError("assert.ok")] + errors: [createError("assert.ok")], }, // notOk { code: testUtils.wrapInTest("assert.notOk(!foo)"), output: testUtils.wrapInTest("assert.ok(foo)"), - errors: [createError("assert.notOk")] + errors: [createError("assert.notOk")], }, { code: testUtils.wrapInTest("assert.notOk(!foo, 'message')"), output: testUtils.wrapInTest("assert.ok(foo, 'message')"), - errors: [createError("assert.notOk")] + errors: [createError("assert.notOk")], }, // triple negation is not allowed { code: testUtils.wrapInTest("assert.ok(!!!foo)"), output: testUtils.wrapInTest("assert.notOk(foo)"), - errors: [createError("assert.ok")] + errors: [createError("assert.ok")], }, // triple negation is not allowed (with message) { code: testUtils.wrapInTest("assert.notOk(!!!foo)"), output: testUtils.wrapInTest("assert.ok(foo)"), - errors: [createError("assert.notOk")] + errors: [createError("assert.notOk")], }, // triple negation is not allowed (with notOk) { code: testUtils.wrapInTest("assert.notOk(!!!foo, 'message')"), output: testUtils.wrapInTest("assert.ok(foo, 'message')"), - errors: [createError("assert.notOk")] + errors: [createError("assert.notOk")], }, // true { code: testUtils.wrapInTest("assert.true(!foo)"), output: testUtils.wrapInTest("assert.false(foo)"), - errors: [createError("assert.true")] + errors: [createError("assert.true")], }, // false { code: testUtils.wrapInTest("assert.false(!foo)"), output: testUtils.wrapInTest("assert.true(foo)"), - errors: [createError("assert.false")] - } - ] - + errors: [createError("assert.false")], + }, + ], }); diff --git a/tests/lib/rules/no-nested-tests.js b/tests/lib/rules/no-nested-tests.js index 80b248de..b98b6997 100644 --- a/tests/lib/rules/no-nested-tests.js +++ b/tests/lib/rules/no-nested-tests.js @@ -28,7 +28,7 @@ ruleTester.run("no-nested-tests", rule, { "QUnit.module('ParentModule', function () {\n QUnit.test('Name', function() {});\n QUnit.module('ChildModule', function () {\n QUnit.test('ChildTest', function () {});\n });\n })\n", "QUnit.module('ParentModule', function () {\n test('Name', function() {});\n module('ChildModule', function () {\n QUnit.test('ChildTest', function () {});\n });\n })\n", "module('ParentModule', function () {\n QUnit.test('Name', function() {});\n QUnit.module('ChildModule', function () {\n test('ChildTest', function () {});\n });\n })\n", - "module('ParentModule', function () {\n test('Name', function() {});\n module('ChildModule', function () {\n test('ChildTest', function () {});\n });\n })\n" + "module('ParentModule', function () {\n test('Name', function() {});\n module('ChildModule', function () {\n test('ChildTest', function () {});\n });\n })\n", ], invalid: [ @@ -39,14 +39,13 @@ ruleTester.run("no-nested-tests", rule, { "QUnit.test('ParentTest', function () {\n QUnit.module('ChildModule', function () {\n QUnit.test('ChildTest', function () {});\n });\n });", "test('ParentTest', function () {\n module('ChildModule', function () {\n test('ChildTest', function () {});\n });\n });", "QUnit.test('ParentTest', function () {\n module('ChildModule', function () {\n test('ChildTest', function () {});\n });\n });", - "test('ParentTest', function () {\n QUnit.module('ChildModule', function () {\n QUnit.test('ChildTest', function () {});\n });\n });" - ] - .map(code => ({ - code, - errors: [ - { - messageId: "noNestedTests" - } - ] - })) + "test('ParentTest', function () {\n QUnit.module('ChildModule', function () {\n QUnit.test('ChildTest', function () {});\n });\n });", + ].map((code) => ({ + code, + errors: [ + { + messageId: "noNestedTests", + }, + ], + })), }); diff --git a/tests/lib/rules/no-ok-equality.js b/tests/lib/rules/no-ok-equality.js index ca787899..dbc52b1c 100644 --- a/tests/lib/rules/no-ok-equality.js +++ b/tests/lib/rules/no-ok-equality.js @@ -22,8 +22,8 @@ function createError(assertion, suggestion, a, b) { assertion, suggestion, a, - b - } + b, + }, }; } @@ -34,7 +34,6 @@ function createError(assertion, suggestion, a, b) { const ruleTester = new RuleTester(); ruleTester.run("no-ok-equality", rule, { - valid: [ "test('Name', function (assert) { assert.ok(x); });", "test('Name', function (assert) { assert.ok(x, 'message'); });", @@ -50,189 +49,157 @@ ruleTester.run("no-ok-equality", rule, { "test('Name', function (foo) { foo.notOk(x, 'message'); });", { code: "test('Name', function () { ok(x === 1); });", - options: [{ allowGlobal: false }] + options: [{ allowGlobal: false }], }, { code: "test('Name', function () { notOk(x === 1); });", - options: [{ allowGlobal: false }] + options: [{ allowGlobal: false }], }, { code: "test('Name', function () { ok(x == 1); });", - options: [{ allowGlobal: false }] + options: [{ allowGlobal: false }], }, { code: "test('Name', function () { notOk(x == 1); });", - options: [{ allowGlobal: false }] + options: [{ allowGlobal: false }], }, { code: "test('Name', function () { ok(x !== 1); });", - options: [{ allowGlobal: false }] + options: [{ allowGlobal: false }], }, { code: "test('Name', function () { notOk(x !== 1); });", - options: [{ allowGlobal: false }] + options: [{ allowGlobal: false }], }, { code: "test('Name', function () { ok(x != 1); });", - options: [{ allowGlobal: false }] + options: [{ allowGlobal: false }], }, { code: "test('Name', function () { notOk(x != 1); });", - options: [{ allowGlobal: false }] + options: [{ allowGlobal: false }], }, // Boolean assertions with no equality checks: "test('Name', function (assert) { assert.true(x); });", "test('Name', function (assert) { assert.true(x, 'message'); });", "test('Name', function (assert) { assert.false(x); });", - "test('Name', function (assert) { assert.false(x, 'message'); });" + "test('Name', function (assert) { assert.false(x, 'message'); });", ], invalid: [ { code: "test('Name', function (assert) { assert.ok(x === 1); });", output: "test('Name', function (assert) { assert.strictEqual(x, 1); });", - errors: [ - createError("assert.ok", "assert.strictEqual", "x", "1") - ] + errors: [createError("assert.ok", "assert.strictEqual", "x", "1")], }, { // TypeScript: test callback is adding a type to `this` code: "test('Name', function (this: LocalTestContext, assert) { assert.ok(x === 1); });", output: "test('Name', function (this: LocalTestContext, assert) { assert.strictEqual(x, 1); });", parser: require.resolve("@typescript-eslint/parser"), - errors: [ - createError("assert.ok", "assert.strictEqual", "x", "1") - ] + errors: [createError("assert.ok", "assert.strictEqual", "x", "1")], }, { code: "test('Name', (assert) => { assert.ok(x === 1); });", output: "test('Name', (assert) => { assert.strictEqual(x, 1); });", parserOptions: { ecmaVersion: 6 }, - errors: [ - createError("assert.ok", "assert.strictEqual", "x", "1") - ] + errors: [createError("assert.ok", "assert.strictEqual", "x", "1")], }, { // With message: code: "test('Name', function (assert) { assert.ok(x === 1, 'my message'); });", output: "test('Name', function (assert) { assert.strictEqual(x, 1, 'my message'); });", - errors: [ - createError("assert.ok", "assert.strictEqual", "x", "1") - ] + errors: [createError("assert.ok", "assert.strictEqual", "x", "1")], }, { code: "test('Name', function (assert) { assert.notOk(x === 1); });", output: "test('Name', function (assert) { assert.notStrictEqual(x, 1); });", errors: [ - createError("assert.notOk", "assert.notStrictEqual", "x", "1") - ] + createError("assert.notOk", "assert.notStrictEqual", "x", "1"), + ], }, { code: "test('Name', function () { ok(x === 1); });", output: "test('Name', function () { strictEqual(x, 1); });", options: [{ allowGlobal: true }], - errors: [ - createError("ok", "strictEqual", "x", "1") - ] + errors: [createError("ok", "strictEqual", "x", "1")], }, { code: "test('Name', function () { notOk(x === 1); });", output: "test('Name', function () { notStrictEqual(x, 1); });", options: [{ allowGlobal: true }], - errors: [ - createError("notOk", "notStrictEqual", "x", "1") - ] + errors: [createError("notOk", "notStrictEqual", "x", "1")], }, { code: "test('Name', function (assert) { assert.ok(x == 1); });", output: "test('Name', function (assert) { assert.equal(x, 1); });", - errors: [ - createError("assert.ok", "assert.equal", "x", "1") - ] + errors: [createError("assert.ok", "assert.equal", "x", "1")], }, { code: "test('Name', function (assert) { assert.notOk(x == 1); });", output: "test('Name', function (assert) { assert.notEqual(x, 1); });", - errors: [ - createError("assert.notOk", "assert.notEqual", "x", "1") - ] + errors: [createError("assert.notOk", "assert.notEqual", "x", "1")], }, { code: "test('Name', function () { ok(x == 1); });", output: "test('Name', function () { equal(x, 1); });", options: [{ allowGlobal: true }], - errors: [ - createError("ok", "equal", "x", "1") - ] + errors: [createError("ok", "equal", "x", "1")], }, { code: "test('Name', function () { notOk(x == 1); });", output: "test('Name', function () { notEqual(x, 1); });", options: [{ allowGlobal: true }], - errors: [ - createError("notOk", "notEqual", "x", "1") - ] + errors: [createError("notOk", "notEqual", "x", "1")], }, { code: "test('Name', function (assert) { assert.ok(x !== 1); });", output: "test('Name', function (assert) { assert.notStrictEqual(x, 1); });", errors: [ - createError("assert.ok", "assert.notStrictEqual", "x", "1") - ] + createError("assert.ok", "assert.notStrictEqual", "x", "1"), + ], }, { code: "test('Name', function (assert) { assert.notOk(x !== 1); });", output: "test('Name', function (assert) { assert.strictEqual(x, 1); });", errors: [ - createError("assert.notOk", "assert.strictEqual", "x", "1") - ] + createError("assert.notOk", "assert.strictEqual", "x", "1"), + ], }, { code: "test('Name', function () { ok(x !== 1); });", output: "test('Name', function () { notStrictEqual(x, 1); });", options: [{ allowGlobal: true }], - errors: [ - createError("ok", "notStrictEqual", "x", "1") - ] + errors: [createError("ok", "notStrictEqual", "x", "1")], }, { code: "test('Name', function () { notOk(x !== 1); });", output: "test('Name', function () { strictEqual(x, 1); });", options: [{ allowGlobal: true }], - errors: [ - createError("notOk", "strictEqual", "x", "1") - ] + errors: [createError("notOk", "strictEqual", "x", "1")], }, { code: "test('Name', function (assert) { assert.ok(x != 1); });", output: "test('Name', function (assert) { assert.notEqual(x, 1); });", - errors: [ - createError("assert.ok", "assert.notEqual", "x", "1") - ] + errors: [createError("assert.ok", "assert.notEqual", "x", "1")], }, { code: "test('Name', function (assert) { assert.notOk(x != 1); });", output: "test('Name', function (assert) { assert.equal(x, 1); });", - errors: [ - createError("assert.notOk", "assert.equal", "x", "1") - ] + errors: [createError("assert.notOk", "assert.equal", "x", "1")], }, { code: "test('Name', function () { ok(x != 1); });", output: "test('Name', function () { notEqual(x, 1); });", options: [{ allowGlobal: true }], - errors: [ - createError("ok", "notEqual", "x", "1") - ] + errors: [createError("ok", "notEqual", "x", "1")], }, { code: "test('Name', function () { notOk(x != 1); });", output: "test('Name', function () { equal(x, 1); });", options: [{ allowGlobal: true }], - errors: [ - createError("notOk", "equal", "x", "1") - ] + errors: [createError("notOk", "equal", "x", "1")], }, // Boolean assertions with equality checks @@ -241,33 +208,32 @@ ruleTester.run("no-ok-equality", rule, { code: "test('Name', function (assert) { assert.true(x === 1); });", output: "test('Name', function (assert) { assert.strictEqual(x, 1); });", errors: [ - createError("assert.true", "assert.strictEqual", "x", "1") - ] + createError("assert.true", "assert.strictEqual", "x", "1"), + ], }, { // true, with message code: "test('Name', function (assert) { assert.true(x === 1, 'message'); });", output: "test('Name', function (assert) { assert.strictEqual(x, 1, 'message'); });", errors: [ - createError("assert.true", "assert.strictEqual", "x", "1") - ] + createError("assert.true", "assert.strictEqual", "x", "1"), + ], }, { // false code: "test('Name', function (assert) { assert.false(x === 1); });", output: "test('Name', function (assert) { assert.notStrictEqual(x, 1); });", errors: [ - createError("assert.false", "assert.notStrictEqual", "x", "1") - ] + createError("assert.false", "assert.notStrictEqual", "x", "1"), + ], }, { // false, with message code: "test('Name', function (assert) { assert.false(x === 1, 'message'); });", output: "test('Name', function (assert) { assert.notStrictEqual(x, 1, 'message'); });", errors: [ - createError("assert.false", "assert.notStrictEqual", "x", "1") - ] - } - ] - + createError("assert.false", "assert.notStrictEqual", "x", "1"), + ], + }, + ], }); diff --git a/tests/lib/rules/no-only.js b/tests/lib/rules/no-only.js index c97327ba..9b7b0270 100644 --- a/tests/lib/rules/no-only.js +++ b/tests/lib/rules/no-only.js @@ -22,39 +22,49 @@ ruleTester.run("no-only", rule, { "QUnit.module.test('Name', function() { });", "QUnit.test('Name', function() { });", "module.test('Name', function() { });", - "test('Name', function() { });" + "test('Name', function() { });", ], invalid: [ { code: "QUnit.module.only('Name', function() { });", - errors: [{ - messageId: "noQUnitOnly" - }] + errors: [ + { + messageId: "noQUnitOnly", + }, + ], }, { code: "QUnit.only('Name', function() { });", - errors: [{ - messageId: "noQUnitOnly" - }] + errors: [ + { + messageId: "noQUnitOnly", + }, + ], }, { code: "module.only('Name', function() { });", - errors: [{ - messageId: "noQUnitOnly" - }] + errors: [ + { + messageId: "noQUnitOnly", + }, + ], }, { code: "only('Name', function() { });", - errors: [{ - messageId: "noQUnitOnly" - }] + errors: [ + { + messageId: "noQUnitOnly", + }, + ], }, { code: "test.only('Name', function() { });", - errors: [{ - messageId: "noQUnitOnly" - }] - } - ] + errors: [ + { + messageId: "noQUnitOnly", + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-qunit-push.js b/tests/lib/rules/no-qunit-push.js index 10b44638..a1d7d27c 100644 --- a/tests/lib/rules/no-qunit-push.js +++ b/tests/lib/rules/no-qunit-push.js @@ -11,7 +11,6 @@ const rule = require("../../../lib/rules/no-qunit-push"), RuleTester = require("eslint").RuleTester; - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ @@ -19,16 +18,18 @@ const rule = require("../../../lib/rules/no-qunit-push"), const ruleTester = new RuleTester(); ruleTester.run("no-qunit-push", rule, { valid: [ - "this.pushResult({ result: result, actual: actual, expected: expected, message: message });" + "this.pushResult({ result: result, actual: actual, expected: expected, message: message });", ], invalid: [ { code: "QUnit.push(result, actual, expected, message);", - errors: [{ - messageId: "noQUnitPush", - type: "CallExpression" - }] - } - ] + errors: [ + { + messageId: "noQUnitPush", + type: "CallExpression", + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-qunit-start-in-tests.js b/tests/lib/rules/no-qunit-start-in-tests.js index 984f3644..e2871e4d 100644 --- a/tests/lib/rules/no-qunit-start-in-tests.js +++ b/tests/lib/rules/no-qunit-start-in-tests.js @@ -19,8 +19,8 @@ function createError(context) { return { messageId: "noQUnitStartInTests", data: { - context - } + context, + }, }; } @@ -30,38 +30,37 @@ function createError(context) { const ruleTester = new RuleTester(); ruleTester.run("no-qunit-start-in-tests", rule, { - valid: [ // Must allow QUnit.start() outside of test contexts "QUnit.start();", // Must allow QUnit.start() in module properties that are not hooks - "QUnit.module(\"a module\", { notAHook: function() { QUnit.start(); } });" + 'QUnit.module("a module", { notAHook: function() { QUnit.start(); } });', ], invalid: [ { - code: "QUnit.asyncTest(\"test\", function(assert) { QUnit.start(); });", - errors: [createError("test")] + code: 'QUnit.asyncTest("test", function(assert) { QUnit.start(); });', + errors: [createError("test")], }, // Module hooks { - code: "QUnit.module(\"module\", { beforeEach: function() { QUnit.start(); } });", - errors: [createError("beforeEach hook")] + code: 'QUnit.module("module", { beforeEach: function() { QUnit.start(); } });', + errors: [createError("beforeEach hook")], }, { - code: "QUnit.module(\"module\", { afterEach: function() { QUnit.start(); } });", - errors: [createError("afterEach hook")] + code: 'QUnit.module("module", { afterEach: function() { QUnit.start(); } });', + errors: [createError("afterEach hook")], }, { - code: "QUnit.module(\"module\", { setup: function() { QUnit.start(); } });", - errors: [createError("setup hook")] + code: 'QUnit.module("module", { setup: function() { QUnit.start(); } });', + errors: [createError("setup hook")], }, { - code: "QUnit.module(\"module\", { teardown: function() { QUnit.start(); } });", - errors: [createError("teardown hook")] - } + code: 'QUnit.module("module", { teardown: function() { QUnit.start(); } });', + errors: [createError("teardown hook")], + }, // Module hooks (new-style modules) /* Enable when supported @@ -74,5 +73,5 @@ ruleTester.run("no-qunit-start-in-tests", rule, { errors: [createError("afterEach hook")] } */ - ] + ], }); diff --git a/tests/lib/rules/no-qunit-stop.js b/tests/lib/rules/no-qunit-stop.js index a5b67e27..94543e25 100644 --- a/tests/lib/rules/no-qunit-stop.js +++ b/tests/lib/rules/no-qunit-stop.js @@ -11,32 +11,32 @@ const rule = require("../../../lib/rules/no-qunit-stop"), RuleTester = require("eslint").RuleTester; - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ const ruleTester = new RuleTester(); ruleTester.run("no-qunit-stop", rule, { - - valid: [ - "var done = assert.async();" - ], + valid: ["var done = assert.async();"], invalid: [ { code: "QUnit.stop();", - errors: [{ - messageId: "noQUnitStop", - type: "CallExpression" - }] + errors: [ + { + messageId: "noQUnitStop", + type: "CallExpression", + }, + ], }, { code: "QUnit.stop(2);", - errors: [{ - messageId: "noQUnitStop", - type: "CallExpression" - }] - } - ] + errors: [ + { + messageId: "noQUnitStop", + type: "CallExpression", + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-reassign-log-callbacks.js b/tests/lib/rules/no-reassign-log-callbacks.js index c13c2ccc..4c7e583a 100644 --- a/tests/lib/rules/no-reassign-log-callbacks.js +++ b/tests/lib/rules/no-reassign-log-callbacks.js @@ -19,7 +19,6 @@ const rule = require("../../../lib/rules/no-reassign-log-callbacks"), const ruleTester = new RuleTester(); ruleTester.run("no-reassign-log-callbacks", rule, { - valid: [ "QUnit.begin(function () { });", "QUnit.done(function () { });", @@ -30,58 +29,72 @@ ruleTester.run("no-reassign-log-callbacks", rule, { "QUnit.testStart(function () { });", // Assigning to other QUnit properties is okay - "QUnit.blah = function () { };" + "QUnit.blah = function () { };", ], invalid: [ { code: "QUnit.begin = function () { };", - errors: [{ - messageId: "noReassignLogCallbacks", - type: "AssignmentExpression" - }] + errors: [ + { + messageId: "noReassignLogCallbacks", + type: "AssignmentExpression", + }, + ], }, { code: "QUnit.done = function () { };", - errors: [{ - messageId: "noReassignLogCallbacks", - type: "AssignmentExpression" - }] + errors: [ + { + messageId: "noReassignLogCallbacks", + type: "AssignmentExpression", + }, + ], }, { code: "QUnit.log = function () { };", - errors: [{ - messageId: "noReassignLogCallbacks", - type: "AssignmentExpression" - }] + errors: [ + { + messageId: "noReassignLogCallbacks", + type: "AssignmentExpression", + }, + ], }, { code: "QUnit.moduleDone = function () { };", - errors: [{ - messageId: "noReassignLogCallbacks", - type: "AssignmentExpression" - }] + errors: [ + { + messageId: "noReassignLogCallbacks", + type: "AssignmentExpression", + }, + ], }, { code: "QUnit.moduleStart = function () { };", - errors: [{ - messageId: "noReassignLogCallbacks", - type: "AssignmentExpression" - }] + errors: [ + { + messageId: "noReassignLogCallbacks", + type: "AssignmentExpression", + }, + ], }, { code: "QUnit.testDone = function () { };", - errors: [{ - messageId: "noReassignLogCallbacks", - type: "AssignmentExpression" - }] + errors: [ + { + messageId: "noReassignLogCallbacks", + type: "AssignmentExpression", + }, + ], }, { code: "QUnit.testStart = function () { };", - errors: [{ - messageId: "noReassignLogCallbacks", - type: "AssignmentExpression" - }] - } - ] + errors: [ + { + messageId: "noReassignLogCallbacks", + type: "AssignmentExpression", + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-reset.js b/tests/lib/rules/no-reset.js index dc92209a..39bc4555 100644 --- a/tests/lib/rules/no-reset.js +++ b/tests/lib/rules/no-reset.js @@ -19,22 +19,23 @@ const rule = require("../../../lib/rules/no-reset"), const ruleTester = new RuleTester(); ruleTester.run("no-reset", rule, { - valid: [ // Only invocations are reported "QUnit.reset", // Only QUnit.reset() is reported - "QUnit.init()" + "QUnit.init()", ], invalid: [ { code: "QUnit.reset();", - errors: [{ - messageId: "noReset", - type: "CallExpression" - }] - } - ] + errors: [ + { + messageId: "noReset", + type: "CallExpression", + }, + ], + }, + ], }); diff --git a/tests/lib/rules/no-setup-teardown.js b/tests/lib/rules/no-setup-teardown.js index a9c70ebb..ac20316b 100644 --- a/tests/lib/rules/no-setup-teardown.js +++ b/tests/lib/rules/no-setup-teardown.js @@ -13,14 +13,12 @@ const rule = require("../../../lib/rules/no-setup-teardown"), RuleTester = require("eslint").RuleTester; - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ const ruleTester = new RuleTester(); ruleTester.run("no-setup-teardown", rule, { - valid: [ // Modules without hooks are always fine "QUnit.module('Module');", @@ -35,52 +33,59 @@ ruleTester.run("no-setup-teardown", rule, { "QUnit.module('Module', { beforeEach: function () {}, afterEach: function () {} });", // other property names are not reported - "QUnit.module('Module', { foo: function () {} });" + "QUnit.module('Module', { foo: function () {} });", ], invalid: [ { code: "QUnit.module('module', { setup: function () { } });", output: "QUnit.module('module', { beforeEach: function () { } });", - errors: [{ - messageId: "noSetupTeardown", - data: { - forbidden: "setup", - preferred: "beforeEach" + errors: [ + { + messageId: "noSetupTeardown", + data: { + forbidden: "setup", + preferred: "beforeEach", + }, + type: "Property", }, - type: "Property" - }] + ], }, { code: "QUnit.module('module', { teardown: function () { } });", output: "QUnit.module('module', { afterEach: function () { } });", - errors: [{ - messageId: "noSetupTeardown", - data: { - forbidden: "teardown", - preferred: "afterEach" + errors: [ + { + messageId: "noSetupTeardown", + data: { + forbidden: "teardown", + preferred: "afterEach", + }, + type: "Property", }, - type: "Property" - }] + ], }, { code: "QUnit.module('module', { setup: function () {}, teardown: function () { } });", output: "QUnit.module('module', { beforeEach: function () {}, afterEach: function () { } });", - errors: [{ - messageId: "noSetupTeardown", - data: { - forbidden: "setup", - preferred: "beforeEach" + errors: [ + { + messageId: "noSetupTeardown", + data: { + forbidden: "setup", + preferred: "beforeEach", + }, + type: "Property", }, - type: "Property" - }, { - messageId: "noSetupTeardown", - data: { - forbidden: "teardown", - preferred: "afterEach" + { + messageId: "noSetupTeardown", + data: { + forbidden: "teardown", + preferred: "afterEach", + }, + type: "Property", }, - type: "Property" - }] - } - ] + ], + }, + ], }); diff --git a/tests/lib/rules/no-skip.js b/tests/lib/rules/no-skip.js index 83fccc06..6449114f 100644 --- a/tests/lib/rules/no-skip.js +++ b/tests/lib/rules/no-skip.js @@ -22,29 +22,29 @@ ruleTester.run("no-skip", rule, { "QUnit.module.test('Name', function() { });", "QUnit.test('Name', function() { });", "module.test('Name', function() { });", - "test('Name', function() { });" + "test('Name', function() { });", ], invalid: [ { code: "QUnit.module.skip('Name', function() { });", - errors: [{ messageId: "noQUnitSkip" }] + errors: [{ messageId: "noQUnitSkip" }], }, { code: "QUnit.skip('Name', function() { });", - errors: [{ messageId: "noQUnitSkip" }] + errors: [{ messageId: "noQUnitSkip" }], }, { code: "module.skip('Name', function() { });", - errors: [{ messageId: "noQUnitSkip" }] + errors: [{ messageId: "noQUnitSkip" }], }, { code: "skip('Name', function() { });", - errors: [{ messageId: "noQUnitSkip" }] + errors: [{ messageId: "noQUnitSkip" }], }, { code: "test.skip('Name', function() { });", - errors: [{ messageId: "noQUnitSkip" }] - } - ] + errors: [{ messageId: "noQUnitSkip" }], + }, + ], }); diff --git a/tests/lib/rules/no-test-expect-argument.js b/tests/lib/rules/no-test-expect-argument.js index 983f7c9c..5fb1cc6e 100644 --- a/tests/lib/rules/no-test-expect-argument.js +++ b/tests/lib/rules/no-test-expect-argument.js @@ -11,7 +11,6 @@ const rule = require("../../../lib/rules/no-test-expect-argument"), RuleTester = require("eslint").RuleTester; - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ @@ -35,49 +34,57 @@ ruleTester.run("no-test-expect-argument", rule, { "test('test name', function (assert) { assert.expect(0); });", "QUnit.test('test name', function (assert) { assert.expect(0); });", "asyncTest('test name', function (assert) { assert.expect(0); });", - "QUnit.asyncTest('test name', function (assert) { assert.expect(0); });" + "QUnit.asyncTest('test name', function (assert) { assert.expect(0); });", ], invalid: [ { code: "test('test name', 0, function () { });", - errors: [{ - messageId: "noExpectArgument", - data: { - callee: "test" + errors: [ + { + messageId: "noExpectArgument", + data: { + callee: "test", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "QUnit.test('test name', 0, function () { });", - errors: [{ - messageId: "noExpectArgument", - data: { - callee: "QUnit.test" + errors: [ + { + messageId: "noExpectArgument", + data: { + callee: "QUnit.test", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "asyncTest('test name', 0, function () { });", - errors: [{ - messageId: "noExpectArgument", - data: { - callee: "asyncTest" + errors: [ + { + messageId: "noExpectArgument", + data: { + callee: "asyncTest", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "QUnit.asyncTest('test name', 0, function () { });", - errors: [{ - messageId: "noExpectArgument", - data: { - callee: "QUnit.asyncTest" + errors: [ + { + messageId: "noExpectArgument", + data: { + callee: "QUnit.asyncTest", + }, + type: "CallExpression", }, - type: "CallExpression" - }] - } - ] + ], + }, + ], }); diff --git a/tests/lib/rules/no-throws-string.js b/tests/lib/rules/no-throws-string.js index 0adc2dcf..9cdbe5aa 100644 --- a/tests/lib/rules/no-throws-string.js +++ b/tests/lib/rules/no-throws-string.js @@ -11,7 +11,6 @@ const rule = require("../../../lib/rules/no-throws-string"), RuleTester = require("eslint").RuleTester; - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ @@ -39,62 +38,72 @@ ruleTester.run("no-throws-string", rule, { "QUnit.test('a test', function (assert) { assert.foo(function () { }, 'string', 'Error should have been thrown'); });", // Not inside a test - "someFunction();" + "someFunction();", ], invalid: [ { code: "QUnit.test('a test', function (assert) { assert.throws(function () { }, 'Error message', 'Error should have been thrown'); });", - errors: [{ - messageId: "noThrowsWithString", - data: { - callee: "assert.throws" + errors: [ + { + messageId: "noThrowsWithString", + data: { + callee: "assert.throws", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { // TypeScript: test callback is adding a type to `this` code: "QUnit.test('a test', function (this: LocalTestContext, assert) { assert.throws(function () { }, 'Error message', 'Error should have been thrown'); });", parser: require.resolve("@typescript-eslint/parser"), - errors: [{ - messageId: "noThrowsWithString", - data: { - callee: "assert.throws" + errors: [ + { + messageId: "noThrowsWithString", + data: { + callee: "assert.throws", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "QUnit.test('a test', (assert) => { assert.throws(function () { }, 'Error message', 'Error should have been thrown'); });", parserOptions: { ecmaVersion: 6 }, - errors: [{ - messageId: "noThrowsWithString", - data: { - callee: "assert.throws" + errors: [ + { + messageId: "noThrowsWithString", + data: { + callee: "assert.throws", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "QUnit.test('a test', function (assert) { assert.raises(function () { }, 'Error message', 'Error should have been thrown'); });", - errors: [{ - messageId: "noThrowsWithString", - data: { - callee: "assert.raises" + errors: [ + { + messageId: "noThrowsWithString", + data: { + callee: "assert.raises", + }, + type: "CallExpression", }, - type: "CallExpression" - }] + ], }, { code: "QUnit.test('a test', function () { throws(function () { }, 'Error message', 'Error should have been thrown'); });", - errors: [{ - messageId: "noThrowsWithString", - data: { - callee: "throws" + errors: [ + { + messageId: "noThrowsWithString", + data: { + callee: "throws", + }, + type: "CallExpression", }, - type: "CallExpression" - }] - } - ] + ], + }, + ], }); diff --git a/tests/lib/rules/require-expect.js b/tests/lib/rules/require-expect.js index d1a93c51..0826f9fa 100644 --- a/tests/lib/rules/require-expect.js +++ b/tests/lib/rules/require-expect.js @@ -23,8 +23,8 @@ function alwaysErrorMessage(expectCallName) { return { messageId: "expectRequired", data: { - expect: expectCallName - } + expect: expectCallName, + }, }; } @@ -32,8 +32,8 @@ function exceptSimpleErrorMessage(expectCallName) { return { messageId: "expectRequiredComplexTest", data: { - expect: expectCallName - } + expect: expectCallName, + }, }; } @@ -41,24 +41,23 @@ function neverErrorMessage(expectCallName) { return { messageId: "expectForbidden", data: { - expect: expectCallName - } + expect: expectCallName, + }, }; } ruleTester.run("require-expect", rule, { - valid: [ // default, calling expect is valid { code: "test('name', function(assert) { assert.expect(0) });", - options: [] // Defaults to never-except-zero + options: [], // Defaults to never-except-zero }, // default, using global expect { code: "test('name', function() { expect(0) });", - options: [] // Defaults to never-except-zero + options: [], // Defaults to never-except-zero }, // default, using global expect, TS @@ -66,50 +65,50 @@ ruleTester.run("require-expect", rule, { // TypeScript: test callback is adding a type to `this` code: "test('name', function(this: LocalTestContext) { expect(0) });", options: [], // Defaults to never-except-zero - parser: require.resolve("@typescript-eslint/parser") + parser: require.resolve("@typescript-eslint/parser"), }, // CallExpression without parent object throws no errors { code: "test('name', function(assert) { assert.expect(0); noParentObject() });", - options: [] // Defaults to never-except-zero + options: [], // Defaults to never-except-zero }, { code: "test('name', function(assert) { assert.expect(0); noParentObject() });", - options: ["always"] + options: ["always"], }, { // With arrow function code: "test('name', assert => { assert.expect(0); noParentObject() });", - options: ["always"] + options: ["always"], }, // assert at top of test context is ok { code: "test('name', function(assert) { assert.ok(true) });", - options: ["except-simple"] + options: ["except-simple"], }, { code: "test('name', function(assert) { assert.ok(true) });", - options: [] // Defaults to never-except-zero + options: [], // Defaults to never-except-zero }, // global assertion at top of test context is ok { code: "test('name', function() { ok(true) });", - options: ["except-simple"] + options: ["except-simple"], }, // assert in block with expect at the top of test context is ok { code: "test('name', function(assert) { assert.expect(0); if (false) { assert.ok(false) } });", - options: ["except-simple"] + options: ["except-simple"], }, // global assertion in block with expect at the top of test context is ok { code: "test('name', function() { expect(0); if (false) { ok(false) } });", - options: ["except-simple"] + options: ["except-simple"], }, // nested modules @@ -125,46 +124,46 @@ ruleTester.run("require-expect", rule, { " ok(true, 'still no expect needed');", " });", " });", - "});" + "});", ].join(returnAndIndent), - options: ["except-simple"] + options: ["except-simple"], }, // "except-simple" (with arrow function) { code: "test('name', assert => { assert.expect(2); assert.ok(true); assert.ok(true); });", - options: ["except-simple"] + options: ["except-simple"], }, // "never" - assert without expect is fine { code: "test('name', function(assert) { assert.ok(true) });", - options: ["never"] + options: ["never"], }, // "never" - assert without expect is fine (with arrow function) { code: "test('name', assert => { assert.ok(true) });", - options: ["never"] + options: ["never"], }, // "never-except-zero" - assert without expect is fine { code: "test('name', function(assert) { assert.ok(true) });", - options: ["never-except-zero"] + options: ["never-except-zero"], }, // "never-except-zero" - expect zero is fine { code: "test('name', function(assert) { assert.expect(0) });", - options: ["never-except-zero"] + options: ["never-except-zero"], }, // "never-except-zero" - expect zero is fine (with arrow function) { code: "test('name', assert => { assert.expect(0) });", - options: ["never-except-zero"] - } + options: ["never-except-zero"], + }, ], invalid: [ @@ -172,146 +171,146 @@ ruleTester.run("require-expect", rule, { { code: "test('name', function(assert) { other.assert.expect(0) });", options: ["always"], - errors: [alwaysErrorMessage("assert.expect")] + errors: [alwaysErrorMessage("assert.expect")], }, { code: "test('name', (assert) => { other.assert.expect(0) });", options: ["always"], parserOptions: { ecmaVersion: 6 }, - errors: [alwaysErrorMessage("assert.expect")] + errors: [alwaysErrorMessage("assert.expect")], }, { // TypeScript: test callback is adding a type to `this` code: "test('name', function(this: LocalTestContext, assert) { other.assert.expect(0) });", options: ["always"], parser: require.resolve("@typescript-eslint/parser"), - errors: [alwaysErrorMessage("assert.expect")] + errors: [alwaysErrorMessage("assert.expect")], }, // assert in loop block { code: "test('name', function(assert) { while (false) { assert.ok(true) } });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("assert.expect")] + errors: [exceptSimpleErrorMessage("assert.expect")], }, // global assertion in loop block { code: "test('name', function() { for (;;) { ok(true) } });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("expect")] + errors: [exceptSimpleErrorMessage("expect")], }, // assert used in callback { code: "test('name', function(assert) { maybe(function() { assert.ok(true) }); });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("assert.expect")] + errors: [exceptSimpleErrorMessage("assert.expect")], }, { code: "test('name', function(assert) { maybe(() => { assert.ok(true) }); });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("assert.expect")] + errors: [exceptSimpleErrorMessage("assert.expect")], }, { code: "test('name', function(assert) { maybe(() => assert.ok(true)); });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("assert.expect")] + errors: [exceptSimpleErrorMessage("assert.expect")], }, // "except-simple" with arrow function and assert used in callback { code: "test('name', assert => { maybe(() => { assert.ok(true) }); });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("assert.expect")] + errors: [exceptSimpleErrorMessage("assert.expect")], }, { code: "test('name', assert => { maybe(() => { maybe(() => { assert.ok(true) }); }); });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("assert.expect")] + errors: [exceptSimpleErrorMessage("assert.expect")], }, // global assertion used in callback { code: "test('name', function(assert) { maybe(function() { ok(true) }); });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("assert.expect")] + errors: [exceptSimpleErrorMessage("assert.expect")], }, // assert in function expression { code: "test('name', function(assert) { var maybe = function() { assert.ok(true) }; });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("assert.expect")] + errors: [exceptSimpleErrorMessage("assert.expect")], }, // global assertion in function expression { code: "test('name', function() { var maybe = function() { ok(true) }; });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("expect")] + errors: [exceptSimpleErrorMessage("expect")], }, // `expect` does not count when used inside of a block. { code: "test('name', function(assert) { function name() { assert.expect(1); assert.ok(true) } });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("assert.expect")] + errors: [exceptSimpleErrorMessage("assert.expect")], }, // global `expect` does not count when used inside of a block. { code: "test('name', function() { function name() { expect(1); ok(true) } });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("expect")] + errors: [exceptSimpleErrorMessage("expect")], }, // `expect` does not count when used inside of a callback { code: "test('name', function(assert) { maybe(function() { assert.expect(1); assert.ok(true) }); });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("assert.expect")] + errors: [exceptSimpleErrorMessage("assert.expect")], }, // global `expect` does not count when used inside of a callback { code: "test('name', function() { maybe(function() { expect(1); ok(true) }); });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("expect")] + errors: [exceptSimpleErrorMessage("expect")], }, // assert in outer test context and nested in a block { code: "test('name', function(assert) { assert.ok(true); if (true) { assert.ok(true); } });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("assert.expect")] + errors: [exceptSimpleErrorMessage("assert.expect")], }, // Deeply nested { code: "test('name', function() { if (true) { if (true) { ok(true); } } });", options: ["except-simple"], - errors: [exceptSimpleErrorMessage("expect")] + errors: [exceptSimpleErrorMessage("expect")], }, // Sending assert to a function { code: [ "function myAssertion(a, assert, c) { assert.ok(true); }", - "test('name', function(assert) { myAssertion(null, assert, null); });" + "test('name', function(assert) { myAssertion(null, assert, null); });", ].join(returnAndIndent), options: ["except-simple"], - errors: [exceptSimpleErrorMessage("assert.expect")] + errors: [exceptSimpleErrorMessage("assert.expect")], }, // Sending assert to a function - renaming assert { code: [ "function myAssertion(a, localAssert, c) { localAssert.ok(true); }", - "test('name', function(myAssert) { myAssertion(null, myAssert, null); });" + "test('name', function(myAssert) { myAssertion(null, myAssert, null); });", ].join(returnAndIndent), options: ["except-simple"], - errors: [exceptSimpleErrorMessage("myAssert.expect")] + errors: [exceptSimpleErrorMessage("myAssert.expect")], }, // nested modules @@ -330,38 +329,46 @@ ruleTester.run("require-expect", rule, { " assert.ok(true, 'has expect');", " });", " });", - "});" + "});", ].join(returnAndIndent), options: ["except-simple"], - errors: [Object.assign(exceptSimpleErrorMessage("assert.expect"), { line: 2 })] + errors: [ + Object.assign(exceptSimpleErrorMessage("assert.expect"), { + line: 2, + }), + ], }, // Multiple assert statements only report one error per test { code: "test('name', function(assert) { maybe(function() { assert.ok(true); assert.ok(true); }) });", options: ["except-simple"], - errors: [Object.assign(exceptSimpleErrorMessage("assert.expect"), { column: 1 })] + errors: [ + Object.assign(exceptSimpleErrorMessage("assert.expect"), { + column: 1, + }), + ], }, // "always" configuration - simple case { code: "test('name', function(assert) { assert.ok(true) })", options: ["always"], - errors: [alwaysErrorMessage("assert.expect")] + errors: [alwaysErrorMessage("assert.expect")], }, // "always" configuration - global assertion { code: "test('name', function() { equal(1, 1) })", options: ["always"], - errors: [alwaysErrorMessage("expect")] + errors: [alwaysErrorMessage("expect")], }, // "always" configuration checking that "expect" is called on assert. { code: "test('name', function(assert) { other.expect(1); assert.ok(true); });", options: ["always"], - errors: [alwaysErrorMessage("assert.expect")] + errors: [alwaysErrorMessage("assert.expect")], }, // "always" configuration - errors are reported on `test()` line @@ -373,44 +380,49 @@ ruleTester.run("require-expect", rule, { " assert.ok(true, 'needs expect');", " }", " });", - "});" + "});", ].join(returnAndIndent), options: ["always"], - errors: [Object.assign(alwaysErrorMessage("assert.expect"), { line: 2 })] + errors: [ + Object.assign(alwaysErrorMessage("assert.expect"), { line: 2 }), + ], }, // "always" configuration - multiple assert statements only report one error per test { code: "test('name', function(assert) { maybe(function() { assert.ok(true); assert.ok(true); }) });", options: ["always"], - errors: [Object.assign(alwaysErrorMessage("assert.expect"), { column: 1 })] + errors: [ + Object.assign(alwaysErrorMessage("assert.expect"), { + column: 1, + }), + ], }, // "never" - expect is not fine { code: "test('name', function(assert) { assert.expect(1); assert.ok(true); });", options: ["never"], - errors: [neverErrorMessage("assert.expect")] + errors: [neverErrorMessage("assert.expect")], }, // "never" - expect zero is not fine { code: "test('name', function(assert) { assert.expect(0) });", options: ["never"], - errors: [neverErrorMessage("assert.expect")] + errors: [neverErrorMessage("assert.expect")], }, // "never-except-zero" - expect is not fine { code: "test('name', function(assert) { assert.expect(1); assert.ok(true); });", options: ["never-except-zero"], - errors: [neverErrorMessage("assert.expect")] + errors: [neverErrorMessage("assert.expect")], }, { code: "test('name', function(assert) { assert.expect(1); assert.ok(true); });", options: [], // defaults to never-except-zero - errors: [neverErrorMessage("assert.expect")] - } - ] - + errors: [neverErrorMessage("assert.expect")], + }, + ], }); diff --git a/tests/lib/rules/require-object-in-propequal.js b/tests/lib/rules/require-object-in-propequal.js index a6c5b90c..4dfe895e 100644 --- a/tests/lib/rules/require-object-in-propequal.js +++ b/tests/lib/rules/require-object-in-propequal.js @@ -19,12 +19,14 @@ const rule = require("../../../lib/rules/require-object-in-propequal"), function createInvalid(assertionCode, invalidValue) { return { code: testUtils.wrapInTest(assertionCode), - errors: [{ - messageId: "useObject", - data: { - value: invalidValue - } - }] + errors: [ + { + messageId: "useObject", + data: { + value: invalidValue, + }, + }, + ], }; } @@ -35,8 +37,8 @@ function createInvalid(assertionCode, invalidValue) { const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2020, - ecmaFeatures: { jsx: true } - } + ecmaFeatures: { jsx: true }, + }, }); ruleTester.run("require-object-in-propequal", rule, { @@ -76,24 +78,69 @@ ruleTester.run("require-object-in-propequal", rule, { testUtils.wrapInTest("assert.deepEqual(actual, 0n);"), testUtils.wrapInTest("assert.propEqual(actual, foo?.bar);"), - testUtils.wrapInTest("assert.propEqual(actual, foo?.bar?.());") + testUtils.wrapInTest("assert.propEqual(actual, foo?.bar?.());"), ], invalid: [ - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, 0);"), "0"), - createInvalid(testUtils.wrapInArrowTest("assert.propEqual(actual, 0);"), "0"), - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, -1);"), "-1"), - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, 'string');"), "'string'"), - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, `template`);"), "`template`"), - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, true);"), "true"), - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, false);"), "false"), - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, null);"), "null"), - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, /regex/);"), "/regex/"), - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, ++foo);"), "++foo"), - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, foo++);"), "foo++"), - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, --foo);"), "--foo"), - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, foo--);"), "foo--"), - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, )"), ""), - createInvalid(testUtils.wrapInTest("assert.propEqual(actual, 0n);"), "0n") - ] + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, 0);"), + "0", + ), + createInvalid( + testUtils.wrapInArrowTest("assert.propEqual(actual, 0);"), + "0", + ), + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, -1);"), + "-1", + ), + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, 'string');"), + "'string'", + ), + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, `template`);"), + "`template`", + ), + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, true);"), + "true", + ), + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, false);"), + "false", + ), + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, null);"), + "null", + ), + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, /regex/);"), + "/regex/", + ), + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, ++foo);"), + "++foo", + ), + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, foo++);"), + "foo++", + ), + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, --foo);"), + "--foo", + ), + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, foo--);"), + "foo--", + ), + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, )"), + "", + ), + createInvalid( + testUtils.wrapInTest("assert.propEqual(actual, 0n);"), + "0n", + ), + ], }); diff --git a/tests/lib/rules/resolve-async.js b/tests/lib/rules/resolve-async.js index 2cbb90cc..a8a75da0 100644 --- a/tests/lib/rules/resolve-async.js +++ b/tests/lib/rules/resolve-async.js @@ -23,9 +23,9 @@ function createNeedStartCallsMessage(nodeType, numberOfCalls = 1) { messageId: "needMoreStartCalls", data: { semaphore, - callOrCalls + callOrCalls, }, - type: nodeType + type: nodeType, }; } @@ -33,9 +33,9 @@ function createAsyncCallbackNotCalledMessage(nodeType, callbackVar) { return { messageId: "asyncCallbackNotCalled", data: { - asyncVar: callbackVar || "done" + asyncVar: callbackVar || "done", }, - type: nodeType + type: nodeType, }; } @@ -45,7 +45,6 @@ function createAsyncCallbackNotCalledMessage(nodeType, callbackVar) { const ruleTester = new RuleTester(); ruleTester.run("resolve-async", rule, { - valid: [ // stop()/start() "test('name', function () { stop(); start(); });", @@ -149,346 +148,359 @@ ruleTester.run("resolve-async", rule, { // module properties that aren't hooks should not be flagged "QUnit.module({ someProp: function () { QUnit.stop(); } });", - "QUnit.module({ someProp: function (assert) { assert.async(); } });" + "QUnit.module({ someProp: function (assert) { assert.async(); } });", ], invalid: [ // stop()/start() { code: "asyncTest('name', function () {});", - errors: [createNeedStartCallsMessage("CallExpression")] + errors: [createNeedStartCallsMessage("CallExpression")], }, { code: "test('name', function () { stop(); });", - errors: [createNeedStartCallsMessage("CallExpression")] + errors: [createNeedStartCallsMessage("CallExpression")], }, { code: "QUnit.asyncTest('name', function () {});", - errors: [createNeedStartCallsMessage("CallExpression")] + errors: [createNeedStartCallsMessage("CallExpression")], }, { code: "QUnit.test('name', function () { stop(); });", - errors: [createNeedStartCallsMessage("CallExpression")] + errors: [createNeedStartCallsMessage("CallExpression")], }, { code: "test('name', function () { QUnit.stop(); });", - errors: [createNeedStartCallsMessage("CallExpression")] + errors: [createNeedStartCallsMessage("CallExpression")], }, { code: "QUnit.test('name', function () { QUnit.stop(); });", - errors: [createNeedStartCallsMessage("CallExpression")] + errors: [createNeedStartCallsMessage("CallExpression")], }, { code: "QUnit.module('name', { setup: function () { QUnit.stop(); } });", - errors: [createNeedStartCallsMessage("Property")] + errors: [createNeedStartCallsMessage("Property")], }, { code: "QUnit.module('name', { teardown: function () { QUnit.stop(); } });", - errors: [createNeedStartCallsMessage("Property")] + errors: [createNeedStartCallsMessage("Property")], }, { code: "QUnit.module('name', { beforeEach: function () { QUnit.stop(); } });", - errors: [createNeedStartCallsMessage("Property")] + errors: [createNeedStartCallsMessage("Property")], }, { code: "QUnit.module('name', { afterEach: function () { QUnit.stop(); } });", - errors: [createNeedStartCallsMessage("Property")] + errors: [createNeedStartCallsMessage("Property")], }, // Multiple start() calls needed { code: "asyncTest('name', function () { stop(); });", - errors: [createNeedStartCallsMessage("CallExpression", 2)] + errors: [createNeedStartCallsMessage("CallExpression", 2)], }, { code: "test('name', function () { stop(); stop(); });", - errors: [createNeedStartCallsMessage("CallExpression", 2)] + errors: [createNeedStartCallsMessage("CallExpression", 2)], }, { code: "test('name', function () { QUnit.stop(); stop(); });", - errors: [createNeedStartCallsMessage("CallExpression", 2)] + errors: [createNeedStartCallsMessage("CallExpression", 2)], }, { code: "QUnit.asyncTest('name', function () { stop(); });", - errors: [createNeedStartCallsMessage("CallExpression", 2)] + errors: [createNeedStartCallsMessage("CallExpression", 2)], }, { code: "QUnit.test('name', function () { stop(); stop(); });", - errors: [createNeedStartCallsMessage("CallExpression", 2)] + errors: [createNeedStartCallsMessage("CallExpression", 2)], }, { code: "QUnit.test('name', function () { stop(); QUnit.stop(); });", - errors: [createNeedStartCallsMessage("CallExpression", 2)] + errors: [createNeedStartCallsMessage("CallExpression", 2)], }, { code: "asyncTest('name', function () { QUnit.stop(); });", - errors: [createNeedStartCallsMessage("CallExpression", 2)] + errors: [createNeedStartCallsMessage("CallExpression", 2)], }, { code: "test('name', function () { QUnit.stop(); QUnit.stop(); });", - errors: [createNeedStartCallsMessage("CallExpression", 2)] + errors: [createNeedStartCallsMessage("CallExpression", 2)], }, { code: "QUnit.asyncTest('name', function () { QUnit.stop(); });", - errors: [createNeedStartCallsMessage("CallExpression", 2)] + errors: [createNeedStartCallsMessage("CallExpression", 2)], }, { code: "QUnit.test('name', function () { QUnit.stop(); QUnit.stop(); });", - errors: [createNeedStartCallsMessage("CallExpression", 2)] + errors: [createNeedStartCallsMessage("CallExpression", 2)], }, { code: "QUnit.module('name', { setup: function () { QUnit.stop(); QUnit.stop(); } });", - errors: [createNeedStartCallsMessage("Property", 2)] + errors: [createNeedStartCallsMessage("Property", 2)], }, { code: "QUnit.module('name', { teardown: function () { QUnit.stop(); QUnit.stop(); } });", - errors: [createNeedStartCallsMessage("Property", 2)] + errors: [createNeedStartCallsMessage("Property", 2)], }, { code: "QUnit.module('name', { beforeEach: function () { QUnit.stop(); QUnit.stop(); } });", - errors: [createNeedStartCallsMessage("Property", 2)] + errors: [createNeedStartCallsMessage("Property", 2)], }, { code: "QUnit.module('name', { afterEach: function () { QUnit.stop(); QUnit.stop(); } });", - errors: [createNeedStartCallsMessage("Property", 2)] + errors: [createNeedStartCallsMessage("Property", 2)], }, // assert.async() { code: "test('name', function (assert) { var done = assert.async(); });", - errors: [createAsyncCallbackNotCalledMessage("CallExpression")] + errors: [createAsyncCallbackNotCalledMessage("CallExpression")], }, { code: "QUnit.test('name', function (assert) { var done = assert.async(); });", - errors: [createAsyncCallbackNotCalledMessage("CallExpression")] + errors: [createAsyncCallbackNotCalledMessage("CallExpression")], }, { code: "test('name', function (assert) { var done; done = assert.async(); });", - errors: [createAsyncCallbackNotCalledMessage("CallExpression")] + errors: [createAsyncCallbackNotCalledMessage("CallExpression")], }, { code: "QUnit.test('name', function (assert) { var done; done = assert.async(); });", - errors: [createAsyncCallbackNotCalledMessage("CallExpression")] + errors: [createAsyncCallbackNotCalledMessage("CallExpression")], }, { code: "QUnit.module({ setup: function (assert) { var done = assert.async(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property")] + errors: [createAsyncCallbackNotCalledMessage("Property")], }, { code: "QUnit.module({ teardown: function (assert) { var done = assert.async(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property")] + errors: [createAsyncCallbackNotCalledMessage("Property")], }, { code: "QUnit.module({ beforeEach: function (assert) { var done = assert.async(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property")] + errors: [createAsyncCallbackNotCalledMessage("Property")], }, { code: "QUnit.module({ afterEach: function (assert) { var done = assert.async(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property")] + errors: [createAsyncCallbackNotCalledMessage("Property")], }, { code: "QUnit.module({ setup: function (assert) { var done; done = assert.async(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property")] + errors: [createAsyncCallbackNotCalledMessage("Property")], }, { code: "QUnit.module({ teardown: function (assert) { var done; done = assert.async(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property")] + errors: [createAsyncCallbackNotCalledMessage("Property")], }, { code: "QUnit.module({ beforeEach: function (assert) { var done; done = assert.async(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property")] + errors: [createAsyncCallbackNotCalledMessage("Property")], }, { code: "QUnit.module({ afterEach: function (assert) { var done; done = assert.async(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property")] + errors: [createAsyncCallbackNotCalledMessage("Property")], }, // Multiple assert.async() calls { code: "test('name', function (assert) { var done1 = assert.async(), done2 = assert.async(); done1(); });", - errors: [createAsyncCallbackNotCalledMessage("CallExpression", "done2")] + errors: [ + createAsyncCallbackNotCalledMessage("CallExpression", "done2"), + ], }, { code: "test('name', function (assert) { var done1 = assert.async(), done2 = assert.async(); });", errors: [ createAsyncCallbackNotCalledMessage("CallExpression", "done1"), - createAsyncCallbackNotCalledMessage("CallExpression", "done2") - ] + createAsyncCallbackNotCalledMessage("CallExpression", "done2"), + ], }, { code: "QUnit.test('name', function (assert) { var done1 = assert.async(), done2 = assert.async(); done1(); });", - errors: [createAsyncCallbackNotCalledMessage("CallExpression", "done2")] + errors: [ + createAsyncCallbackNotCalledMessage("CallExpression", "done2"), + ], }, { code: "QUnit.test('name', function (assert) { var done1 = assert.async(), done2 = assert.async(); });", errors: [ createAsyncCallbackNotCalledMessage("CallExpression", "done1"), - createAsyncCallbackNotCalledMessage("CallExpression", "done2") - ] + createAsyncCallbackNotCalledMessage("CallExpression", "done2"), + ], }, { code: "test('name', function (assert) { var done1, done2; done1 = assert.async(); done2 = assert.async(); done1(); });", - errors: [createAsyncCallbackNotCalledMessage("CallExpression", "done2")] + errors: [ + createAsyncCallbackNotCalledMessage("CallExpression", "done2"), + ], }, { code: "test('name', function (assert) { var done1, done2; done1 = assert.async(); done2 = assert.async(); });", errors: [ createAsyncCallbackNotCalledMessage("CallExpression", "done1"), - createAsyncCallbackNotCalledMessage("CallExpression", "done2") - ] + createAsyncCallbackNotCalledMessage("CallExpression", "done2"), + ], }, { code: "QUnit.test('name', function (assert) { var done1, done2; done1 = assert.async(); done2 = assert.async(); done1(); });", - errors: [createAsyncCallbackNotCalledMessage("CallExpression", "done2")] + errors: [ + createAsyncCallbackNotCalledMessage("CallExpression", "done2"), + ], }, { code: "QUnit.test('name', function (assert) { var done1, done2; done1 = assert.async(); done2 = assert.async(); });", errors: [ createAsyncCallbackNotCalledMessage("CallExpression", "done1"), - createAsyncCallbackNotCalledMessage("CallExpression", "done2") - ] + createAsyncCallbackNotCalledMessage("CallExpression", "done2"), + ], }, { code: "QUnit.module({ setup: function (assert) { var done1 = assert.async(), done2 = assert.async(); done1(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property", "done2")] + errors: [createAsyncCallbackNotCalledMessage("Property", "done2")], }, { code: "QUnit.module({ setup: function (assert) { var done1 = assert.async(), done2 = assert.async(); } });", errors: [ createAsyncCallbackNotCalledMessage("Property", "done1"), - createAsyncCallbackNotCalledMessage("Property", "done2") - ] + createAsyncCallbackNotCalledMessage("Property", "done2"), + ], }, { code: "QUnit.module({ setup: function (assert) { var done1, done2; done1 = assert.async(); done2 = assert.async(); done1(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property", "done2")] + errors: [createAsyncCallbackNotCalledMessage("Property", "done2")], }, { code: "QUnit.module({ setup: function (assert) { var done1, done2; done1 = assert.async(); done2 = assert.async(); } });", errors: [ createAsyncCallbackNotCalledMessage("Property", "done1"), - createAsyncCallbackNotCalledMessage("Property", "done2") - ] + createAsyncCallbackNotCalledMessage("Property", "done2"), + ], }, { code: "QUnit.module({ teardown: function (assert) { var done1 = assert.async(), done2 = assert.async(); done1(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property", "done2")] + errors: [createAsyncCallbackNotCalledMessage("Property", "done2")], }, { code: "QUnit.module({ teardown: function (assert) { var done1 = assert.async(), done2 = assert.async(); } });", errors: [ createAsyncCallbackNotCalledMessage("Property", "done1"), - createAsyncCallbackNotCalledMessage("Property", "done2") - ] + createAsyncCallbackNotCalledMessage("Property", "done2"), + ], }, { code: "QUnit.module({ teardown: function (assert) { var done1, done2; done1 = assert.async(); done2 = assert.async(); done1(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property", "done2")] + errors: [createAsyncCallbackNotCalledMessage("Property", "done2")], }, { code: "QUnit.module({ teardown: function (assert) { var done1, done2; done1 = assert.async(); done2 = assert.async(); } });", errors: [ createAsyncCallbackNotCalledMessage("Property", "done1"), - createAsyncCallbackNotCalledMessage("Property", "done2") - ] + createAsyncCallbackNotCalledMessage("Property", "done2"), + ], }, { code: "QUnit.module({ beforeEach: function (assert) { var done1 = assert.async(), done2 = assert.async(); done1(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property", "done2")] + errors: [createAsyncCallbackNotCalledMessage("Property", "done2")], }, { code: "QUnit.module({ beforeEach: function (assert) { var done1 = assert.async(), done2 = assert.async(); } });", errors: [ createAsyncCallbackNotCalledMessage("Property", "done1"), - createAsyncCallbackNotCalledMessage("Property", "done2") - ] + createAsyncCallbackNotCalledMessage("Property", "done2"), + ], }, { code: "QUnit.module({ beforeEach: function (assert) { var done1, done2; done1 = assert.async(); done2 = assert.async(); done1(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property", "done2")] + errors: [createAsyncCallbackNotCalledMessage("Property", "done2")], }, { code: "QUnit.module({ beforeEach: function (assert) { var done1, done2; done1 = assert.async(); done2 = assert.async(); } });", errors: [ createAsyncCallbackNotCalledMessage("Property", "done1"), - createAsyncCallbackNotCalledMessage("Property", "done2") - ] + createAsyncCallbackNotCalledMessage("Property", "done2"), + ], }, { code: "QUnit.module({ afterEach: function (assert) { var done1 = assert.async(), done2 = assert.async(); done1(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property", "done2")] + errors: [createAsyncCallbackNotCalledMessage("Property", "done2")], }, { code: "QUnit.module({ afterEach: function (assert) { var done1 = assert.async(), done2 = assert.async(); } });", errors: [ createAsyncCallbackNotCalledMessage("Property", "done1"), - createAsyncCallbackNotCalledMessage("Property", "done2") - ] + createAsyncCallbackNotCalledMessage("Property", "done2"), + ], }, { code: "QUnit.module({ afterEach: function (assert) { var done1, done2; done1 = assert.async(); done2 = assert.async(); done1(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property", "done2")] + errors: [createAsyncCallbackNotCalledMessage("Property", "done2")], }, { code: "QUnit.module({ afterEach: function (assert) { var done1, done2; done1 = assert.async(); done2 = assert.async(); } });", errors: [ createAsyncCallbackNotCalledMessage("Property", "done1"), - createAsyncCallbackNotCalledMessage("Property", "done2") - ] + createAsyncCallbackNotCalledMessage("Property", "done2"), + ], }, // assert.async callback can be invoked via .call/.apply { code: "QUnit.test('name', function (assert) { var done1 = assert.async(), done2 = assert.async(); done1.call(); });", - errors: [createAsyncCallbackNotCalledMessage("CallExpression", "done2")] + errors: [ + createAsyncCallbackNotCalledMessage("CallExpression", "done2"), + ], }, { code: "QUnit.test('name', function (assert) { var done1 = assert.async(), done2 = assert.async(); done1.apply(); });", - errors: [createAsyncCallbackNotCalledMessage("CallExpression", "done2")] + errors: [ + createAsyncCallbackNotCalledMessage("CallExpression", "done2"), + ], }, // start/stop calls outside of test context should not affect count { code: "start(); asyncTest('name', function () {});", - errors: [createNeedStartCallsMessage("CallExpression")] + errors: [createNeedStartCallsMessage("CallExpression")], }, { code: "start(); test('name', function () { stop(); });", - errors: [createNeedStartCallsMessage("CallExpression")] + errors: [createNeedStartCallsMessage("CallExpression")], }, { code: "stop(); asyncTest('name', function () {});", - errors: [createNeedStartCallsMessage("CallExpression")] + errors: [createNeedStartCallsMessage("CallExpression")], }, { code: "stop(); test('name', function () { stop(); });", - errors: [createNeedStartCallsMessage("CallExpression")] + errors: [createNeedStartCallsMessage("CallExpression")], }, // assert.async() calls outside of test context should not matter { code: "var done = assert.async(); asyncTest('name', function () { done(); });", - errors: [createNeedStartCallsMessage("CallExpression")] + errors: [createNeedStartCallsMessage("CallExpression")], }, { code: "var done1 = assert.async(); QUnit.test('name', function (assert) { var done2 = assert.async(); done1(); });", - errors: [createAsyncCallbackNotCalledMessage("CallExpression", "done2")] + errors: [ + createAsyncCallbackNotCalledMessage("CallExpression", "done2"), + ], }, // async calls can be done using a different variable { code: "QUnit.test('name', function (foo) { var done = foo.async(); });", - errors: [createAsyncCallbackNotCalledMessage("CallExpression")] + errors: [createAsyncCallbackNotCalledMessage("CallExpression")], }, { code: "QUnit.test('name', (foo) => { var done = foo.async(); });", parserOptions: { ecmaVersion: 6 }, - errors: [createAsyncCallbackNotCalledMessage("CallExpression")] + errors: [createAsyncCallbackNotCalledMessage("CallExpression")], }, { code: "QUnit.module({ setup: function (foo) { var done = foo.async(); } });", - errors: [createAsyncCallbackNotCalledMessage("Property")] - } - ] - + errors: [createAsyncCallbackNotCalledMessage("Property")], + }, + ], });