Bug 1467712 - add eslint rule to check usage of browser-test ok() draft
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 08 Jun 2018 10:21:55 +0200
changeset 805655 cc2f339a2c2ab44c8df7487004c52aa37c640ea7
parent 805408 fb8a79ada7692d3cb4f973531fb5eb4e90f54476
push id112732
push userjdescottes@mozilla.com
push dateFri, 08 Jun 2018 08:38:08 +0000
bugs1467712
milestone62.0a1
Bug 1467712 - add eslint rule to check usage of browser-test ok() MozReview-Commit-ID: 2rSunmz4Vo9
tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js
tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/max-two-arguments-browser-test-ok.js
--- 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");
+      }
+    }
+  };
+};