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.phpcs = { name = '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" }, blade = { "phpcs" }, } 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", "ll", function() lint.try_lint() end) end, }