Bug 1358418 - Be more informative about which file ESLint is failing on when getASTSource() hits a computed member expression. r=Mossop
authorMark Banner <standard8@mozilla.com>
Fri, 21 Apr 2017 10:10:54 +0100
changeset 402862 0d5af288c8693b6cafef739d5b4998b9008bbfc8
parent 402861 a96b9b020f1c57d2d44f48aa7ed60563b8266c99
child 402863 4653b1d21e8702461bab684af135ec8fcddf6cd6
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs1358418
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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"
   ],