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 · 6 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'

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

4 participants