Bug 1358310 - eslint-plugin-mozilla: Fix infinite loop when finding repo root. r=mossop
authorMike Cooper <mcooper@mozilla.com>
Tue, 25 Apr 2017 14:12:31 -0700
changeset 403026 c1db498519cd435b1d4af51ed6147bd13846d0fe
parent 403025 73b97e528623649a616ac9d9692ebac532638ece
child 403027 939575bd231f9af1614bf12dd773b8b58585040c
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
bugs1358310
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 1358310 - eslint-plugin-mozilla: Fix infinite loop when finding repo root. r=mossop MozReview-Commit-ID: KrOH7qtiLwS
tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.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
@@ -521,22 +521,26 @@ module.exports = {
    * Gets the root directory of the repository by walking up directories from
    * this file until a .eslintignore file is found.
    * @return {String} The absolute path of the repository directory
    */
   get rootDir() {
     if (!gRootDir) {
       let dirName = path.dirname(module.filename);
 
-      while (dirName && !fs.existsSync(path.join(dirName, ".eslintignore"))) {
-        dirName = path.dirname(dirName);
-      }
-
-      if (!dirName) {
-        throw new Error("Unable to find root of repository");
+      while (true) {
+        const parsed = path.parse(dirName);
+        if (parsed.root === dirName) {
+          // We've reached the top of the filesystem
+          throw new Error("Unable to find root of repository");
+        }
+        dirName = parsed.dir;
+        if (fs.existsSync(path.join(dirName, ".eslintignore"))) {
+          break;
+        }
       }
 
       gRootDir = dirName;
     }
 
     return gRootDir;
   },
 
--- 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.45",
+  "version": "0.2.46",
   "description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
   "keywords": [
     "eslint",
     "eslintplugin",
     "eslint-plugin",
     "mozilla",
     "firefox"
   ],