configure formatters and linters
This commit is contained in:
parent
c47afa2471
commit
b045d7c627
5 changed files with 269 additions and 7 deletions
80
lua/plugins/nvim-lint.lua
Normal file
80
lua/plugins/nvim-lint.lua
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
-- nvim-lint: Linting support (replaces none-ls diagnostics)
|
||||
-- none-ls removed ESLint and many linters, so we use nvim-lint instead
|
||||
|
||||
return {
|
||||
"mfussenegger/nvim-lint",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
config = function()
|
||||
local lint = require("lint")
|
||||
|
||||
-- Configure linters per filetype
|
||||
lint.linters_by_ft = {
|
||||
javascript = { "eslint_d" },
|
||||
javascriptreact = { "eslint_d" },
|
||||
typescript = { "eslint_d" },
|
||||
typescriptreact = { "eslint_d" },
|
||||
markdown = { "markdownlint" },
|
||||
php = { "phpcs" },
|
||||
}
|
||||
|
||||
-- Helper: Find project-local executable, fallback to global
|
||||
local function find_executable(names)
|
||||
local cwd = vim.fn.getcwd()
|
||||
local mason_bin = vim.fn.stdpath("data") .. "/mason/bin/"
|
||||
|
||||
local search_paths = {
|
||||
cwd .. "/node_modules/.bin/",
|
||||
cwd .. "/vendor/bin/",
|
||||
mason_bin,
|
||||
}
|
||||
|
||||
for _, name in ipairs(names) do
|
||||
for _, path in ipairs(search_paths) do
|
||||
local full_path = path .. name
|
||||
if vim.fn.executable(full_path) == 1 then
|
||||
return full_path
|
||||
end
|
||||
end
|
||||
|
||||
if vim.fn.executable(name) == 1 then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Configure phpcs for WordPress standards
|
||||
lint.linters.phpcs.cmd = find_executable({ "phpcs" }) or "phpcs"
|
||||
lint.linters.phpcs.args = {
|
||||
"-q",
|
||||
"--report=json",
|
||||
function()
|
||||
local phpcs_xml = vim.fn.findfile("phpcs.xml", ".;")
|
||||
if phpcs_xml == "" then
|
||||
phpcs_xml = vim.fn.findfile("phpcs.xml.dist", ".;")
|
||||
end
|
||||
if phpcs_xml == "" then
|
||||
return "--standard=WordPress"
|
||||
end
|
||||
return nil
|
||||
end,
|
||||
"-", -- stdin
|
||||
}
|
||||
|
||||
-- Configure eslint_d to use project-local first
|
||||
lint.linters.eslint_d.cmd = find_executable({ "eslint_d", "eslint" }) or "eslint_d"
|
||||
|
||||
-- Configure markdownlint
|
||||
lint.linters.markdownlint.cmd = find_executable({ "markdownlint" }) or "markdownlint"
|
||||
|
||||
-- Auto-lint on these events
|
||||
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,
|
||||
})
|
||||
end,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue