Refresh generated neovim config
This commit is contained in:
@ -1,11 +1,15 @@
|
||||
-- stdout output in the form "63: resourcs ==> resources, resource"
|
||||
local pattern = "(%d+): (.*)"
|
||||
local groups = { "lnum", "message" }
|
||||
local severities = nil -- none provided
|
||||
|
||||
return {
|
||||
cmd = 'codespell',
|
||||
stdin = false,
|
||||
args = { '--stdin-single-line', "-" },
|
||||
stdin = true,
|
||||
ignore_exitcode = true,
|
||||
parser = require('lint.parser').from_errorformat(
|
||||
'%f:%l:%m',
|
||||
{ severity = vim.diagnostic.severity.INFO,
|
||||
source = 'codespell'}
|
||||
)
|
||||
parser = require('lint.parser').from_pattern(pattern, groups, severities, {
|
||||
source = 'codespell',
|
||||
severity = vim.diagnostic.severity.INFO,
|
||||
}),
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ return {
|
||||
return vim.fn.expand("%:p")
|
||||
end,
|
||||
},
|
||||
stream = "stdout",
|
||||
stream = "both",
|
||||
ignore_exitcode = true,
|
||||
parser = function (output)
|
||||
local status, decoded = pcall(vim.json.decode, output)
|
||||
|
||||
@ -4,34 +4,59 @@ local severity_map = {
|
||||
["HIGH"] = vim.diagnostic.severity.ERROR,
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
cmd = "trivy",
|
||||
stdin = false,
|
||||
append_fname = true,
|
||||
args = { "--scanners", "config", "--format", "json", "fs" },
|
||||
args = { "--scanners", "misconfig", "--format", "json", "fs" },
|
||||
stream = "stdout",
|
||||
ignore_exitcode = false,
|
||||
parser = function(output, bufnr)
|
||||
local diagnostics = {}
|
||||
local ok, decoded = pcall(vim.json.decode, output)
|
||||
if not ok then
|
||||
return diagnostics
|
||||
end
|
||||
|
||||
-- example output:
|
||||
-- {
|
||||
-- "Results": [
|
||||
-- "Target": "<file path>",
|
||||
-- "Misconfigurations": [
|
||||
-- {
|
||||
-- "ID": "<nvim-lint code>",
|
||||
-- "Title": "<title>",
|
||||
-- "Description": "<description>",
|
||||
-- "Severity": "<LOW|MEDIUM|HIGH>",
|
||||
-- "CauseMetadata": {
|
||||
-- "StartLine": <line number>,
|
||||
-- "EndLine": <line number>,
|
||||
-- }
|
||||
-- }
|
||||
-- ]
|
||||
-- ]
|
||||
-- }
|
||||
local decoded = vim.json.decode(output)
|
||||
local fpath = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":t")
|
||||
|
||||
for _, result in ipairs(decoded and decoded.Results or {}) do
|
||||
-- trivy can return Results for other files; only report for current buffer
|
||||
--
|
||||
if result.Target == fpath then
|
||||
for _, misconfig in ipairs(result.Misconfigurations or {}) do
|
||||
local err = {
|
||||
local title = misconfig.Title or "<No Title>"
|
||||
local description = misconfig.Description or "<No Description>"
|
||||
local id = misconfig.ID or "<No ID>"
|
||||
local md = misconfig.CauseMetadata or {}
|
||||
local lnum = md.StartLine and md.StartLine - 1 or 0
|
||||
local end_lnum = md.EndLine and md.EndLine - 1 or 0
|
||||
table.insert(diagnostics, {
|
||||
source = "trivy",
|
||||
message = string.format("%s %s", misconfig.Title, misconfig.Description),
|
||||
col = misconfig.CauseMetadata.StartLine,
|
||||
end_col = misconfig.CauseMetadata.EndLine,
|
||||
lnum = misconfig.CauseMetadata.StartLine - 1,
|
||||
end_lnum = misconfig.CauseMetadata.EndLine - 1,
|
||||
code = misconfig.ID,
|
||||
severity = severity_map[misconfig.Severity],
|
||||
}
|
||||
table.insert(diagnostics, err)
|
||||
message = string.format("%s: %s", title, description),
|
||||
col = 0,
|
||||
end_col = 0,
|
||||
lnum = lnum,
|
||||
end_lnum = end_lnum,
|
||||
code = id,
|
||||
severity = severity_map[misconfig.Severity] or vim.diagnostic.severity.WARN,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user