Bug 1369829 - Make eslint-plugin-mozilla more flexible with finding the root directory of the repository. r?Mossop
MozReview-Commit-ID: KmQS9RKwf3K
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
@@ -521,36 +521,41 @@ module.exports = {
/**
* Gets the root directory of the repository by walking up directories from
* this file until a .eslintignore file is found. If this fails, the same
* procedure will be attempted from the current working dir.
* @return {String} The absolute path of the repository directory
*/
get rootDir() {
if (!gRootDir) {
- function searchUpForIgnore(dirName) {
+ function searchUpForIgnore(dirName, filename) {
let parsed = path.parse(dirName);
while (parsed.root !== dirName) {
- if (fs.existsSync(path.join(dirName, ".eslintignore"))) {
+ if (fs.existsSync(path.join(dirName, filename))) {
return dirName;
}
// Move up a level
dirName = parsed.dir;
parsed = path.parse(dirName);
}
return null;
}
- let possibleRoot = searchUpForIgnore(path.dirname(module.filename));
+ let possibleRoot = searchUpForIgnore(path.dirname(module.filename), ".eslintignore");
+ if (!possibleRoot) {
+ possibleRoot = searchUpForIgnore(path.resolve(), ".eslintignore");
+ }
if (!possibleRoot) {
- possibleRoot = searchUpForIgnore(path.resolve());
- if (!possibleRoot) {
- // We've couldn't find a root from the module or CWD
- throw new Error("Unable to find root of repository");
- }
+ possibleRoot = searchUpForIgnore(path.resolve(), "package.json");
+ }
+ if (!possibleRoot) {
+ // We've couldn't find a root from the module or CWD, so lets just go
+ // for the CWD. We really don't want to throw if possible, as that
+ // tends to give confusing results when used with ESLint.
+ possibleRoot = process.cwd();
}
gRootDir = possibleRoot;
}
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.3.3",
+ "version": "0.3.4",
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin",
"mozilla",
"firefox"
],