Skip to content
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(eslint): yarn 2 project cwd #3684

Merged
merged 3 commits into from
Jun 19, 2021
Merged

fix(eslint): yarn 2 project cwd #3684

merged 3 commits into from
Jun 19, 2021

Conversation

shannonmoeller
Copy link
Contributor

Improves logic around detecting a project root based on the presence of eslint in node_modules or .yarn/sdks. Helps with, but still not a complete fix for #2970.

@shannonmoeller shannonmoeller changed the title Eslint project dir fix(eslint): yarn 2 project cwd Apr 9, 2021
@@ -52,14 +52,20 @@ function! ale#handlers#eslint#GetCwd(buffer) abort
let l:executable = ale#node#FindNearestExecutable(a:buffer, s:executables)

if !empty(l:executable)
let l:nmi = strridx(l:executable, 'node_modules')
let l:project_dir = l:executable[0:l:nmi - 2]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was causing the CWD to be set to /path/to/project/.yarn/sdks/eslint/bin/eslint. instead of /path/to/project which made the command fail as eslint. doesn't exist and definitely isn't a directory.

(executable check - success) /path/to/project/.yarn/sdks/eslint/bin/eslint.js
(finished - exit code 1) ['/bin/zsh', '-c', 'cd ''/path/to/project/.yarn/sdks/eslint/bin/eslint.'' && ''/path/to/project/.yarn/sdks/eslint/bin/eslint.js'' -f json --stdin --stdin-filename ''/path/to/project/src/some/file.js'' < ''/var/folders/tr/.../file.js''']

endif

return !empty(l:project_dir) ? l:project_dir : ''
return strlen(l:modules_root) > strlen(l:sdks_root) ? l:modules_root : l:sdks_root
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The longest value is the nearer directory.

@shannonmoeller
Copy link
Contributor Author

Sorry to be noisy, but checking on the status here. I implemented a solution with passing tests. Is there anything else you need from me to get this merged? Thanks.

@w0rp w0rp merged commit 397d56f into dense-analysis:master Jun 19, 2021
@w0rp
Copy link
Member

w0rp commented Jun 19, 2021

Cheers! 🍻

@shannonmoeller shannonmoeller deleted the eslint-project-dir branch June 19, 2021 12:20
@shannonmoeller
Copy link
Contributor Author

Thank you!!

@jsit
Copy link
Contributor

jsit commented Apr 27, 2023

@shannonmoeller This doesn't seem to be working for me. I have eslint 8.33.0 installed in a project. When I try to run .yarn/sdks/eslint/bin/eslint.js directly, I get this message:

Error: Missing "./bin/eslint.js" export in "eslint" package

I assume this isn't an issue with your code, but with some change in eslint. Any idea what might fix this? Thanks!

As a workaround I've added this to my vimrc:

if !empty(finddir('.yarn/sdks', ';'))
	let g:ale_javascript_eslint_use_global = 1
	let g:ale_javascript_eslint_executable = 'yarn'
	let g:ale_javascript_eslint_options = 'run eslint'
endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants