fix(linter): make more resilient against some edge case behavior
This commit is contained in:
+25
-13
@@ -349,20 +349,33 @@ function Linter:run()
|
||||
log.error(out.stderr)
|
||||
end
|
||||
|
||||
if not output or output == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local lines = vim.split(output, "\n", { trimempty = true })
|
||||
|
||||
if self.config.json then
|
||||
local ok, json = pcall(
|
||||
vim.json.decode,
|
||||
output,
|
||||
{ luanil = { object = true, array = true } }
|
||||
)
|
||||
if not ok then
|
||||
log.error("Failed to parse JSON: " .. json)
|
||||
success = false
|
||||
return
|
||||
local diagnostics = {}
|
||||
for _, line in ipairs(lines) do
|
||||
local ok, json = pcall(
|
||||
vim.json.decode,
|
||||
line,
|
||||
{ luanil = { object = true, array = true } }
|
||||
)
|
||||
if not ok then
|
||||
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
|
||||
|
||||
local diagnostics = self:process_json_output(json)
|
||||
if diagnostics then
|
||||
if #diagnostics > 0 then
|
||||
if self.config.hook then
|
||||
self.config.hook(self, diagnostics)
|
||||
end
|
||||
@@ -372,9 +385,8 @@ function Linter:run()
|
||||
return
|
||||
end
|
||||
|
||||
local output_lines = vim.fn.split(output, "\n", false)
|
||||
local diagnostics = {}
|
||||
for _, line in ipairs(output_lines) do
|
||||
for _, line in ipairs(lines) do
|
||||
local ok, resp = pcall(
|
||||
vim.diagnostic.match,
|
||||
line,
|
||||
|
||||
Reference in New Issue
Block a user