fix(linter): make more resilient against some edge case behavior

This commit is contained in:
2026-02-28 09:52:49 +01:00
parent c01c4a5622
commit feee9b1f10
+25 -13
View File
@@ -349,20 +349,33 @@ function Linter:run()
log.error(out.stderr) log.error(out.stderr)
end end
if not output or output == "" then
return
end
local lines = vim.split(output, "\n", { trimempty = true })
if self.config.json then if self.config.json then
local ok, json = pcall( local diagnostics = {}
vim.json.decode, for _, line in ipairs(lines) do
output, local ok, json = pcall(
{ luanil = { object = true, array = true } } vim.json.decode,
) line,
if not ok then { luanil = { object = true, array = true } }
log.error("Failed to parse JSON: " .. json) )
success = false if not ok then
return log.error("Failed to parse JSON: " .. json)
success = false
return
end
local diags = self:process_json_output(json)
if diags then
vim.list_extend(diagnostics, diags)
end
end end
local diagnostics = self:process_json_output(json) if #diagnostics > 0 then
if diagnostics then
if self.config.hook then if self.config.hook then
self.config.hook(self, diagnostics) self.config.hook(self, diagnostics)
end end
@@ -372,9 +385,8 @@ function Linter:run()
return return
end end
local output_lines = vim.fn.split(output, "\n", false)
local diagnostics = {} local diagnostics = {}
for _, line in ipairs(output_lines) do for _, line in ipairs(lines) do
local ok, resp = pcall( local ok, resp = pcall(
vim.diagnostic.match, vim.diagnostic.match,
line, line,