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_d unable to recognize the 9.x version of the configuration file #610

Open
imddc opened this issue Jun 27, 2024 · 8 comments
Open

Comments

@imddc
Copy link

imddc commented Jun 27, 2024

Could not parse linter output due to: Expected value but found invalid token at character 1
output: Error: No ESLint configuration found in /Users/dccd/Desktop/item/front/vauch/src.

it's ok to use .eslintrc.json, but i do not want to use the legacy cofiguration file. 😭

@Mouarius
Copy link

I was having the same issue ! I realised when reading the README of the eslint_d package, that they don't completely support the new config format yet.

Experimental support for eslint flat config is available since v13.1.0 if the ESLINT_USE_FLAT_CONFIG environment variable is defined.

I guess a fix would be to add the option to add this environment variable when running the linter. I'm just arriving here to this repo, I'll try to understand how it works and make a PR if it could help !

@Mouarius
Copy link

Ok some discoveries about the issue and how to solve it !

As described on the repo of eslint_d, the feature for using the new eslint config is experimental, and should be activated by spawning the eslint_d server with the ESLINT_USE_FLAT_CONFIG=true variable. What I understood is that the eslint_d works by having a process (named eslint_d) that orchestrates multiple instances of eslint that are run each time it is being called. But killing and calling back a process for a file (what is done internally by nvim-lint) doesn't kill and restart the parent eslint_d server (that's one of the reasons why it is faster than eslint).

For that you need to run ESLINT_USE_FLAT_CONFIG=true ./path/to/eslint_d restart to restart the server with the flag on. (if you use Mason to manage your packages, you could find the eslint_d binary in ~/.local/share/nvim/mason/bin/eslint_d )

Note : I've tried to add this environment variable to the env property of the nvim-lint linter config, but for some reason, when I try to add it there, everything stops working... I couldn't find why.

Then after restarting Neovim, you should probably run into some errors about not finding the config file for your project. You can solve it by configuring the --config flag to your linter configuration.

Here is my configuration that works :

return {
  'mfussenegger/nvim-lint',
  event = { 'BufReadPre', 'BufNewFile' },
  config = function()
    local lint = require 'lint'
    lint.linters_by_ft = {
      javascript = { 'eslint_d' },
      javascriptreact = { 'eslint_d' },
      typescript = { 'eslint_d' },
      typescriptreact = { 'eslint_d' },
    }

    local eslint_d = require 'lint.linters.eslint_d'
    eslint_d.args = vim.tbl_extend('force', {
      '--config',
      function()
        return vim.fn.getcwd() .. '/eslint.config.js'
      end,
    }, eslint_d.args)

    local lint_augroup = vim.api.nvim_create_augroup('lint', { clear = true })

    vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, {
      group = lint_augroup,
      callback = function()
        lint.try_lint()
      end,
    })
  end,
}

Let me know if it works for you, and if it doesn't I'll be happy to help !

If someone reads this and has a solution to avoid restarting the process by hand I would really like to hear about it !

@imddc
Copy link
Author

imddc commented Jul 1, 2024

Thank you for your contribution, but it doesn't seem to work for my project. The error message still exists.

@Mouarius
Copy link

Mouarius commented Jul 1, 2024

Thank you for your contribution, but it doesn't seem to work for my project. The error message still exists.

When you work on your project, do you open neovim in the directory that is the root of your project, and that contains your eslint.config.js file ?

@boydkelly
Copy link

worked for me! But of course if you are switching projects then it wont work for < 9. Thanks!!!

@zayihu
Copy link

zayihu commented Aug 3, 2024

Hello! Well I have same problem, and I have project mono repo type, so my eslint.config.js is in vim.fn.getcwd() .. '/app-frontend/eslint.config.js'

@mgramigna
Copy link

For anyone still fighting with this issue, it may not be an nvim-lint problem. I just contributed mantoni/eslint_d.js#331 to the eslint_d repo which allows you to specify the root directory to look for the eslint node module when running eslint_d. This was released in [email protected]

This is useful in monorepos where the file structure of node_modules might be atypical. Here's a snippet of config that works for me with this change:

vim.env.ESLINT_D_PPID = vim.fn.getpid()
vim.env.ESLINT_D_ROOT = "/path/to/my/monorepo/root"

require("lint").linters_by_ft = {
	typescript = { "eslint_d" },
	javascript = { "eslint_d" },
	typescriptreact = { "eslint_d" },
	javascriptreact = { "eslint_d" },
}

vim.api.nvim_create_autocmd({ "BufWritePost" }, {
	callback = function()
		require("lint").try_lint()
	end,
})

@mantoni
Copy link

mantoni commented Dec 20, 2024

Uh, somebody could've @-mentioned me here 😉. With the rewrite of eslint_d in v14 the architecture changed completely and using old and new configs in different projects is no longer an issue.

There is also a new --debug flag to see what's going on behind the scenes. Hope this helps with debugging.

Please upgrade and let me know if this is still an issue. 🙏

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

No branches or pull requests

6 participants