Bug 1808400 - Handle cases of .then(foo, Cu.reportError) in ESLint rule no-cu-reportError. r=mossop

Differential Revision: https://phabricator.services.mozilla.com/D167520
This commit is contained in:
Mark Banner
2023-01-23 18:09:04 +00:00
parent 24d67b71d0
commit 774d70b85f
10 changed files with 54 additions and 49 deletions

View File

@@ -1854,7 +1854,7 @@ var gSync = {
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
navbar.overflowable.show().then(() => {
PanelUI.showSubView("PanelUI-remotetabs", anchor);
}, Cu.reportError);
}, console.error);
} else {
// It is placed somewhere else - just try and show it.
PanelUI.showSubView("PanelUI-remotetabs", anchor);

View File

@@ -3923,7 +3923,7 @@ BrowserGlue.prototype = {
.catch(console.error)
.then(() => enableProfilerButton(wasAddonActive))
.catch(console.error);
}, Cu.reportError);
}, console.error);
}
// Clear unused socks proxy backup values - see bug 1625773.

View File

@@ -647,7 +647,7 @@ var gEditItemOverlay = {
if (this._paneInfo) {
this._mayUpdateFirstEditField("tagsField");
}
}, Cu.reportError);
}, console.error);
}
},

View File

@@ -626,7 +626,7 @@ var gEditItemOverlay = {
if (anyChanges && this._paneInfo) {
this._mayUpdateFirstEditField("tagsField");
}
}, Cu.reportError);
}, console.error);
}
},

View File

@@ -1160,7 +1160,7 @@ add_setup(function test_common_initialize() {
aResponse.finish();
info("Aborting response with network reset.");
})
.then(null, Cu.reportError);
.then(null, console.error);
});
// During unit tests, most of the functions that require profile access or

View File

@@ -316,7 +316,7 @@ EnterprisePoliciesManager.prototype = {
break;
case "EnterprisePolicies:Restart":
this._restart().then(null, Cu.reportError);
this._restart().then(null, console.error);
break;
}
},

View File

@@ -564,7 +564,7 @@ function sendConsoleAPIMessage(aConsole, aLevel, aFrame, aArgs, aOptions = {}) {
consoleEvent.groupName = Array.prototype.join.call(aArgs, " ");
} catch (ex) {
console.error(ex);
Cu.reportError(ex.stack);
console.error(ex.stack);
return;
}
break;

View File

@@ -102,7 +102,7 @@ class nsContentDispatchChooser {
aURI
);
} catch (error) {
Cu.reportError(error.message);
console.error(error.message);
}
if (!shouldOpenHandler) {

View File

@@ -84,28 +84,22 @@ module.exports = {
create(context) {
return {
CallExpression(node) {
let checkNode;
if (
node.arguments.length >= 1 &&
node.arguments[0].type == "MemberExpression"
) {
// Handles cases of `.foo(Cu.reportError)`.
checkNode = node.arguments[0];
} else {
let checkNodes = [];
if (isCuReportError(node.callee)) {
// Handles cases of `Cu.reportError()`.
checkNode = node.callee;
}
if (!isCuReportError(checkNode)) {
return;
}
if (checkNode == node.callee && node.arguments.length > 1) {
if (node.arguments.length > 1) {
// TODO: Bug 1802347 For initial landing, we allow the two
// argument form of Cu.reportError as the second argument is a stack
// argument which is more complicated to deal with.
return;
}
checkNodes = [node.callee];
} else if (node.arguments.length >= 1) {
// Handles cases of `.foo(Cu.reportError)`.
checkNodes = node.arguments.filter(n => isCuReportError(n));
}
for (let checkNode of checkNodes) {
context.report({
node,
fix: fixer => {
@@ -129,6 +123,7 @@ module.exports = {
},
messageId: "useConsoleError",
});
}
},
};
},

View File

@@ -39,11 +39,21 @@ ruleTester.run("no-cu-reportError", rule, {
output: "console.error(bar)",
errors: callError(),
},
{
code: "Cu.reportError(bar.stack)",
output: "console.error(bar.stack)",
errors: callError(),
},
{
code: "foo().catch(Cu.reportError)",
output: "foo().catch(console.error)",
errors: callError(),
},
{
code: "foo().then(bar, Cu.reportError)",
output: "foo().then(bar, console.error)",
errors: callError(),
},
// When referencing identifiers/members, try to reference them rather
// than stringifying:
{