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.

86 lines
2.6 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. return {
  2. "mfussenegger/nvim-lint",
  3. event = { "BufReadPre", "BufNewFile" },
  4. config = function()
  5. local lint = require("lint")
  6. local severities = {
  7. ERROR = vim.diagnostic.severity.ERROR,
  8. WARNING = vim.diagnostic.severity.WARN,
  9. }
  10. lint.linters.phpcs = {
  11. name = 'phpcs',
  12. cmd = 'phpcs',
  13. stdin = true,
  14. args = {
  15. '-q',
  16. '--report=json',
  17. '--standard=~/.config/phpcs.xml',
  18. '-', -- need `-` at the end for stdin support
  19. },
  20. ignore_exitcode = true,
  21. parser = function(output, _)
  22. if vim.trim(output) == '' or output == nil then
  23. return {}
  24. end
  25. if not vim.startswith(output, '{') then
  26. vim.notify(output)
  27. return {}
  28. end
  29. local decoded = vim.json.decode(output)
  30. local diagnostics = {}
  31. local messages = decoded['files']['STDIN']['messages']
  32. for _, msg in ipairs(messages or {}) do
  33. table.insert(diagnostics, {
  34. lnum = msg.line - 1,
  35. end_lnum = msg.line - 1,
  36. col = msg.column - 1,
  37. end_col = msg.column - 1,
  38. message = msg.message,
  39. code = msg.source,
  40. source = 'phpcs',
  41. severity = assert(severities[msg.type], 'missing mapping for severity ' .. msg.type),
  42. })
  43. end
  44. return diagnostics
  45. end
  46. }
  47. lint.linters_by_ft = {
  48. javascript = { "eslint" },
  49. typescript = { "eslint" },
  50. vue = { "eslint" },
  51. json = { "jsonlint" },
  52. markdown = { "markdownlint" },
  53. php = { "phpcs" },
  54. golang = { "gospell", "golangci-lint" },
  55. python = { "pylint" },
  56. dockerfile = { "hadolint" },
  57. blade = { "phpcs" },
  58. }
  59. local lint_augroup = vim.api.nvim_create_augroup("lint", {
  60. clear = true,
  61. })
  62. vim.api.nvim_create_autocmd({
  63. "BufEnter",
  64. "BufWritePost",
  65. "InsertLeave",
  66. }, {
  67. group = lint_augroup,
  68. callback = function()
  69. lint.try_lint()
  70. end,
  71. })
  72. vim.keymap.set("n", "<leader>ll", function()
  73. lint.try_lint()
  74. end)
  75. end,
  76. }