Bug 1358310 - eslint-plugin-mozilla: Fix infinite loop when finding repo root. r?mossop
MozReview-Commit-ID: KrOH7qtiLwS
--- 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"
],