mfussenegger / nvim-lint

An asynchronous linter plugin for Neovim complementary to the built-in Language Server Protocol support.
GNU General Public License v3.0
1.76k stars 191 forks source link

eslint_d unable to recognize the 9.x version of the configuration file #610

Open imddc opened 6 days ago

imddc commented 6 days ago

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 commented 5 days ago

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 commented 4 days ago

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-lintlinter 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 commented 3 days ago

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

Mouarius commented 2 days ago

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 commented 2 days ago

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