-
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
Custom error messages don't have data replaced when cache is enabled #2575
Comments
@ncou I'm not sure I understand the question. This works perfectly well in my experience. Just to be sure I ran some tests and found no problems. This is the code I used for the tests: <?php
/**
* Test
* @return void
*/
function test( $paramA, $paramB ) {
return;
} Initial ruleset: <?xml version="1.0"?>
<ruleset name="Test-2575">
<rule ref="Squiz.Commenting.FunctionComment.MissingParamTag"/>
</ruleset> Result:
Ruleset based on your described issue: <?xml version="1.0"?>
<ruleset name="Test-2575">
<rule ref="Squiz.Commenting.FunctionComment.MissingParamTag">
<message>@param annotation for parameter "%s" missing</message>
</rule>
</ruleset> Result:
|
here is what i get when i run the test in local (using OS Windows 7 64bits). <?xml version="1.0"?>
<ruleset name="Coding-Standard">
<rule ref="Squiz.Commenting.FunctionComment.MissingParamTag">
<message>@param annotation for parameter "%s" missing</message>
</rule>
</ruleset> Class : <?php
class Test
{
/**
* Test
*
* @return void
*/
public function test($paramA, $paramB): void
{
echo 'test';
}
} Result :
|
in my installed.json file it's indicated the php code sniffer version is 3.4.2. |
@ncou How are you running PHPCS ? How is PHPCS installed ? I honestly cannot reproduce your issue, no matter what I try (and I'm on Windows 7 too). |
I can replicate this. It's a problem with caching. When re-adding the messages after loading from cache, the data isn't being replaced. I still need to look into where the problem is coming from. If you use |
Actually, I know exactly what is happening. When errors are replayed after loading from cache, LocalFile::replayErrors() calls File::addMessage() to put the error data back into the file without actually checking it. The addMessage() method looks at the ruleset and finds a custom message format using %s, so it overrides the message with the one from the ruleset. But it doesn't have any data to replace (it is only replaying the errors, not supplying any data) and so the %s goes unreplaced. The solution for this is to allow addMessage to know that error are being replayed and to not go looking for ruleset settings for the message format. |
I've committed a fix for this, which will be in 3.5.0. For now, disabling cache is the only way to work around this. Or remove the custom error message from the ruleset until the fix is released. |
Yes you are right, if i remove the line
|
I really don't know. There is a very big refactoring project going into that release so it wont be out until that is complete.
No, there is no included sniff for this as it isn't part of the PSR1/2/12 standards directly. |
Thank you for your answers. I will disable the cache and wait for the v3.5 :) |
Hi,
The following sniff doesn't seems to work
https://github.com/slevomat/coding-standard/blob/master/build/phpcs-consistence.xml#L202
The %s string is not replaced with the parameter name. If i remove the custom message it works fine. Is it a regression ? or custom message doesn't support args ?
Thanks for your help.
The text was updated successfully, but these errors were encountered: