-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enabling caching using a ruleset produces invalid cache files when using --sniffs and --exclude CLI args #2992
Comments
Solution 3 is actually what PHPCS is actually trying to do, but I think the issue is the order of commands in this case. When caching, PHPCS intentionally doesn't filter out any errors based on filtering rules: PHP_CodeSniffer/src/Files/File.php Lines 894 to 910 in a957a73
When doing a normal run with a cache file, all errors are replayed to apply the filtering rules correctly: PHP_CodeSniffer/src/Files/LocalFile.php Lines 102 to 112 in a957a73
I need to look into still, but I suspect what is happening is that the |
I've looked into this a bit more and it looks like the problem is with ruleset parsing. Before the sample ruleset is parsed, PHPCS thinks that caching is disabled. Once the ruleset is parsed, it now knows that caching is enabled, but it's already set the sniffs restrictions. The fix I'm currently testing is to blank out the sniff restrictions after the ruleset has been parsed, as we then know if caching is enabled or not. |
…ache files when using --sniffs and --exclude CLI args
…ache files when using --sniffs and --exclude CLI args
That fix looks to have worked, so I've committed that change. Thanks for reporting this. |
@gsherwood Thanks a lot! I'll test it along the way. |
While researching how the result caching was implemented and playing around with it, I noticed that the
--sniffs
and--exclude
arguments are not taken into account properly, leading to misleading results being cached and displayed for runs.Steps to reproduce the issue when using the
--sniffs
CLI argumentGiven the following file:
With this ruleset saved as
phpcs.xml.dist
:phpcs.cache
file in the test directory.phpcs --report=source
The output will be:
phpcs --report=source --sniffs=Generic.WhiteSpace.DisallowTabIndent,Squiz.Classes.ValidClassName
The output will be:
phpcs --report=source --sniffs=Generic.WhiteSpace.DisallowTabIndent,Squiz.Classes.ValidClassName
again and get a clean bill of health.phpcs --report=source --sniffs=Squiz.Scope.MethodScope,PSR2.Classes.ClassDeclaration
and see no issues being reported.phpcs --report=source --sniffs=Squiz.Scope.MethodScope,PSR2.Classes.ClassDeclaration --no-cache
The result will be as below. Take note of the discrepancy between the output in step 5 and step 6:
Steps to reproduce the issue when using the
--exclude
CLI argumentGiven the following file:
With this ruleset saved as
phpcs.xml.dist
:phpcs.cache
file in the test directory.phpcs --report=source
The output will be:
phpcs --report=source --exclude=Generic.WhiteSpace.DisallowTabIndent,Squiz.Classes.ValidClassName,PSR2.Methods.FunctionCallSignature
The output will be:
PSR2.Classes.ClassDeclaration.OpenBraceNewLine
and theSquiz.Scope.MethodScope.Missing
issues.phpcs --report=source --exclude=Generic.WhiteSpace.DisallowTabIndent,Squiz.Classes.ValidClassName,PSR2.Methods.FunctionCallSignature
again.The output will be:
phpcs --report=source
The output will be:
phpcs --report=source --no-cache
The result will be as below. Take note of the discrepancy between the output in step 5 and step 6:
Now, there are multiple possible solutions for this:
--sniffs
or--exclude
is being used.This will be detrimental for people who don't use a custom ruleset and have these arguments set up to be used by default in, for instance, a Composer script.
--sniffs
or--exclude
is not the same as for the cached run.This will mean that the cache will be invalidated and recreated from scratch a lot more often for people often using these arguments, but the results will be accurate.
This would mean refactoring of parts of PHPCS, so if desired, should probably be left for PHPCS 4.x.
So, for now, I'm proposing to implement solution 2.
The text was updated successfully, but these errors were encountered: