Skip to content

Commit 032364c

Browse files
authored
fix(VariableComment): Allow phpcs:ignore comments before member variables (#3477601)
1 parent c43cb34 commit 032364c

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

.github/workflows/testing.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ jobs:
8080
if: ${{ matrix.extra-tests == '1' }}
8181
# In case Drupal core files have known problems that should be
8282
# ignored temporarily, add them with the --ignore option.
83+
# @todo Remove ignore option once Coder 8.3.27 is released and Drupal
84+
# core is updated to that version.
8385
run: |
8486
cd drupal/core
85-
../../vendor/bin/phpcs -p
87+
../../vendor/bin/phpcs -p -s --ignore=lib/Drupal/Core/Entity/EntityType.php,lib/Drupal/Core/Recipe/RecipeInputFormTrait.php,lib/Drupal/Core/Form/FormState.php,modules/migrate/src/Plugin/Migration.php,modules/views/src/ViewExecutable.php,modules/views/src/Plugin/views/style/StylePluginBase.php

coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use PHP_CodeSniffer\Files\File;
1313
use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
14+
use PHP_CodeSniffer\Util\Tokens;
1415

1516
/**
1617
* Parses and verifies class property doc comments.
@@ -38,7 +39,7 @@ class VariableCommentSniff extends AbstractVariableSniff
3839
public function processMemberVar(File $phpcsFile, $stackPtr)
3940
{
4041
$tokens = $phpcsFile->getTokens();
41-
$ignore = [
42+
$ignore = ([
4243
T_PUBLIC => T_PUBLIC,
4344
T_PRIVATE => T_PRIVATE,
4445
T_PROTECTED => T_PROTECTED,
@@ -57,7 +58,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
5758
T_FALSE => T_FALSE,
5859
T_SELF => T_SELF,
5960
T_PARENT => T_PARENT,
60-
];
61+
] + Tokens::$phpcsCommentTokens);
6162

6263
for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) {
6364
if (isset($ignore[$tokens[$commentEnd]['code']]) === true) {

tests/Drupal/Commenting/VariableCommentUnitTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,10 @@ class Test {
9696
*/
9797
protected UserStorageInterface&MockObject $userStorageMock2;
9898

99+
/**
100+
* The search score.
101+
*/
102+
// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName
103+
public string $search_score;
104+
99105
}

tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,10 @@ class Test {
100100
*/
101101
protected UserStorageInterface&MockObject $userStorageMock2;
102102

103+
/**
104+
* The search score.
105+
*/
106+
// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName
107+
public string $search_score;
108+
103109
}

0 commit comments

Comments
 (0)