Bug 1264063 - 2 - Make the CPOW rule log errors and ignore ContentTask.spawn; r=Mossop
MozReview-Commit-ID: KN2MAgAvX2c
--- 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;
}
}
};
};