Bug 1264063 - 2 - Make the CPOW rule log errors and ignore ContentTask.spawn; r=Mossop

MozReview-Commit-ID: KN2MAgAvX2c

--HG--
extra : rebase_source : 099489c97f2b0fcae3903cbdd06d43b84e4113b1
This commit is contained in:
Patrick Brosset 2016-04-13 11:05:04 +02:00
parent 5574624f3f
commit f469bf022f
3 changed files with 29 additions and 3 deletions

View File

@ -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,

View File

@ -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");
});

View File

@ -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;
}