nvim-lint
nvim-lint copied to clipboard
phpcs doesn't seem to follow rulesets with exclude-pattern
I'm new to nvim-lint and php is not my primary language, but I noticed an inconsistency between running phpcs locally versus inside neovim.
.phpcs.xml
<?xml version="1.0"?>
<ruleset name="MyApp">
<file>blog/wp-content/themes/mytheme-child/</file>
<file>app/</file>
<rule ref="WordPress">
<exclude-pattern>app/</exclude-pattern>
</rule>
<rule ref="PSR12">
<exclude-pattern>blog/</exclude-pattern>
</rule>
<arg name="colors"/>
<arg value="sp"/>
<arg name="parallel" value="8"/>
<arg name="report" value="full"/>
<ini name="memory_limit" value="128M"/>
</ruleset>
plugins.lua
{
'mfussenegger/nvim-lint',
config = function()
require('plugin.linter')
end
},
plugins/linter.lua
local lint = require("lint")
-- PHP
local phpcs = lint.linters.phpcs
phpcs.cmd = "vendor/bin/phpcs"
-- Setup Linters
lint.linters_by_ft = {
php = { "phpcs" },
}
Scenario 1: Inside neovim
- When running
:lua require('lint').try_lint()
onapp/test.php
, I see WordPress related errors. - When running
:lua require('lint').try_lint()
onblog/wp-config.php
, I see PSR12 related errors.
Scenario 2: Running phpcs
- When running
vendor/bin/phpcs app/test.php
, I see only PSR12 related errors. - When running
vendor/bin/phpcs blog/wp-config.php
, I only see WordPress related errors.
I believe the issue is with stdin and lua/lint/linters/phpcs.lua. I can create a PR, but not sure if I'm heading down the right path.
I was able to match the functionality between running phpcs locally and using the linter in nvim.
I made the following changes to phpcs.lua
.
parser = function(output, bufnr)
-- other unmodified code
local filename = vim.fn.fnamemodify(vim.fn.bufname(bufnr), ":p")
local files = decoded["files"]
local messages = {}
if files["STDIN"] == nil then
if files[filename] == nil then
return {}
end
messages = files[filename]["messages"]
else
messages = files["STDIN"]["messages"]
end
-- other unmodified code
end,
And customized the linter in my config to be:
local lint = require("lint")
-- PHP
local phpcs = lint.linters.phpcs
phpcs.cmd = "vendor/bin/phpcs"
phpcs.stdin = false
phpcs.args = {
"--report=json",
"-q",
}
This does work, but is this something worth submitting?