Skip to content

Commit f606589

Browse files
authored
fix(DocComment): Allow phpcs:ignore directives between param comments (#3526455)
1 parent e8d5f31 commit f606589

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,12 @@ public function process(File $phpcsFile, $stackPtr)
406406
continue;
407407
}
408408

409+
// Search for the previous comment string but also allow for
410+
// PHPCS ignore comments. If we encounter ignore comments then
411+
// we need to be more lenient later by checking if $prev is an
412+
// ignore comment.
409413
$prev = $phpcsFile->findPrevious(
410-
T_DOC_COMMENT_STRING,
414+
([T_DOC_COMMENT_STRING => T_DOC_COMMENT_STRING] + Tokens::$phpcsCommentTokens),
411415
($tag - 1),
412416
$tokens[$commentStart]['comment_tags'][($pos - 1)]
413417
);
@@ -442,6 +446,7 @@ public function process(File $phpcsFile, $stackPtr)
442446
} else if ($isNewGroup === false
443447
&& (in_array($currentTag, $checkTags) === true || in_array($previousTag, $checkTags) === true)
444448
&& $previousTag !== $currentTag
449+
&& in_array($tokens[$prev]['code'], Tokens::$phpcsCommentTokens) === false
445450
) {
446451
$error = 'Separate the %s and %s sections by a blank line.';
447452
$fix = $phpcsFile->addFixableError($error, $tag, 'TagGroupSpacing', [$previousTag, $currentTag]);

tests/Drupal/good/good.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,3 +2020,30 @@ public function ignore_phpstan_comment() {
20202020
// @phpstan-ignore-next-line missingType.return
20212021
public function ignore_phpstan_comment_with_attribute_before() {
20222022
}
2023+
2024+
/**
2025+
* Test PHPCS ignore comments between param docs.
2026+
*/
2027+
interface BreadcrumbBuilderInterface {
2028+
2029+
/**
2030+
* Whether this breadcrumb builder should be used to build the breadcrumb.
2031+
*
2032+
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
2033+
* The current route match.
2034+
* phpcs:ignore Drupal.Commenting.FunctionComment.ParamNameNoMatch
2035+
* @param \Drupal\Core\Cache\CacheableMetadata $cacheable_metadata
2036+
* The cacheable metadata to add to if your check varies by or depends
2037+
* on something. Anything you specify here does not have to be repeated in
2038+
* the build() method as it will be merged in automatically.
2039+
*
2040+
* @return bool
2041+
* TRUE if this builder should be used or FALSE to let other builders
2042+
* decide.
2043+
*
2044+
* @todo Uncomment new method parameters before drupal:12.0.0, see
2045+
* https://www.drupal.org/project/drupal/issues/3459277.
2046+
*/
2047+
public function applies(RouteMatchInterface $route_match /* , CacheableMetadata $cacheable_metadata */);
2048+
2049+
}

0 commit comments

Comments
 (0)