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) {

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

anoopjohn created an issue. See original summary.

anoopjohn’s picture

Status: Active » Needs review
FileSize
856 bytes

Attaching a patch that fixes this issue.

klausi’s picture

Component: Review/Rules » Coder Sniffer
Status: Needs review » Needs work
Issue tags: +Needs tests

Looks good, can you add a test case to good.php?

anoopjohn’s picture

Status: Needs work » Needs review
FileSize
1.36 KB

I 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

klausi’s picture

Status: Needs review » Needs work

If 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?

anoopjohn’s picture

Thanks for reviewing this patiently klausi. I have updated the patch with the changes as suggested. I hope this will take of this issue.

anoopjohn’s picture

Status: Needs work » Needs review

  • klausi committed 3269a52 on 8.x-2.x authored by anoopjohn
    Issue #2707989 by anoopjohn: Drupal.Commenting.FunctionComment....
klausi’s picture

Status: Needs review » Fixed

I 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!

anoopjohn’s picture

Thanks for guiding me on this. I will do that henceforth.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.