Bug 1358418 - Be more informative about which file ESLint is failing on when getASTSource() hits a computed member expression. r?Mossop draft
authorMark Banner <standard8@mozilla.com>
Fri, 21 Apr 2017 10:10:54 +0100
changeset 567029 28f99b122ac162ac8c9039eb53c0ece6bdff0fc8
parent 566881 73752931e273091185e1e4b5231c28beed657cc8
child 625501 0342567b9368357666f17229e8d4b548ffff26cb
push id55419
push userbmo:standard8@mozilla.com
push dateMon, 24 Apr 2017 10:01:58 +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"
   ],