Bug 1358310 - eslint-plugin-mozilla: Fix infinite loop when finding repo root. r?mossop draft
authorMike Cooper <mcooper@mozilla.com>
Tue, 25 Apr 2017 14:12:31 -0700
changeset 568305 c578bea9228b9b1be802167f26167c1a9ead57f4
parent 568252 3f0c8da53c5cb015933b10b52ded3f30432b378a
child 625878 f03041a20f424d948203a02e87edd4b31a2721a5
push id55819
push userbmo:mcooper@mozilla.com
push dateTue, 25 Apr 2017 22:46:29 +0000
reviewersmossop
bugs1358310
milestone55.0a1
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"
   ],