New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: wrong baseDir (fixes #6450) #6457
Conversation
LGTM |
By analyzing the blame information on this pull request, we identified @nzakas, @SpainTrain and @MethodGrab to be potential reviewers |
@@ -315,6 +315,10 @@ function getBaseDir(configFilePath) { | |||
// calculates the path of the project including ESLint as dependency | |||
var projectPath = path.resolve(__dirname, "../../../"); | |||
|
|||
if (path.basename(projectPath) === "node_modules") { | |||
projectPath = path.dirname(projectPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yikes! This seems like a fragile test, there has to be something else going on.
LGTM |
4c80417
to
c569e40
Compare
I modified it, just add Before
After
|
This fixes the problem for us (using |
That looks much better then the check for |
@@ -313,7 +313,7 @@ function write(config, filePath) { | |||
function getBaseDir(configFilePath) { | |||
|
|||
// calculates the path of the project including ESLint as dependency | |||
var projectPath = path.resolve(__dirname, "../../../"); | |||
var projectPath = path.resolve(__dirname, "../../../../"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make sense to me. If this file hasn't moved, then why is this change necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it's wrong.
Do you think this basedir
and lookupPath
are correct?
load( C:\Users\t-nagashima.AD\Documents\GitHub\sandbox\.eslintrc.json undefined undefined )
resolvedPath: { filePath: 'C:\\Users\\t-nagashima.AD\\Documents\\GitHub\\sandbox\\.eslintrc.json' }
dirname: C:\Users\t-nagashima.AD\Documents\GitHub\sandbox
basedir: C:\Users\t-nagashima.AD\Documents\GitHub\sandbox\node_modules
lookupPath: C:\Users\t-nagashima.AD\Documents\GitHub\sandbox\node_modules\node_modules
I think the intention of projectPath
is the root directory of a project which depends on ESLint. But it's not so currently. It's the node_modules
directory of a project which depends on ESLint.
Then basedir
and lookupPath
are calculated from projectPath
.
Then the problematic relativeTo
is the basedir
.
Then it went to wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mysticatea You might be right, in this case basedir
doesn't look right. But with your fix, globally installed ESLint is failing even worse. It's now two directories off from where it should be looking (before this fix, it was one dir off).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilyavolodin I confirmed the problem for globally installed ESLint.
So.... to fix this route cause, do we needs === "node_modules"
check as same as the first way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm...
basedir
is not the location of .eslintrc file for globally installed ESLint...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got it.
We cannot use relativeTo
to resolve relative paths in .eslintrc files.
So #6468 is the correct way to fix this problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering that this parser path is working fine with this wrong basedir
and lookupPath
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirmed the parser path is not working (same as extends
of v2.13.0).
We cannot use the basedir
in order to resolve relative paths.
It also looks like the test isn't reproducing the bug that's being reported. |
I think I figured it out here: #6468 |
Please see my first comment.
|
c569e40
to
7854109
Compare
LGTM |
1 similar comment
LGTM |
7854109
to
7f9145b
Compare
I reverted the change of Then, I found that this parser path is not working as same as So I replaced |
LGTM |
7f9145b
to
60ca62a
Compare
I added some tests.
|
Ah! This looks much better. LGTM |
Fixes #6450
I'm not sure this fix is correct or not. I want to get any insights about
getBaseDir
.And actually, this new test does not make sense. The test succeeds as well before this fix. The issue's error seems to be appeared only if eslint is installed to another package. I'm not sure how to write tests for this fix...