phpcs -s --standard=Drupal ./core/lib/Drupal/Clate/TwigTransTokenParser.php
Will trigger the following error on latest 8.2.x branch
FILE: .../drupal-8/core/lib/Drupal/Core/Template/TwigTransTokenParser.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
84 | ERROR | @throws comment must be on the next line
| | (Drupal.Commenting.FunctionComment.ThrowsComment)
----------------------------------------------------------------------
There is no comment for the specific @throws error line.
/**
* Ensure that any nodes that are parsed are only of allowed types.
*
* @param \Twig_Node $body
* The expression to check.
* @param int $lineno
* The source line.
*
* @throws \Twig_Error_Syntax
*/
The reason why this is failing is that str_word_count in line 360 in the sniff is parsing underscores as a word separator. If you change the third parameter to '\\_' it would not trigger this error.
if (str_word_count($tokens[($tag + 2)]['content'], 0, '\\') > 1) {
Comment | File | Size | Author |
---|---|---|---|
#6 | coder-FunctionCommentSniff-throws-error-fix-2707989-6.patch | 1.63 KB | anoopjohn |
Comments
Comment #2
anoopjohn CreditAttribution: anoopjohn at Zyxware Technologies commentedAttaching a patch that fixes this issue.
Comment #3
klausiLooks good, can you add a test case to good.php?
Comment #4
anoopjohn CreditAttribution: anoopjohn at Zyxware Technologies commentedI have updated the existing NoCommentThrows test case to allow no comments for classes with underscores as well. I have attached the patch herewith. On testing good.php I had found an error which I have reported separately #2712723: Drupal.WhiteSpace.OperatorSpacing.NoSpaceBeforeAmp triggering when using & as reference operator in an array
Comment #5
klausiIf I only apply the changes to good.php then the phpunit test does not fail. Can you create a separate test function in good.php that results in a phpunit test fail if the fix in FunctionCommentSniff is not applied?
Comment #6
anoopjohn CreditAttribution: anoopjohn at Zyxware Technologies commentedThanks for reviewing this patiently klausi. I have updated the patch with the changes as suggested. I hope this will take of this issue.
Comment #7
anoopjohn CreditAttribution: anoopjohn at Zyxware Technologies commentedComment #9
klausiI had to fix your test case one more time because the method name with underscores was invalid. Make sure to run ./vendor/bin/phpunit next time :)
Committed, thanks!
Comment #10
anoopjohn CreditAttribution: anoopjohn at Zyxware Technologies commentedThanks for guiding me on this. I will do that henceforth.