nvim-lint icon indicating copy to clipboard operation
nvim-lint copied to clipboard

Eslint_d error when .eslint.json doesn't exist.

Open Kazimazi opened this issue 2 years ago • 9 comments

I have the the same issue as mentioned in https://github.com/mfussenegger/nvim-lint/issues/454#issue-1986742975 except for with eslint_d and solution mentioned there wouldn't work, so setting ignore_errors = true option for try_lint wouldn't work. https://github.com/mfussenegger/nvim-lint/blob/9e096df0858a1834ec2a60abe6cceb4d84dbd34c/lua/lint.lua#L208 seems to return as successful, but in the buffer I see the error:

Could not parse linter output due to: Expected value but found invalid token at character 1
output: Error: No Eslint configuration found in <path-to-project-root>.

I'm not sure how to go on debugging this issue.

It works as expected with eslint.

Kazimazi avatar Nov 16 '23 23:11 Kazimazi

I've managed to make it work by overriding the config for that linter and adding the --no-warn-ignored CLI argument. Here is an excerpt of my config with lazy.nvim:

{
  'mfussenegger/nvim-lint',
  opts = {
    -- other config
    linters = {
      eslint_d = {
        args = {
          '--no-warn-ignored', -- <-- this is the key argument
          '--format',
          'json',
          '--stdin',
          '--stdin-filename',
          function()
            return vim.api.nvim_buf_get_name(0)
          end,
        },
      },
    },
  },
}


tizot avatar Nov 21 '23 11:11 tizot

Did eslint_d lint in project with eslint config for you? --no-warn-ignored broke that for me.

Kazimazi avatar Nov 25 '23 10:11 Kazimazi

Did eslint_d lint in project with eslint config for you? --no-warn-ignored broke that for me.

Yes:

  • in my project, eslint is installed as a dev dependency
  • I can lint from the terminal: npm run eslint .
  • from Neovim, the files are linted with nvim-lint using the eslint_d linter (configured as above), which in fact use the eslint bin installed in the repo (see https://github.com/fsouza/prettierd#local-instance)

Note that I don't install eslint_d in the project (I use Mason to manage the binaries for linters/formatters).

Camille-Upway avatar Nov 25 '23 12:11 Camille-Upway

@Camille-Upway I'm not sure how that happens, when I try to lint from cli it would not output any error, but it should: eslint_d --no-warn-ignored --format json --stdin --stdin-filename jira.js < jira.js. Keep in mind, without the --no-warn-ignored flag I get expected output.

Kazimazi avatar Dec 21 '23 15:12 Kazimazi

I checked how this issue is handled in none-ls.nvim and it seems that exit code is checked. My particular error has the output of:

Error: No ESLint configuration found in /home/kazimazi/nixos-config/home/kazimazi/features/desktop/comm
on/wayland-wm/ags/simple-bar

and exit code is 2. Regular eslint rule violations would get exit code of 1 and if no errors then 0.

Kazimazi avatar Dec 21 '23 16:12 Kazimazi

Did anyone find a permanent solution?

For one of my projects I made a eslintrc.json and the error disappeared. However, I did not want to keep doing that so, I opted for using the eslint-lsp with mason and lsp-zero instead.

jozhw avatar Mar 04 '24 14:03 jozhw

Did anyone find a permanent solution?

I learned to live with it.

Kazimazi avatar Mar 04 '24 15:03 Kazimazi

thanks to @tizot i made it

`local lint = require "lint"

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

lint.linters_by_ft = { typescript = { "biomejs", "eslint_d", "eslint" }, javascript = { "biomejs", "eslint_d", "eslint" }, typescriptreact = { "biomejs", "eslint_d", "eslint" }, javascriptreact = { "biomejs", "eslint_d", "eslint" }, }

local eslint = lint.linters.eslint_d

eslint.args = { "--no-warn-ignored", -- <-- this is the key argument "--format", "json", "--stdin", "--stdin-filename", function() return vim.api.nvim_buf_get_name(0) end, }

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

KurobaneShin avatar Mar 09 '24 02:03 KurobaneShin

I also got this error at my work computer and not on my PC with the same config. I did :MasonUninstallAll, reopened neovim and mason reinstalls all stuff within the ensure_installed. After that everything worked fine.

Edit: After not not touching my computer for about 30mins, the error came back even after restarting neovim.

marcus-dc avatar May 16 '24 08:05 marcus-dc

A fix would be greatly appreciated!

DarhkVoyd avatar Jun 16 '24 10:06 DarhkVoyd

Using @KurobaneShin's config but removing --no-warn-ignored fixed it for me. Dunno what changed but it used to work having it included.

ewal avatar Jun 17 '24 18:06 ewal

UPDATE: 20240814

    eslint.args = {
      "--no-warn-ignored", -- <-- this is the key argument
      "--format",
      "json",
      "--stdin",
      "--stdin-filename",
      function()
        return vim.api.nvim_buf_get_name(0)
      end,
    }

above is not working, because the eslint_d's output is changed from 'Error: No ESLint configuration found' to 'Error: Could not find config file', my current temp solution:

    lint.linters.eslint_d = require("lint.util").wrap(lint.linters.eslint_d, function(diagnostic)
      -- try to ignore "No ESLint configuration found" error
      -- if diagnostic.message:find("Error: No ESLint configuration found") then -- old version
      -- update: 20240814, following is working
      if diagnostic.message:find("Error: Could not find config file") then
        return nil
      end
      return diagnostic
    end)

hope to add a fix pr

CrzMarvin avatar Aug 14 '24 07:08 CrzMarvin

My case is a bit different. I have a mono repo. if I open the UI code directory contains .eslintrc.cjs file or use lcd to change to the that directory linter working. If I open from the mono repo root, it will see the error.
image

I think i finally figured out what's going on. Mason installed eslint_d has buddled v9.x of eslint which is looking for .eslint.config.js as configuration which is not there image

Resolved by uninstalling the Mason install eslint_d and use global install version via npm install -g eslint@8

pwang2 avatar Aug 15 '24 17:08 pwang2

Thanks, @pwang2, I've installed

MasonInstall [email protected]

And it fixed an error with config (because eslint 8 )

nesterone avatar Aug 22 '24 07:08 nesterone

@nesterone , yeah! that also works.

pwang2 avatar Aug 22 '24 17:08 pwang2