You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

88 lines
2.4 KiB

return {
"mfussenegger/nvim-lint",
event = { "BufReadPre", "BufNewFile" },
config = function()
local lint = require("lint")
local severities = {
ERROR = vim.diagnostic.severity.ERROR,
WARNING = vim.diagnostic.severity.WARN,
}
lint.linters.ecs = {
cmd = "ecs",
}
lint.linters.phpcs = {
cmd = 'phpcs',
stdin = true,
args = {
'-q',
'--report=json',
'--standard=~/.config/phpcs.xml',
'-', -- need `-` at the end for stdin support
},
ignore_exitcode = true,
parser = function(output, _)
if vim.trim(output) == '' or output == nil then
return {}
end
if not vim.startswith(output,'{') then
vim.notify(output)
return {}
end
local decoded = vim.json.decode(output)
local diagnostics = {}
local messages = decoded['files']['STDIN']['messages']
for _, msg in ipairs(messages or {}) do
table.insert(diagnostics, {
lnum = msg.line - 1,
end_lnum = msg.line - 1,
col = msg.column - 1,
end_col = msg.column - 1,
message = msg.message,
code = msg.source,
source = 'phpcs',
severity = assert(severities[msg.type], 'missing mapping for severity ' .. msg.type),
})
end
return diagnostics
end
}
lint.linters_by_ft = {
javascript = { "eslint" },
typescript = { "eslint" },
vue = { "eslint" },
json = { "jsonlint" },
markdown = { "markdownlint" },
php = { "phpcs" },
golang = { "gospell", "golangci-lint" },
python = { "pylint" },
dockerfile = { "hadolint" },
}
local lint_augroup = vim.api.nvim_create_augroup("lint", {
clear = true,
})
vim.api.nvim_create_autocmd({
"BufEnter",
"BufWritePost",
"InsertLeave",
}, {
group = lint_augroup,
callback = function()
lint.try_lint()
end,
})
vim.keymap.set("n", "<leader>ll", function()
lint.try_lint()
end)
end,
}