Linter command `cmd.exe` exited with code: 1
Description
This error occurs whenever I load a c or c++ file that calls cppcheck on windows:
Does anyone have an idea as to what is causing this? The linter saying its name is cmd.exe is a bit strange, but I guess it's probably some windows compatibility thing.
Configuration
My config for lint (loaded with lazy.nvim) is as follows:
return {
'mfussenegger/nvim-lint',
event = { 'BufReadPre', 'BufNewFile' },
config = function()
local lint = require 'lint'
lint.linters_by_ft = {
c = {
'cppcheck',
},
cpp = {
'cppcheck',
},
}
-- Create autocommand which carries out the actual linting
-- on the specified events.
local lint_augroup = vim.api.nvim_create_augroup('lint', { clear = true })
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, {
group = lint_augroup,
callback = function()
if vim.opt_local.modifiable:get() then
lint.try_lint()
end
end,
})
end,
}
This is the stock configuration that comes with kickstart.nvim with cppcheck enabled for c and c++.
Other info
I normally use git bash as my shell on windows, but I tested with cmd as my shell and it hits the same error. Also, I have cppcheck in my PATH, so that shouldn't be the problem.
It's also worth noting that this configuration works fine on Linux.
Probably related to https://github.com/mfussenegger/nvim-lint/pull/476 / https://github.com/mfussenegger/nvim-lint/pull/471#issuecomment-1824754487
If wrapping linters' in cmd.exe on windows isn't always safe it probably needs a new option to prevent that.
Do we know what wrapping in cmd.exe does? If bash on windows works as a wrapper too, it might be better to instead wrap all commands (regardless of OS) in vim's shell-related options (shell, shellcmdflag, shellquote, shellslash, etc.), or run commands in a way such that they get used by default.
On windows systems, these options default to produce cmd.exe /S /C as the command runner, which is similar (but not the same) as what lint.lua currently does:
https://github.com/mfussenegger/nvim-lint/blob/936197073214c26a347fb933c9459c8766376b23/lua/lint.lua#L355-L356
See also: cmd.exe argument reference
On unix systems and the like, it defaults to similarly sensible options.