Bug 1358418 - Be more informative about which file ESLint is failing on when getASTSource() hits a computed member expression. r?Mossop
MozReview-Commit-ID: GA4bEvJXH3O
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
@@ -75,21 +75,22 @@ module.exports = {
* A simplistic conversion of some AST nodes to a standard string form.
*
* @param {Object} node
* The AST node to convert.
*
* @return {String}
* The JS source for the node.
*/
- getASTSource(node) {
+ getASTSource(node, context) {
switch (node.type) {
case "MemberExpression":
if (node.computed) {
- throw new Error("getASTSource unsupported computed MemberExpression");
+ let filename = context && context.getFilename();
+ throw new Error(`getASTSource unsupported computed MemberExpression in ${filename}`);
}
return this.getASTSource(node.object) + "." +
this.getASTSource(node.property);
case "ThisExpression":
return "this";
case "Identifier":
return node.name;
case "Literal":
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/avoid-removeChild.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/avoid-removeChild.js
@@ -29,25 +29,25 @@ module.exports = function(context) {
callee.property.name != "removeChild" ||
node.arguments.length != 1) {
return;
}
if (callee.object.type == "MemberExpression" &&
callee.object.property.type == "Identifier" &&
callee.object.property.name == "parentNode" &&
- helpers.getASTSource(callee.object.object) ==
+ helpers.getASTSource(callee.object.object, context) ==
helpers.getASTSource(node.arguments[0])) {
context.report(node, "use element.remove() instead of " +
"element.parentNode.removeChild(element)");
}
if (node.arguments[0].type == "MemberExpression" &&
node.arguments[0].property.type == "Identifier" &&
node.arguments[0].property.name == "firstChild" &&
- helpers.getASTSource(callee.object) ==
+ helpers.getASTSource(callee.object, context) ==
helpers.getASTSource(node.arguments[0].object)) {
context.report(node, "use element.firstChild.remove() instead of " +
"element.removeChild(element.firstChild)");
}
}
};
};
--- a/tools/lint/eslint/eslint-plugin-mozilla/package.json
+++ b/tools/lint/eslint/eslint-plugin-mozilla/package.json
@@ -1,11 +1,11 @@
{
"name": "eslint-plugin-mozilla",
- "version": "0.2.42",
+ "version": "0.2.43",
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin",
"mozilla",
"firefox"
],