Bug 1230093 - Make the import-headjs-globals rule store variables correctly; r=Mossop
authorPatrick Brosset <pbrosset@mozilla.com>
Thu, 03 Dec 2015 11:17:02 +0100
changeset 275452 4c9ca7614d701d28549ef734d41dcce5ac37cba2
parent 275451 6e27e28a8dfa0028cb5069a6cf5ed885f5d535c7
child 275453 f416176fa1693802b5d7f5fc9b8fd737e48e736e
push id16542
push userpbrosset@mozilla.com
push dateThu, 03 Dec 2015 17:23:56 +0000
treeherderfx-team@4c9ca7614d70 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs1230093
milestone45.0a1
Bug 1230093 - Make the import-headjs-globals rule store variables correctly; r=Mossop
devtools/.eslintrc
testing/eslint-plugin-mozilla/lib/helpers.js
--- a/devtools/.eslintrc
+++ b/devtools/.eslintrc
@@ -249,19 +249,18 @@
     // Allow the use of ternary operators.
     "no-ternary": 0,
     // Disallow throwing literals (eg. throw "error" instead of
     // throw new Error("error")).
     "no-throw-literal": 2,
     // Disallow trailing whitespace at the end of lines.
     "no-trailing-spaces": 2,
     // Disallow use of undeclared variables unless mentioned in a /*global */
-    // block.
-    // This should really be a 2, but until we define all globals in comments
-    // and .eslintrc, keeping this as a 1.
+    // block. Note that globals from head.js are automatically imported in tests
+    // by the import-headjs-globals rule form the mozilla eslint plugin.
     "no-undef": 2,
     // Allow dangling underscores in identifiers (for privates).
     "no-underscore-dangle": 0,
     // Allow use of undefined variable.
     "no-undefined": 0,
     // Disallow the use of Boolean literals in conditional expressions.
     "no-unneeded-ternary": 2,
     // Disallow unreachable statements after a return, throw, continue, or break
--- a/testing/eslint-plugin-mozilla/lib/helpers.js
+++ b/testing/eslint-plugin-mozilla/lib/helpers.js
@@ -124,16 +124,23 @@ module.exports = {
   addVarToScope: function(name, context) {
     var scope = context.getScope();
     var variables = scope.variables;
     var variable = new escope.Variable(name, scope);
 
     variable.eslintExplicitGlobal = false;
     variable.writeable = true;
     variables.push(variable);
+
+    // Since eslint 1.10.3, scope variables are now duplicated in the scope.set
+    // map, so we need to store them there too if it exists.
+    // See https://groups.google.com/forum/#!msg/eslint/Y4_oHMWwP-o/5S57U8jXd8kJ
+    if (scope.set) {
+      scope.set.set(name, variable);
+    }
   },
 
   /**
    * Get the single line text represented by a particular AST node.
    *
    * @param  {ASTNode} node
    *         The AST node representing the source text.
    * @param  {String} text