Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lua/guard/lint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ end
---@param message string?
---@param severity number?
---@param source string?
function M.diag_fmt(buf, lnum_start, col_start, message, severity, source, lnum_end, col_end)
---@param code string?
function M.diag_fmt(buf, lnum_start, col_start, message, severity, source, lnum_end, col_end, code)
return {
bufnr = buf,
col = col_start,
Expand All @@ -152,6 +153,7 @@ function M.diag_fmt(buf, lnum_start, col_start, message, severity, source, lnum_
namespace = ns,
severity = severity or vim.diagnostic.severity.HINT,
source = source or 'Guard',
code = code,
}
end

Expand Down Expand Up @@ -188,10 +190,6 @@ local json_opts = {
lines = nil,
}

local function formulate_msg(msg, code)
return (msg or '') .. (code and ('[%s]'):format(code) or '')
end

local function attr_value(mes, attribute)
return type(attribute) == 'function' and attribute(mes) or mes[attribute]
end
Expand Down Expand Up @@ -239,11 +237,12 @@ function M.from_json(opts)
buf,
json_get_offset(mes, attr.lnum, off),
json_get_offset(mes, attr.col, off),
formulate_msg(message, code),
message,
opts.severities[attr_value(mes, attr.severity)],
opts.source,
json_get_offset(mes, attr.lnum_end or attr.lnum, off),
json_get_offset(mes, attr.col_end or attr.col, off)
json_get_offset(mes, attr.col_end or attr.col, off),
code
)
)
end, offences or {})
Expand Down Expand Up @@ -282,11 +281,12 @@ function M.from_regex(opts)
buf,
normalize(mes.lnum, off),
normalize(mes.col, off),
formulate_msg(mes.message, mes.code),
mes.message,
opts.severities[mes.severity],
opts.source,
normalize(mes.lnum_end or mes.lnum, off),
normalize(mes.col_end or mes.lnum, off)
normalize(mes.col_end or mes.lnum, off),
mes.code
)
)
end, offences)
Expand Down
9 changes: 6 additions & 3 deletions spec/lint_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ describe('lint module', function()
end_col = 1,
lnum = 1,
end_lnum = 1,
message = 'Very important error message[error code 114514]',
message = 'Very important error message',
code = 'error code 114514',
namespace = ns,
severity = 2,
},
Expand All @@ -136,7 +137,8 @@ describe('lint module', function()
end_col = 1,
lnum = 1,
end_lnum = 1,
message = 'Very important error message[error code 114514]',
message = 'Very important error message',
code = 'error code 114514',
namespace = ns,
severity = 2,
},
Expand All @@ -146,7 +148,8 @@ describe('lint module', function()
end_col = 0,
end_lnum = 0,
lnum = 0,
message = 'Very important error message[warning]',
message = 'Very important error message',
code = 'warning',
namespace = ns,
severity = 2,
source = 'mock_linter_json',
Expand Down
2 changes: 1 addition & 1 deletion spec/settings_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('settings', function()
same(true, util.getopt('auto_lint'))
vim.cmd('silent! write!')
vim.wait(500)
same('Very important error message[error code 114514]', vd.get()[1].message)
same('Very important error message', vd.get()[1].message)

vim.g.guard_config = { auto_lint = false }
same(false, util.getopt('auto_lint'))
Expand Down
Loading