Skip to content

fix(DocComment): Allow phpcs:ignore directives between param comments (#3526455) #266

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

Merged
merged 2 commits into from
May 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,12 @@ public function process(File $phpcsFile, $stackPtr)
continue;
}

// Search for the previous comment string but also allow for
// PHPCS ignore comments. If we encounter ignore comments then
// we need to be more lenient later by checking if $prev is an
// ignore comment.
$prev = $phpcsFile->findPrevious(
T_DOC_COMMENT_STRING,
([T_DOC_COMMENT_STRING => T_DOC_COMMENT_STRING] + Tokens::$phpcsCommentTokens),
($tag - 1),
$tokens[$commentStart]['comment_tags'][($pos - 1)]
);
Expand Down Expand Up @@ -442,6 +446,7 @@ public function process(File $phpcsFile, $stackPtr)
} else if ($isNewGroup === false
&& (in_array($currentTag, $checkTags) === true || in_array($previousTag, $checkTags) === true)
&& $previousTag !== $currentTag
&& in_array($tokens[$prev]['code'], Tokens::$phpcsCommentTokens) === false
) {
$error = 'Separate the %s and %s sections by a blank line.';
$fix = $phpcsFile->addFixableError($error, $tag, 'TagGroupSpacing', [$previousTag, $currentTag]);
Expand Down
27 changes: 27 additions & 0 deletions tests/Drupal/good/good.php
Original file line number Diff line number Diff line change
Expand Up @@ -2020,3 +2020,30 @@ public function ignore_phpstan_comment() {
// @phpstan-ignore-next-line missingType.return
public function ignore_phpstan_comment_with_attribute_before() {
}

/**
* Test PHPCS ignore comments between param docs.
*/
interface BreadcrumbBuilderInterface {

/**
* Whether this breadcrumb builder should be used to build the breadcrumb.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
* phpcs:ignore Drupal.Commenting.FunctionComment.ParamNameNoMatch
* @param \Drupal\Core\Cache\CacheableMetadata $cacheable_metadata
* The cacheable metadata to add to if your check varies by or depends
* on something. Anything you specify here does not have to be repeated in
* the build() method as it will be merged in automatically.
*
* @return bool
* TRUE if this builder should be used or FALSE to let other builders
* decide.
*
* @todo Uncomment new method parameters before drupal:12.0.0, see
* https://www.drupal.org/project/drupal/issues/3459277.
*/
public function applies(RouteMatchInterface $route_match /* , CacheableMetadata $cacheable_metadata */);

}