diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js index db3591d388a0..9163e8e58f91 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js @@ -180,7 +180,6 @@ module.exports = { "mozilla/no-useless-parameters": "error", "mozilla/no-useless-removeEventListener": "error", "mozilla/rejects-requires-await": "error", - "mozilla/require-expected-throws-or-rejects": "error", "mozilla/use-cc-etc": "error", "mozilla/use-chromeutils-generateqi": "error", "mozilla/use-chromeutils-import": "error", diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js index 2d07a6a453cd..129b328c1a2e 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js @@ -54,8 +54,6 @@ module.exports = { require("../lib/rules/no-useless-removeEventListener"), "no-useless-run-test": require("../lib/rules/no-useless-run-test"), - "require-expected-throws-or-rejects": - require("../lib/rules/require-expected-throws-or-rejects"), "reject-importGlobalProperties": require("../lib/rules/reject-importGlobalProperties"), "reject-some-requires": require("../lib/rules/reject-some-requires"), diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/require-expected-throws-or-rejects.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/require-expected-throws-or-rejects.js deleted file mode 100644 index 906ca7f47ebb..000000000000 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/require-expected-throws-or-rejects.js +++ /dev/null @@ -1,71 +0,0 @@ -/** - * @fileoverview Reject use of Cu.importGlobalProperties - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -"use strict"; - -function checkArgs(context, node, name) { - if (node.arguments.length < 2) { - context.report({ - node, - messageId: "needsTwoArguments", - data: { - name - } - }); - return; - } - - if (!("regex" in node.arguments[1]) && - node.arguments[1].type !== "FunctionExpression" && - node.arguments[1].type !== "ArrowFunctionExpression" && - node.arguments[1].type !== "MemberExpression" && - (node.arguments[1].type !== "Identifier" || - node.arguments[1].name === "undefined")) { - context.report({ - node, - messageId: "requireExpected", - data: { - name - } - }); - } -} - -module.exports = { - meta: { - messages: { - needsTwoArguments: "Assert.{{name}} should have at least two arguments (assert, expected).", - requireExpected: "Second argument to Assert.{{name}} should be a RegExp, function or object to compare the exception to." - } - }, - - create(context) { - return { - "CallExpression": function(node) { - if (node.callee.type === "MemberExpression") { - let memexp = node.callee; - if (memexp.object.type === "Identifier" && - memexp.object.name === "Assert" && - memexp.property.type === "Identifier" && - memexp.property.name === "rejects") { - // We have ourselves an Assert.rejects. - checkArgs(context, node, "rejects"); - } - - if (memexp.object.type === "Identifier" && - memexp.object.name === "Assert" && - memexp.property.type === "Identifier" && - memexp.property.name === "throws") { - // We have ourselves an Assert.throws. - checkArgs(context, node, "throws"); - } - } - } - }; - } -}; diff --git a/tools/lint/eslint/eslint-plugin-mozilla/tests/require-expected-throws-or-rejects.js b/tools/lint/eslint/eslint-plugin-mozilla/tests/require-expected-throws-or-rejects.js deleted file mode 100644 index 993dd23234e4..000000000000 --- a/tools/lint/eslint/eslint-plugin-mozilla/tests/require-expected-throws-or-rejects.js +++ /dev/null @@ -1,63 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -// ------------------------------------------------------------------------------ -// Requirements -// ------------------------------------------------------------------------------ - -var rule = require("../lib/rules/require-expected-throws-or-rejects"); -var RuleTester = require("eslint/lib/testers/rule-tester"); - -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); - -// ------------------------------------------------------------------------------ -// Tests -// ------------------------------------------------------------------------------ - -function invalidCode(code, messageId, name) { - return {code, errors: [{messageId, data: {name}}]}; -} - -ruleTester.run("no-useless-run-test", rule, { - valid: [ - "Assert.throws(() => foo(), /assertion/);", - "Assert.throws(() => foo(), /assertion/, 'message');", - "Assert.throws(() => foo(), ex => {}, 'message');", - "Assert.throws(() => foo(), foo, 'message');", - "Assert.rejects(foo, /assertion/)", - "Assert.rejects(foo, /assertion/, 'msg')", - "Assert.rejects(foo, ex => {}, 'msg')", - "Assert.rejects(foo, foo, 'msg')", - "Assert.rejects(foo, foo.bar, 'msg')" - ], - invalid: [ - invalidCode("Assert.throws(() => foo());", - "needsTwoArguments", "throws"), - - invalidCode("Assert.throws(() => foo(), 'message');", - "requireExpected", "throws"), - - invalidCode("Assert.throws(() => foo(), 'invalid', 'message');", - "requireExpected", "throws"), - - invalidCode("Assert.throws(() => foo(), null, 'message');", - "requireExpected", "throws"), - - invalidCode("Assert.throws(() => foo(), undefined, 'message');", - "requireExpected", "throws"), - - invalidCode("Assert.rejects(foo)", - "needsTwoArguments", "rejects"), - - invalidCode("Assert.rejects(foo, 'msg')", - "requireExpected", "rejects"), - - invalidCode("Assert.rejects(foo, 'invalid', 'msg')", - "requireExpected", "rejects"), - - invalidCode("Assert.rejects(foo, undefined, 'msg')", - "requireExpected", "rejects") - ] -});