Backed out changeset c88863b64010 (bug 1312355) for eslint bustage. r=backout
authorSebastian Hengst <archaeopteryx@coole-files.de>
Tue, 01 Nov 2016 20:43:18 +0100
changeset 347129 8d658d7287efedce6375dd0a3cbfddbe21e723ee
parent 347128 c88863b6401043a0b951a6ddd983d0ca3b93e1d3
child 347130 2694e55d59724696f972f3404f3064cdf2480be0
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1312355
milestone52.0a1
backs outc88863b6401043a0b951a6ddd983d0ca3b93e1d3
Backed out changeset c88863b64010 (bug 1312355) for eslint bustage. r=backout
toolkit/mozapps/extensions/internal/XPIProvider.jsm
tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js
tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js
tools/lint/eslint/eslint-plugin-mozilla/package.json
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -13,16 +13,17 @@ this.EXPORTED_SYMBOLS = ["XPIProvider"];
 
 const CONSTANTS = {};
 Cu.import("resource://gre/modules/addons/AddonConstants.jsm", CONSTANTS);
 const { ADDON_SIGNING, REQUIRE_SIGNING } = CONSTANTS
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/AddonManager.jsm");
+/* globals AddonManagerPrivate*/
 Cu.import("resource://gre/modules/Preferences.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "AddonRepository",
                                   "resource://gre/modules/addons/AddonRepository.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ChromeManifestParser",
                                   "resource://gre/modules/ChromeManifestParser.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager",
                                   "resource://gre/modules/LightweightThemeManager.jsm");
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js
@@ -65,17 +65,16 @@ const globalCache = new Map();
  * parents parameter which is a list of the parent nodes of the current node.
  * Each returns an array of globals found.
  *
  * @param  {String} path
  *         The absolute path of the file being parsed.
  */
 function GlobalsForNode(path) {
   this.path = path;
-  this.root = helpers.getRootDir(path);
 }
 
 GlobalsForNode.prototype = {
   BlockComment(node, parents) {
     let value = node.value.trim();
     let match = /^import-globals-from\s+(.+)$/.exec(value);
     if (!match) {
       return [];
@@ -88,18 +87,18 @@ GlobalsForNode.prototype = {
       filePath = path.resolve(dirName, filePath);
     }
 
     return module.exports.getGlobalsForFile(filePath);
   },
 
   ExpressionStatement(node, parents) {
     let isGlobal = helpers.getIsGlobalScope(parents);
-    let names = helpers.convertExpressionToGlobals(node, isGlobal, this.root);
-    return names.map(name => { return { name, writable: true }});
+    let name = helpers.convertExpressionToGlobal(node, isGlobal);
+    return name ? [{ name, writable: true}] : [];
   },
 };
 
 module.exports = {
   /**
    * Returns all globals for a given file. Recursively searches through
    * import-globals-from directives and also includes globals defined by
    * standard eslint directives.
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
@@ -7,18 +7,16 @@
 "use strict";
 
 var escope = require("escope");
 var espree = require("espree");
 var estraverse = require("estraverse");
 var path = require("path");
 var fs = require("fs");
 
-var modules = null;
-
 var definitions = [
   /^loader\.lazyGetter\(this, "(\w+)"/,
   /^loader\.lazyImporter\(this, "(\w+)"/,
   /^loader\.lazyServiceGetter\(this, "(\w+)"/,
   /^loader\.lazyRequireGetter\(this, "(\w+)"/,
   /^XPCOMUtils\.defineLazyGetter\(this, "(\w+)"/,
   /^XPCOMUtils\.defineLazyModuleGetter\(this, "(\w+)"/,
   /^XPCOMUtils\.defineLazyServiceGetter\(this, "(\w+)"/,
@@ -27,17 +25,17 @@ var definitions = [
   /^DevToolsUtils\.defineLazyGetter\(this, "(\w+)"/,
   /^Object\.defineProperty\(this, "(\w+)"/,
   /^Reflect\.defineProperty\(this, "(\w+)"/,
   /^this\.__defineGetter__\("(\w+)"/,
   /^this\.(\w+) =/
 ];
 
 var imports = [
-  /^(?:Cu|Components\.utils)\.import\(".*\/((.*?)\.jsm?)"(?:, this)?\)/,
+  /^(?:Cu|Components\.utils)\.import\(".*\/(.*?)\.jsm?"(?:, this)?\)/,
 ];
 
 module.exports = {
   /**
    * Gets the abstract syntax tree (AST) of the JavaScript source code contained
    * in sourceText.
    *
    * @param  {String} sourceText
@@ -149,70 +147,60 @@ module.exports = {
       }
     });
     if (parents.length) {
       throw new Error("Entered more nodes than left.");
     }
   },
 
   /**
-   * Attempts to convert an ExpressionStatement to likely global variable
-   * definitions.
+   * Attempts to convert an ExpressionStatement to a likely global variable
+   * definition.
    *
    * @param  {Object} node
    *         The AST node to convert.
    * @param  {boolean} isGlobal
-   *         True if the current node is in the global scope.
-   * @param  {String} repository
-   *         The root of the repository.
+   *         True if the current node is in the global scope
    *
-   * @return {Array}
-   *         An array of variable names defined.
+   * @return {String or null}
+   *         The variable name defined.
    */
-  convertExpressionToGlobals: function(node, isGlobal, repository) {
-    if (!modules) {
-      modules = require(path.join(repository, "tools", "lint", "eslint", "modules.json"));
-    }
-
+  convertExpressionToGlobal: function(node, isGlobal) {
     try {
       var source = this.getASTSource(node);
     }
     catch (e) {
-      return [];
+      return null;
     }
 
     for (var reg of definitions) {
       var match = source.match(reg);
       if (match) {
         // Must be in the global scope
         if (!isGlobal) {
-          return [];
+          return null;
         }
 
-        return [match[1]];
+        return match[1];
       }
     }
 
     for (reg of imports) {
       var match = source.match(reg);
       if (match) {
         // The two argument form is only acceptable in the global scope
         if (node.expression.arguments.length > 1 && !isGlobal) {
-          return [];
+          return null;
         }
 
-        if (match[1] in modules) {
-          return modules[match[1]];
-        }
-
-        return [match[2]];
+        return match[1];
       }
     }
 
-    return [];
+    return null;
   },
 
   /**
    * Add a variable to the current scope.
    * HACK: This relies on eslint internals so it could break at any time.
    *
    * @param {String} name
    *        The variable name to add to the scope.
@@ -364,22 +352,23 @@ module.exports = {
     }
 
     return this.getIsBrowserMochitest(scope);
   },
 
   /**
    * Gets the root directory of the repository by walking up directories until
    * a .eslintignore file is found.
-   * @param {String} fileName
-   *        The absolute path of a file in the repository
+   * @param {ASTContext} context
+   *        The current context.
    *
    * @return {String} The absolute path of the repository directory
    */
-  getRootDir: function(fileName) {
+  getRootDir: function(context) {
+    var fileName = this.getAbsoluteFilePath(context);
     var dirName = path.dirname(fileName);
 
     while (dirName && !fs.existsSync(path.join(dirName, ".eslintignore"))) {
       dirName = path.dirname(dirName);
     }
 
     if (!dirName) {
       throw new Error("Unable to find root of repository");
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js
@@ -55,18 +55,17 @@ const SCRIPTS = [
 module.exports = function(context) {
   return {
     Program: function(node) {
       if (!helpers.getIsBrowserMochitest(this) &&
           !helpers.getIsHeadFile(this)) {
         return;
       }
 
-      let filepath = helpers.getAbsoluteFilePath(context);
-      let root = helpers.getRootDir(filepath);
+      let root = helpers.getRootDir(context);
       for (let script of SCRIPTS) {
         let fileName = path.join(root, script);
         try {
           let newGlobals = globals.getGlobalsForFile(fileName);
           helpers.addGlobals(newGlobals, context.getScope());
         } catch (e) {
           context.report(
             node,
--- 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.4",
+  "version": "0.2.3",
   "description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
   "keywords": [
     "eslint",
     "eslintplugin",
     "eslint-plugin",
     "mozilla",
     "firefox"
   ],