Bug 1358418 - Be more informative about which file ESLint is failing on when getASTSource() hits a computed member expression. r=mossop
☠☠ backed out by a96b9b020f1c ☠ ☠
authorMark Banner <standard8@mozilla.com>
Fri, 21 Apr 2017 10:10:54 +0100
changeset 567680 93bf1142be38aa8855cf9d6f2b25cd55b0d2a2c6
parent 567679 eec770d062b42f8c12f01391b4e715a7f082b2cf
child 567681 42dcfd6e6b0193dde6b7739ca93bed1de8799807
push id55664
push userbmo:standard8@mozilla.com
push dateTue, 25 Apr 2017 11:49:25 +0000
reviewersmossop
bugs1358418
milestone55.0a1
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
tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/avoid-removeChild.js
tools/lint/eslint/eslint-plugin-mozilla/package.json
--- 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"
   ],