Skip to content
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

fix(VariableComment): Allow phpcs:ignore comments before member variables #247

Merged
merged 3 commits into from
Jan 1, 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
4 changes: 3 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
../../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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions tests/Drupal/Commenting/VariableCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,10 @@ class Test {
*/
protected UserStorageInterface&MockObject $userStorageMock2;

/**
* The search score.
*/
// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName
public string $search_score;

}
6 changes: 6 additions & 0 deletions tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,10 @@ class Test {
*/
protected UserStorageInterface&MockObject $userStorageMock2;

/**
* The search score.
*/
// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName
public string $search_score;

}
Loading