From 8f9dc18ec77dea21e9c622f3c143d785f326f76d Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 18 May 2025 17:32:08 +0200 Subject: [PATCH 1/2] fix(DocComment): Allow phpcs ignore comments before a tag (#3523506) --- .../Sniffs/Commenting/DocCommentSniff.php | 1 + tests/Drupal/good/good.php | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php index 0b2d342c..c58c97aa 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php @@ -370,6 +370,7 @@ public function process(File $phpcsFile, $stackPtr) if ($tokens[$firstTag]['line'] !== ($tokens[$prev]['line'] + 2) && isset($fileShort) === false && in_array($tokens[$firstTag]['content'], ['@code', '@link', '@endlink']) === false + && isset(Tokens::$phpcsCommentTokens[$tokens[$prev]['code']]) === false ) { $error = 'There must be exactly one blank line before the tags in a doc comment'; $fix = $phpcsFile->addFixableError($error, $firstTag, 'SpacingBeforeTags'); diff --git a/tests/Drupal/good/good.php b/tests/Drupal/good/good.php index 357ba614..c4693973 100644 --- a/tests/Drupal/good/good.php +++ b/tests/Drupal/good/good.php @@ -1986,3 +1986,27 @@ protected function getFallbackPluginId($plugin_id, array $configuration = []) { } } + +/** + * Provides a collection of condition plugins. + */ +class ConditionPluginCollection extends DefaultLazyPluginCollection { + + /** + * An array of collected contexts for conditions. + * + * @var \Drupal\Component\Plugin\Context\ContextInterface[] + */ + protected $conditionContexts = []; + + /** + * {@inheritdoc} + * + * phpcs:ignore Drupal.Commenting.FunctionComment.MissingReturnComment + * @return \Drupal\Core\Condition\ConditionInterface + */ + public function &get($instance_id) { + return 'x'; + } + +} From 241dfd006ccfc5a697b355fe72460d5c6ccd720a Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 18 May 2025 17:34:51 +0200 Subject: [PATCH 2/2] shorten test case --- tests/Drupal/good/good.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Drupal/good/good.php b/tests/Drupal/good/good.php index c4693973..42c269ae 100644 --- a/tests/Drupal/good/good.php +++ b/tests/Drupal/good/good.php @@ -1992,13 +1992,6 @@ protected function getFallbackPluginId($plugin_id, array $configuration = []) { */ class ConditionPluginCollection extends DefaultLazyPluginCollection { - /** - * An array of collected contexts for conditions. - * - * @var \Drupal\Component\Plugin\Context\ContextInterface[] - */ - protected $conditionContexts = []; - /** * {@inheritdoc} *