diff --git a/.config/nvim/lua/tovi/plugins/formatting.lua b/.config/nvim/lua/tovi/plugins/formatting.lua index f8a0dec..2f6974e 100644 --- a/.config/nvim/lua/tovi/plugins/formatting.lua +++ b/.config/nvim/lua/tovi/plugins/formatting.lua @@ -39,5 +39,9 @@ return { timeout_ms = 500, }) end) + + conform.formatters.phpcbf = { + prepend_args = { "--standard=~/.config/phpcs.xml" } + } end, } diff --git a/.config/nvim/lua/tovi/plugins/linting.lua b/.config/nvim/lua/tovi/plugins/linting.lua index 1561e6e..2b5e8fc 100644 --- a/.config/nvim/lua/tovi/plugins/linting.lua +++ b/.config/nvim/lua/tovi/plugins/linting.lua @@ -4,10 +4,56 @@ return { 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" }, diff --git a/.config/phpcs.xml b/.config/phpcs.xml new file mode 100644 index 0000000..a2f70e6 --- /dev/null +++ b/.config/phpcs.xml @@ -0,0 +1,33 @@ + + + app + config + public + resources + routes + tests + + */database/* + */cache/* + */*.js + */*.css + */*.xml + */*.blade.php + */autoload.php + */storage/* + */docs/* + */vendor/* + */migrations/* + + + + + + + + + + + + + diff --git a/.zshrc b/.zshrc index 76f50eb..5cda07b 100644 --- a/.zshrc +++ b/.zshrc @@ -224,3 +224,5 @@ export FNM_LOGLEVEL="info" export FNM_NODE_DIST_MIRROR="https://nodejs.org/dist" export FNM_ARCH="x64" rehash + +export PHPCS_STANDARD=~/.config/phpcs.xml