Bug 1452706 - Remove the now redundant ESLint rule require-expected-throws-or-rejects. r=mikedeboer

MozReview-Commit-ID: 7CXrVV6x5I6

--HG--
extra : rebase_source : ade528621c748547192e562a2fee2f6db9d009ef
This commit is contained in:
Mark Banner 2018-07-03 20:22:01 +01:00
Родитель a952f2e027
Коммит 7a479a6ef5
4 изменённых файлов: 0 добавлений и 137 удалений

Просмотреть файл

@ -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",

Просмотреть файл

@ -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"),

Просмотреть файл

@ -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");
}
}
}
};
}
};

Просмотреть файл

@ -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")
]
});