diff --git a/lua/linter.lua b/lua/linter.lua index 78f2d36..5dc3e89 100644 --- a/lua/linter.lua +++ b/lua/linter.lua @@ -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,