fix(linter): make more resilient against some edge case behavior
This commit is contained in:
+17
-5
@@ -349,10 +349,18 @@ 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 diagnostics = {}
|
||||||
|
for _, line in ipairs(lines) do
|
||||||
local ok, json = pcall(
|
local ok, json = pcall(
|
||||||
vim.json.decode,
|
vim.json.decode,
|
||||||
output,
|
line,
|
||||||
{ luanil = { object = true, array = true } }
|
{ luanil = { object = true, array = true } }
|
||||||
)
|
)
|
||||||
if not ok then
|
if not ok then
|
||||||
@@ -361,8 +369,13 @@ function Linter:run()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local diagnostics = self:process_json_output(json)
|
local diags = self:process_json_output(json)
|
||||||
if diagnostics then
|
if diags then
|
||||||
|
vim.list_extend(diagnostics, diags)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #diagnostics > 0 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,
|
||||||
|
|||||||
Reference in New Issue
Block a user