зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
166d8573cb
Коммит
351482d35e
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -647,7 +647,7 @@ var gEditItemOverlay = {
|
|||
if (this._paneInfo) {
|
||||
this._mayUpdateFirstEditField("tagsField");
|
||||
}
|
||||
}, Cu.reportError);
|
||||
}, console.error);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -626,7 +626,7 @@ var gEditItemOverlay = {
|
|||
if (anyChanges && this._paneInfo) {
|
||||
this._mayUpdateFirstEditField("tagsField");
|
||||
}
|
||||
}, Cu.reportError);
|
||||
}, console.error);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -316,7 +316,7 @@ EnterprisePoliciesManager.prototype = {
|
|||
break;
|
||||
|
||||
case "EnterprisePolicies:Restart":
|
||||
this._restart().then(null, Cu.reportError);
|
||||
this._restart().then(null, console.error);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -102,7 +102,7 @@ class nsContentDispatchChooser {
|
|||
aURI
|
||||
);
|
||||
} catch (error) {
|
||||
Cu.reportError(error.message);
|
||||
console.error(error.message);
|
||||
}
|
||||
|
||||
if (!shouldOpenHandler) {
|
||||
|
|
|
@ -84,51 +84,46 @@ 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 (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));
|
||||
}
|
||||
|
||||
if (checkNode == node.callee && 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;
|
||||
for (let checkNode of checkNodes) {
|
||||
context.report({
|
||||
node,
|
||||
fix: fixer => {
|
||||
let fixes = [
|
||||
fixer.replaceText(checkNode.object, "console"),
|
||||
fixer.replaceText(checkNode.property, "error"),
|
||||
];
|
||||
// If we're adding stuff together as an argument, split
|
||||
// into multiple arguments instead:
|
||||
if (
|
||||
checkNode == node.callee &&
|
||||
isConcatenation(node.arguments[0])
|
||||
) {
|
||||
let { fixes: recursiveFixes } = replaceConcatWithComma(
|
||||
fixer,
|
||||
node.arguments[0]
|
||||
);
|
||||
fixes.push(...recursiveFixes);
|
||||
}
|
||||
return fixes;
|
||||
},
|
||||
messageId: "useConsoleError",
|
||||
});
|
||||
}
|
||||
|
||||
context.report({
|
||||
node,
|
||||
fix: fixer => {
|
||||
let fixes = [
|
||||
fixer.replaceText(checkNode.object, "console"),
|
||||
fixer.replaceText(checkNode.property, "error"),
|
||||
];
|
||||
// If we're adding stuff together as an argument, split
|
||||
// into multiple arguments instead:
|
||||
if (
|
||||
checkNode == node.callee &&
|
||||
isConcatenation(node.arguments[0])
|
||||
) {
|
||||
let { fixes: recursiveFixes } = replaceConcatWithComma(
|
||||
fixer,
|
||||
node.arguments[0]
|
||||
);
|
||||
fixes.push(...recursiveFixes);
|
||||
}
|
||||
return fixes;
|
||||
},
|
||||
messageId: "useConsoleError",
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
|
|
|
@ -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:
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче