diff --git a/devtools/.eslintrc b/devtools/.eslintrc index 1fa8ed023ece..c9d1362fe17a 100644 --- a/devtools/.eslintrc +++ b/devtools/.eslintrc @@ -33,7 +33,7 @@ // 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, diff --git a/devtools/client/responsive.html/test/browser/browser_viewport_basics.js b/devtools/client/responsive.html/test/browser/browser_viewport_basics.js index f06dd582cf70..86fc41da9232 100644 --- a/devtools/client/responsive.html/test/browser/browser_viewport_basics.js +++ b/devtools/client/responsive.html/test/browser/browser_viewport_basics.js @@ -24,7 +24,7 @@ addRDMTask(TEST_URL, function* ({ ui }) { // 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"); }); diff --git a/testing/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js b/testing/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js index 82a823027751..96a7b301c34e 100644 --- a/testing/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js +++ b/testing/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js @@ -22,12 +22,18 @@ var cpows = [ /^window\.content/ ]; +var isInContentTask = false; + module.exports = function(context) { // --------------------------------------------------------------------------- // Helpers // --------------------------------------------------------------------------- function showError(node, identifier) { + if (isInContentTask) { + return; + } + context.report({ node: node, message: identifier + @@ -35,11 +41,32 @@ module.exports = function(context) { }); } + 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; @@ -77,7 +104,6 @@ module.exports = function(context) { node.parent.object.name != "content") { return; } - showError(node, expression); return; }