Bug 1346167 - Make the eslint-plugin-mozilla environments more flexible for when they are used outside of mozilla-central. r?Mossop draft
authorMark Banner <standard8@mozilla.com>
Fri, 10 Mar 2017 11:44:35 +0000
changeset 496852 ada9c33d6d41715a9f97eaddf9109dea69fbd52e
parent 496661 92c5b7bcd598c55f88979c014acfb79fd1ad7e45
child 548718 53aa48205b8f36b71983a4c90f4d7b8210208374
push id48711
push userbmo:standard8@mozilla.com
push dateFri, 10 Mar 2017 19:09:01 +0000
reviewersMossop
bugs1346167
milestone55.0a1
Bug 1346167 - Make the eslint-plugin-mozilla environments more flexible for when they are used outside of mozilla-central. r?Mossop For now, we return virtually no globals for browser-window/places-overlay/simpletest as they aren't able to load the m-c files. Later we may want to find a way of enabling this to work for outside repositories. MozReview-Commit-ID: 8SFVuQuEqfL
tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
tools/lint/eslint/eslint-plugin-mozilla/lib/environments/places-overlay.js
tools/lint/eslint/eslint-plugin-mozilla/lib/environments/simpletest.js
tools/lint/eslint/eslint-plugin-mozilla/package.json
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
@@ -48,17 +48,23 @@ const MAPPINGS = {
 };
 
 const globalScriptsRegExp =
   /<script type=\"application\/javascript\" src=\"(.*)\"\/>/;
 
 function getGlobalScriptsIncludes() {
   let globalScriptsPath = path.join(rootDir, "browser", "base", "content",
                                     "global-scripts.inc");
-  let fileData = fs.readFileSync(globalScriptsPath, {encoding: "utf8"});
+  let fileData;
+  try {
+    fileData = fs.readFileSync(globalScriptsPath, {encoding: "utf8"});
+  } catch (ex) {
+    // The file isn't present, so this isn't an m-c repository.
+    return null;
+  }
 
   fileData = fileData.split("\n");
 
   let result = [];
 
   for (let line of fileData) {
     let match = line.match(globalScriptsRegExp);
     if (match) {
@@ -76,18 +82,22 @@ function getGlobalScriptsIncludes() {
     }
   }
 
   return result;
 }
 
 function getScriptGlobals() {
   let fileGlobals = [];
-  var scripts = EXTRA_SCRIPTS.concat(getGlobalScriptsIncludes());
-  for (let script of scripts) {
+  let scripts = getGlobalScriptsIncludes();
+  if (!scripts) {
+    return [];
+  }
+
+  for (let script of scripts.concat(EXTRA_SCRIPTS)) {
     let fileName = path.join(rootDir, script);
     try {
       fileGlobals = fileGlobals.concat(globals.getGlobalsForFile(fileName));
     } catch (e) {
       console.error(`Could not load globals from file ${fileName}: ${e}`);
       console.error(
         `You may need to update the mappings in ${module.filename}`);
       throw new Error(`Could not load globals from file ${fileName}: ${e}`);
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/places-overlay.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/places-overlay.js
@@ -47,17 +47,17 @@ const placesOverlayModules = [
 
 function getScriptGlobals() {
   let fileGlobals = [];
   for (let file of placesOverlayFiles) {
     let fileName = path.join(root, file);
     try {
       fileGlobals = fileGlobals.concat(globals.getGlobalsForFile(fileName));
     } catch (e) {
-      throw new Error(`Could not load globals from file ${fileName}: ${e}`);
+      // The file isn't present, this is probably not an m-c repo.
     }
   }
 
   for (let file of placesOverlayModules) {
     if (file in modules) {
       for (let globalVar of modules[file]) {
         fileGlobals.push({name: globalVar, writable: false});
       }
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/simpletest.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/simpletest.js
@@ -28,17 +28,18 @@ const simpleTestPath = "testing/mochites
 function getScriptGlobals() {
   let fileGlobals = [];
   let root = helpers.getRootDir(module.filename);
   for (let file of simpleTestFiles) {
     let fileName = path.join(root, simpleTestPath, file);
     try {
       fileGlobals = fileGlobals.concat(globals.getGlobalsForFile(fileName));
     } catch (e) {
-      throw new Error(`Could not load globals from file ${fileName}: ${e}`);
+      // The files may not be available in non-m-c repositories.
+      return [];
     }
   }
 
   return fileGlobals;
 }
 
 function mapGlobals(fileGlobals) {
   var globalObjects = {};
--- 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.28",
+  "version": "0.2.29",
   "description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
   "keywords": [
     "eslint",
     "eslintplugin",
     "eslint-plugin",
     "mozilla",
     "firefox"
   ],
@@ -23,15 +23,15 @@
     "escope": "^3.6.0",
     "espree": "^3.2.0",
     "estraverse": "^4.2.0",
     "globals": "^9.14.0",
     "ini-parser": "^0.0.2",
     "sax": "^1.1.4"
   },
   "engines": {
-    "node": ">=4.2.0"
+    "node": ">=6.9.1"
   },
   "scripts": {
     "test": "node tests/test-run-all.js"
   },
   "license": "MPL-2.0"
 }