nvim-lint
nvim-lint copied to clipboard
Eslint_d error when .eslint.json doesn't exist.
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.
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,
},
},
},
},
}
Did eslint_d lint in project with eslint config for you? --no-warn-ignored broke that for me.
Did eslint_d lint in project with eslint config for you?
--no-warn-ignoredbroke that for me.
Yes:
- in my project,
eslintis installed as a dev dependency - I can lint from the terminal:
npm run eslint . - from Neovim, the files are linted with
nvim-lintusing theeslint_dlinter (configured as above), which in fact use theeslintbin 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 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.
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.
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.
Did anyone find a permanent solution?
I learned to live with it.
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, }) `
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.
A fix would be greatly appreciated!
Using @KurobaneShin's config but removing --no-warn-ignored fixed it for me. Dunno what changed but it used to work having it included.
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
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.
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
Resolved by uninstalling the Mason install eslint_d and use global install version via npm install -g eslint@8
Thanks, @pwang2, I've installed
MasonInstall [email protected]
And it fixed an error with config (because eslint 8 )
@nesterone , yeah! that also works.