Skip to content

Commit 4f76f04

Browse files
committed
fix(FunctionComment): Allow PHPCS ignore directives before functions
1 parent 04a4563 commit 4f76f04

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public function process(File $phpcsFile, $stackPtr)
6363
$name = $tokens[$stackPtr]['content'];
6464
$classCodeStart = $stackPtr;
6565

66-
$previousContent = null;
6766
for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) {
6867
if (isset($find[$tokens[$commentEnd]['code']]) === true) {
6968
if (isset(Tokens::$phpcsCommentTokens[$tokens[$commentEnd]['code']]) === true) {
@@ -73,10 +72,6 @@ public function process(File $phpcsFile, $stackPtr)
7372
continue;
7473
}
7574

76-
if ($previousContent === null) {
77-
$previousContent = $commentEnd;
78-
}
79-
8075
if ($tokens[$commentEnd]['code'] === T_ATTRIBUTE_END
8176
&& isset($tokens[$commentEnd]['attribute_opener']) === true
8277
) {

coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,16 @@ public function register()
7575
public function process(File $phpcsFile, $stackPtr)
7676
{
7777
$tokens = $phpcsFile->getTokens();
78-
$ignore = Tokens::$methodPrefixes;
78+
$ignore = (Tokens::$methodPrefixes + Tokens::$phpcsCommentTokens);
7979
$ignore[T_WHITESPACE] = T_WHITESPACE;
8080
$functionCodeStart = $stackPtr;
8181

8282
for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) {
8383
if (isset($ignore[$tokens[$commentEnd]['code']]) === true) {
84+
if (isset(Tokens::$phpcsCommentTokens[$tokens[$commentEnd]['code']]) === true) {
85+
$functionCodeStart = $commentEnd;
86+
}
87+
8488
continue;
8589
}
8690

tests/Drupal/good/good.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,3 +1914,11 @@ enum PUROSELY_WRONG_BUT_OK: int {
19141914
case One = 1;
19151915
case Two = 2;
19161916
}
1917+
1918+
/**
1919+
* Doc block is here and an ignore directive is ok.
1920+
*/
1921+
// phpcs:ignore Drupal.NamingConventions.ValidClassName
1922+
function phpcs_ignore_comment() {
1923+
1924+
}

0 commit comments

Comments
 (0)