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

ESLint: Possible issue with root directory when working with different ESLint versions #3685

Closed
estacioneto opened this issue Apr 3, 2025 · 3 comments · Fixed by #3686
Closed
Labels
bug Something isn't working

Comments

@estacioneto
Copy link
Contributor

estacioneto commented Apr 3, 2025

Description

Hi there!

First off, thanks for the awesome project—it makes configuring LSPs in Neovim so much easier!

Context

I ran into an issue where VSCode correctly picked up the closest ESLint version in my project, but Neovim’s ESLint LSP always used the root directory’s version instead.

After troubleshooting, I found that my inner directory had ESLint ^9.20.1, while the project root had 7.32.0. Neovim defaulted to the root’s version instead of the closest one. I resolved this by tweaking my config:

local function get_eslint_closest_dir()
  local cwd = vim.fn.getcwd()
  local eslint_node_modules = vim.fn.finddir('node_modules/eslint', cwd .. ';')

  if eslint_node_modules == '' then
    return nil
  end

  return eslint_node_modules == 'node_modules/eslint' and cwd
    or eslint_node_modules:match '(.*)/node_modules/eslint'
end

return {
  single_file_support = true,
  on_new_config = function(config, new_root_dir)
    new_root_dir = get_eslint_closest_dir() or new_root_dir
    -- (continuing from on_new_config in nvim-lspconfig)
}

It seems like new_root_dir is always set to the project’s root when opening a file.

So I was wondering—does this behavior come from the on_new_config callback, the ESLint LSP itself, or is it something nvim-lspconfig should handle?

Thanks in advance! 😊

@estacioneto estacioneto added the bug Something isn't working label Apr 3, 2025
@justinmk
Copy link
Member

justinmk commented Apr 3, 2025

Presumably you mean this config:
https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/configs/eslint.lua

PR welcome.

@estacioneto
Copy link
Contributor Author

@justinmk thanks for the response. Just created the PR for it :)

@estacioneto
Copy link
Contributor Author

@justinmk should we reopen this since it was reverted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants