Bug 1467712 - add eslint rule to check usage of browser-test ok()
MozReview-Commit-ID: 2rSunmz4Vo9
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js
@@ -57,11 +57,12 @@ module.exports = {
"plugins": [
"mozilla"
],
"rules": {
"mozilla/import-content-task-globals": "error",
"mozilla/import-headjs-globals": "error",
"mozilla/mark-test-function-used": "error",
+ "mozilla/max-two-arguments-browser-test-ok": "error",
"mozilla/no-arbitrary-setTimeout": "error"
}
};
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
@@ -36,16 +36,18 @@ module.exports = {
"import-browser-window-globals":
require("../lib/rules/import-browser-window-globals"),
"import-content-task-globals":
require("../lib/rules/import-content-task-globals"),
"import-globals": require("../lib/rules/import-globals"),
"import-headjs-globals": require("../lib/rules/import-headjs-globals"),
"mark-exported-symbols-as-used": require("../lib/rules/mark-exported-symbols-as-used"),
"mark-test-function-used": require("../lib/rules/mark-test-function-used"),
+ "max-two-arguments-browser-test-ok":
+ require("../lib/rules/max-two-arguments-browser-test-ok"),
"no-aArgs": require("../lib/rules/no-aArgs"),
"no-arbitrary-setTimeout": require("../lib/rules/no-arbitrary-setTimeout"),
"no-compare-against-boolean-literals": require("../lib/rules/no-compare-against-boolean-literals"),
"no-define-cc-etc": require("../lib/rules/no-define-cc-etc"),
"no-single-arg-cu-import": require("../lib/rules/no-single-arg-cu-import"),
"no-import-into-var-and-global":
require("../lib/rules/no-import-into-var-and-global.js"),
"no-task": require("../lib/rules/no-task"),
new file mode 100644
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/max-two-arguments-browser-test-ok.js
@@ -0,0 +1,35 @@
+/**
+ * @fileoverview Reject use of single argument Cu.import
+ *
+ * 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";
+
+// -----------------------------------------------------------------------------
+// Rule Definition
+// -----------------------------------------------------------------------------
+
+module.exports = function(context) {
+
+ // ---------------------------------------------------------------------------
+ // Public
+ // --------------------------------------------------------------------------
+
+ return {
+ "CallExpression": function(node) {
+ let callee = node.callee;
+
+ if (callee.type !== "Identifier") {
+ return;
+ }
+
+ if (callee.name === "ok" &&
+ node.arguments.length > 2) {
+ context.report(node, "browser-test ok() usually takes only 2 arguments");
+ }
+ }
+ };
+};