From b74c4ea804c8a84cb89cabcfaaaad4fe95641049 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Wed, 1 Jan 2025 19:08:41 +0100 Subject: [PATCH 1/3] fix(VariableComment): Allow phpcs:ignore comments before member variables --- .../Drupal/Sniffs/Commenting/VariableCommentSniff.php | 5 +++-- tests/Drupal/Commenting/VariableCommentUnitTest.inc | 6 ++++++ tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php index bb5200d6..a707843e 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php @@ -11,6 +11,7 @@ use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; +use PHP_CodeSniffer\Util\Tokens; /** * Parses and verifies class property doc comments. @@ -38,7 +39,7 @@ class VariableCommentSniff extends AbstractVariableSniff public function processMemberVar(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - $ignore = [ + $ignore = ([ T_PUBLIC => T_PUBLIC, T_PRIVATE => T_PRIVATE, T_PROTECTED => T_PROTECTED, @@ -57,7 +58,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr) T_FALSE => T_FALSE, T_SELF => T_SELF, T_PARENT => T_PARENT, - ]; + ] + Tokens::$phpcsCommentTokens); for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) { if (isset($ignore[$tokens[$commentEnd]['code']]) === true) { diff --git a/tests/Drupal/Commenting/VariableCommentUnitTest.inc b/tests/Drupal/Commenting/VariableCommentUnitTest.inc index bfb78f30..e11a53d0 100644 --- a/tests/Drupal/Commenting/VariableCommentUnitTest.inc +++ b/tests/Drupal/Commenting/VariableCommentUnitTest.inc @@ -96,4 +96,10 @@ class Test { */ protected UserStorageInterface&MockObject $userStorageMock2; + /** + * The search score. + */ + // phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName + public string $search_score; + } diff --git a/tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed b/tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed index 25ed52c5..b2d9c1f4 100644 --- a/tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed +++ b/tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed @@ -100,4 +100,10 @@ class Test { */ protected UserStorageInterface&MockObject $userStorageMock2; + /** + * The search score. + */ + // phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName + public string $search_score; + } From 6a5d0188b1f8009868865c7aa5358050daaf9796 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Wed, 1 Jan 2025 19:23:10 +0100 Subject: [PATCH 2/3] ignore drupal core files that need to be fixed --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index e5a44484..2922c799 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -82,4 +82,4 @@ jobs: # ignored temporarily, add them with the --ignore option. run: | cd drupal/core - ../../vendor/bin/phpcs -p + ../../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 From 8edc9d277695d89c85a11a0e8e841dde045a65a8 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Wed, 1 Jan 2025 19:31:05 +0100 Subject: [PATCH 3/3] comment --- .github/workflows/testing.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 2922c799..4b9df659 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -80,6 +80,8 @@ jobs: if: ${{ matrix.extra-tests == '1' }} # In case Drupal core files have known problems that should be # ignored temporarily, add them with the --ignore option. + # @todo Remove ignore option once Coder 8.3.27 is released and Drupal + # core is updated to that version. run: | cd drupal/core ../../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