Bug 1264063 - 2 - Make the CPOW rule log errors and ignore ContentTask.spawn; r=Mossop
authorPatrick Brosset <pbrosset@mozilla.com>
Wed, 13 Apr 2016 11:05:04 +0200
changeset 331046 c61fcac04879527762383a702a7d39957085aca3
parent 331045 32d2e4645dde3cdbdaec76721f733b95c8bf7ef5
child 331047 625ed96745ea86e9db9de05cbb459acd19512de2
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs1264063
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1264063 - 2 - Make the CPOW rule log errors and ignore ContentTask.spawn; r=Mossop MozReview-Commit-ID: KN2MAgAvX2c
devtools/.eslintrc
devtools/client/responsive.html/test/browser/browser_viewport_basics.js
testing/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js
--- a/devtools/.eslintrc
+++ b/devtools/.eslintrc
@@ -28,17 +28,17 @@
   },
   "rules": {
     // These are the rules that have been configured so far to match the
     // devtools coding style.
 
     // Rules from the mozilla plugin
     "mozilla/mark-test-function-used": 1,
     "mozilla/no-aArgs": 1,
-    "mozilla/no-cpows-in-tests": 1,
+    "mozilla/no-cpows-in-tests": 2,
     // See bug 1224289.
     "mozilla/reject-importGlobalProperties": 1,
     "mozilla/var-only-at-top-level": 1,
 
     // Rules from the React plugin
     "react/display-name": 2,
     "react/no-danger": 2,
     "react/no-did-mount-set-state": 2,
--- a/devtools/client/responsive.html/test/browser/browser_viewport_basics.js
+++ b/devtools/client/responsive.html/test/browser/browser_viewport_basics.js
@@ -19,12 +19,12 @@ addRDMTask(TEST_URL, function* ({ ui }) 
   is(ui.toolWindow.getComputedStyle(viewport).getPropertyValue("width"),
      "320px", "Viewport has default width");
   is(ui.toolWindow.getComputedStyle(viewport).getPropertyValue("height"),
      "480px", "Viewport has default height");
 
   // Browser's location should match original tab
   yield waitForFrameLoad(ui, TEST_URL);
   let location = yield spawnViewportTask(ui, {}, function* () {
-    return content.location.href;
+    return content.location.href; // eslint-disable-line
   });
   is(location, TEST_URL, "Viewport location matches");
 });
--- a/testing/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js
+++ b/testing/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js
@@ -17,34 +17,61 @@ var helpers = require("../helpers");
 var cpows = [
   /^gBrowser\.contentWindow/,
   /^gBrowser\.contentDocument/,
   /^gBrowser\.selectedBrowser.contentWindow/,
   /^browser\.contentDocument/,
   /^window\.content/
 ];
 
+var isInContentTask = false;
+
 module.exports = function(context) {
   // ---------------------------------------------------------------------------
   // Helpers
   // ---------------------------------------------------------------------------
 
   function showError(node, identifier) {
+    if (isInContentTask) {
+      return;
+    }
+
     context.report({
       node: node,
       message: identifier +
                " is a possible Cross Process Object Wrapper (CPOW)."
     });
   }
 
+  function isContentTask(node) {
+    return node &&
+           node.type === "MemberExpression" &&
+           node.property.type === "Identifier" &&
+           node.property.name === "spawn" &&
+           node.object.type === "Identifier" &&
+           node.object.name === "ContentTask";
+  }
+
   // ---------------------------------------------------------------------------
   // Public
   // ---------------------------------------------------------------------------
 
   return {
+    CallExpression: function(node) {
+      if (isContentTask(node.callee)) {
+        isInContentTask = true;
+      }
+    },
+
+    "CallExpression:exit": function(node) {
+      if (isContentTask(node.callee)) {
+        isInContentTask = false;
+      }
+    },
+
     MemberExpression: function(node) {
       if (!helpers.getIsBrowserMochitest(this)) {
         return;
       }
 
       var expression = context.getSource(node);
 
       // Only report a single CPOW error per node -- so if checking
@@ -72,15 +99,14 @@ module.exports = function(context) {
       var expression = context.getSource(node);
       if (expression == "content" || /^content\./.test(expression)) {
         if (node.parent.type === "MemberExpression" &&
             node.parent.object &&
             node.parent.object.type === "Identifier" &&
             node.parent.object.name != "content") {
           return;
         }
-
         showError(node, expression);
         return;
       }
     }
   };
 };