-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
ESLint doesn't work as a fixer when ESLint used with plugins and run in a parent directory of the project #3143
Comments
@w0rp follow-up for #978 (comment) I made a repo with a minimal repro case. It seems the issue only occurs when there are ESLint plugins in use (ESLint can find the config but not the plugins). cd-ing to the directory of the file (like when linting) should hopefully fix it anyway. |
perhaps related: I'm working in a monorepo that uses Yarn Workspaces where the top level has all the eslint stuff (top level package.json with eslintConfig, node_modules/eslint). I'm trying out SpaceVim/nvim using ALE instead of the default Neomake. It seems like ALE is cd'ing into the child package but that's no good in my case: it should stay put at the root level. Monorepo structure nvim
running manually from
|
ah, reading the source code it looks like the logic is find the |
I really don't like the change ESLint made to how it deals with project roots. It seems like every project that runs ESLInt will have to separately implement its own logic to discover where the ESLint configuration file is to know where to run ESLint from. That seems like a step backwards to me. SublimeLinter had the same issue: https://github.com/SublimeLinter/SublimeLinter/pull/1649/files My suggestion is to always create an ESLint configuration file in the same directory as your |
I agree. Good find on the SublimeLinter issue. I also agree that current logic of running from the nearest directory with
Or perhaps some combination of the above with fallback? |
I've merged that pull request for the fixers now to fix #3094. If anyone knows a way to fix this issue without potentially breaking other things, tag me in a pull request, and someone can look at it eventually. What you can do now is create ESLint configuration files in every directory that has |
ok, I figured out a solution for my case that does not require any further changes to this code. The issue is that I'm using the
the documentation explicitly says:
I found I was able to add a
to override the parent config but inherit the rest. A little annoying but maybe better than further complicating the Interestingly modifying |
@kevinoid I'm back 🤦 my team is mostly on VSCode - I'm the outlier. installing the eslint plugin for VSCode just works out of the box for our current setup. The team is not hot on my adding a duplicate Edit: some are on Intellij which also "just works" as-is... so... it would be awesome, if you have the time, to implement that more subtle |
Using the nearest directory with node_modules does not work correctly for nested projects where the eslint dependencies are in the outer project. For example: dense-analysis#3143 (comment) Adopt the behavior of SublimeLinter, which runs from project_root determined by the presence of the eslint executable in node_modules/.bin (or eslint in dependencies/devDependencies of package.json, which we can add later as necessary). See [NodeLinter#find_local_executable]. [NodeLinter#find_local_executable]: https://github.com/SublimeLinter/SublimeLinter/blob/056e6f6/lint/base_linter/node_linter.py#L109 Signed-off-by: Kevin Locke <[email protected]>
Thanks for the updates @joeldodge79. Taking a closer look, I think the original issue here and in #2997 can be closed as fixed by #3096. The issue described in #3143 (comment) is different (it's not fixer-specific and is due to I also took a closer look at how SublimeLinter works, and I like the idea of choosing the directory where eslint is installed as the project root for eslint. I've created #3222 to implement that behavior. You you could test the PR to confirm it fixes your issue, I'd appreciate it. |
* Split FindNearestExecutable from FindExecutable The path searching in ale#node#FindExecutable() will be useful for eslint. Refactor it into a separate function so it can be used without regard for the state of the _use_global and _executable variables. Signed-off-by: Kevin Locke <[email protected]> * eslint: Set project root from local executable Using the nearest directory with node_modules does not work correctly for nested projects where the eslint dependencies are in the outer project. For example: #3143 (comment) Adopt the behavior of SublimeLinter, which runs from project_root determined by the presence of the eslint executable in node_modules/.bin (or eslint in dependencies/devDependencies of package.json, which we can add later as necessary). See [NodeLinter#find_local_executable]. [NodeLinter#find_local_executable]: https://github.com/SublimeLinter/SublimeLinter/blob/056e6f6/lint/base_linter/node_linter.py#L109 Signed-off-by: Kevin Locke <[email protected]>
I've merged #3222 now, so that should fix this. |
* Split FindNearestExecutable from FindExecutable The path searching in ale#node#FindExecutable() will be useful for eslint. Refactor it into a separate function so it can be used without regard for the state of the _use_global and _executable variables. Signed-off-by: Kevin Locke <[email protected]> * eslint: Set project root from local executable Using the nearest directory with node_modules does not work correctly for nested projects where the eslint dependencies are in the outer project. For example: #3143 (comment) Adopt the behavior of SublimeLinter, which runs from project_root determined by the presence of the eslint executable in node_modules/.bin (or eslint in dependencies/devDependencies of package.json, which we can add later as necessary). See [NodeLinter#find_local_executable]. [NodeLinter#find_local_executable]: https://github.com/SublimeLinter/SublimeLinter/blob/056e6f6/lint/base_linter/node_linter.py#L109 Signed-off-by: Kevin Locke <[email protected]>
Can confirm that #2997 does indeed seem to fixed. I'll go ahead and close it. Thanks a bunch! Hope I'll have some time soon to delve more into Vimscript so I can contribute more than just reporting bugs! |
Information
Operating System: macOS Catalina 10.15.2 (19C57)
What went wrong
When running ESLint as a fixer ALE is not cd-ing into the file's directory like it does when it runs ESLint as a linter:
In such case ESLint is run in Vim's
:pwd
, in my case/Users/juliusz/repos/ale-bug
, while it should run in/Users/juliusz/repos/ale-bug/project
which is where.eslintrc.js
andnode_modules
are. This results in ESLint not being able to find the plugins and exiting with status 2. Doing:cd project
makes ESLint work as a fixer.If I try running ESLint manually while in
/Users/juliusz/repos/ale-bug
it outputs this (this output doesn't show up in:ALEInfo
since it's stderr):Reproducing the bug
Assuming the following Vim config:
git clone https://github.com/jgonera/ale-bug.git
cd ale-bug
(n)vim project/src/index.js
ALE will correctly highlight
123 === NUMBER
as a linting error foryoda
ESLint rule, but:ALEFix
will not fix it. If you run:cd project
and then:ALEFix
, then everything will work.The text was updated successfully, but these errors were encountered: