fix wordpress linter/formatter mismatch
This commit is contained in:
parent
6db3669bdb
commit
a0926e273e
|
|
@ -59,15 +59,20 @@ return {
|
|||
command = find_executable({ "phpcbf" }),
|
||||
prefer_local = "vendor/bin",
|
||||
-- Respects phpcs.xml in project root or uses WordPress standard
|
||||
extra_args = function()
|
||||
local phpcs_xml = vim.fn.findfile("phpcs.xml", ".;")
|
||||
if phpcs_xml == "" then
|
||||
phpcs_xml = vim.fn.findfile("phpcs.xml.dist", ".;")
|
||||
extra_args = function(params)
|
||||
local root = params.root or vim.fn.getcwd()
|
||||
|
||||
-- Check for project ruleset
|
||||
local has_project_ruleset =
|
||||
vim.loop.fs_stat(root .. "/phpcs.xml")
|
||||
or vim.loop.fs_stat(root .. "/phpcs.xml.dist")
|
||||
|
||||
if has_project_ruleset then
|
||||
return {} -- Let project ruleset control standard
|
||||
end
|
||||
if phpcs_xml == "" then
|
||||
return { "--standard=WordPress" }
|
||||
end
|
||||
return {}
|
||||
|
||||
-- No project ruleset: use WordPress to match nvim-lint
|
||||
return { "--standard=WordPress" }
|
||||
end,
|
||||
}),
|
||||
|
||||
|
|
|
|||
|
|
@ -47,21 +47,21 @@ return {
|
|||
|
||||
-- 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
|
||||
}
|
||||
|
||||
-- Build args dynamically based on project ruleset presence
|
||||
-- Note: This runs once at config load, checks cwd for phpcs.xml
|
||||
local cwd = vim.fn.getcwd()
|
||||
local has_project_ruleset =
|
||||
vim.loop.fs_stat(cwd .. "/phpcs.xml")
|
||||
or vim.loop.fs_stat(cwd .. "/phpcs.xml.dist")
|
||||
|
||||
local phpcs_args = { "-q", "--report=json" }
|
||||
if not has_project_ruleset then
|
||||
table.insert(phpcs_args, "--standard=WordPress")
|
||||
end
|
||||
table.insert(phpcs_args, "-") -- stdin
|
||||
|
||||
lint.linters.phpcs.args = phpcs_args
|
||||
|
||||
-- Configure eslint_d to use project-local first
|
||||
lint.linters.eslint_d.cmd = find_executable({ "eslint_d", "eslint" }) or "eslint_d"
|
||||
|
|
|
|||
Loading…
Reference in New Issue