refactor: address emmylua diagnostics

This commit is contained in:
2026-04-20 22:11:18 +02:00
parent 516b9ea749
commit c7dd083083
29 changed files with 542 additions and 532 deletions
+22 -17
View File
@@ -46,7 +46,7 @@ local util = require("util")
---@field pattern? string
--- Named capture groups for pattern matching (required if not using json)
---@field groups? ow.lsp.linter.Group[]
--- Map severity strings to vim diagnostic levels
--- Map severity strings to vim diagnostic levels (required if not using json)
---@field severity_map? table<string, vim.diagnostic.Severity>
--- Source name for diagnostics (default: command name)
---@field source? string
@@ -131,17 +131,13 @@ function Linter:add_tags(diag)
return
end
local have_unnecessary = vim.islist(self.config.tags.unnecessary)
local have_deprecated = vim.islist(self.config.tags.deprecated)
if not have_unnecessary and not have_deprecated then
return
end
diag._tags = {}
diag._tags = {
unnecessary = false,
deprecated = false,
}
if
have_unnecessary
self.config.tags.unnecessary
and vim.list_contains(self.config.tags.unnecessary, diag.code)
then
diag._tags.unnecessary = true
@@ -149,7 +145,7 @@ function Linter:add_tags(diag)
end
if
have_deprecated
self.config.tags.deprecated
and vim.list_contains(self.config.tags.deprecated, diag.code)
then
diag._tags.deprecated = true
@@ -181,13 +177,15 @@ function Linter:fix_indexing(diag)
end
end
---@param json any
function Linter:process_json_output(json)
---@type vim.Diagnostic[]
local diagnostics = {}
local cfg = assert(self.config.json)
local items = json
if self.config.json.diagnostics_root then
items = Linter.get_json_value(json, self.config.json.diagnostics_root)
if cfg.diagnostics_root then
items = Linter.get_json_value(json, cfg.diagnostics_root)
end
if type(items) ~= "table" then
@@ -202,8 +200,9 @@ function Linter:process_json_output(json)
for _, item in ipairs(items) do
local diag = {}
for field, path in pairs(self.config.json) do
for field, path in pairs(cfg) do
if field ~= "diagnostics_root" and field ~= "callback" then
---@cast path string
diag[field] = Linter.get_json_value(item, path)
end
end
@@ -218,12 +217,14 @@ function Linter:process_json_output(json)
diag.severity = self.config.severity_map[diag.severity]
end
---@cast diag vim.Diagnostic
self:fix_indexing(diag)
self:clamp_col(diag)
self:add_tags(diag)
if type(self.config.json.callback) == "function" then
self.config.json.callback(diag)
if type(cfg.callback) == "function" then
cfg.callback(diag)
end
table.insert(diagnostics, diag)
@@ -371,6 +372,9 @@ function Linter:run()
return
end
---@cast self.config.pattern -nil
---@cast self.config.groups -nil
---@cast self.config.severity_map -nil
local diagnostics = {}
for _, line in ipairs(lines) do
@@ -387,6 +391,7 @@ function Linter:run()
success = false
return
elseif resp then
---@cast resp vim.Diagnostic
resp.source = resp.source or self.config.source
self:clamp_col(resp)
self:add_tags(resp)
@@ -439,7 +444,7 @@ function Linter.add(bufnr, config)
buffer = linter.bufnr,
callback = util.debounce(function()
linter:run()
end, config.debounce) --[[@as fun()]],
end, config.debounce),
group = linter.augroup,
})