Skip to content

Commit

Permalink
FIX #1891 Where inline comment fails UseDeclaration sniff
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Feb 15, 2018
1 parent 9d81b3c commit 50dacfd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ public function process(File $phpcsFile, $stackPtr)
}

$end = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1));
$candidateComment = $end;

do {
$nextComment = $candidateComment;
$candidateComment = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextComment + 1));
} while ($candidateComment !== false && $tokens[$candidateComment]['line'] === $tokens[$end]['line']);

$end = $nextComment;

if ($end === false) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
use Foo\Bar; // trailing comment
// This should fail.

class Baz
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
use Foo\Bar; // trailing comment

// This should fail.

class Baz
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
use Foo\Bar; // trailing comment

// This should pass.
class Baz
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function getErrorList($testFile='')
18 => 1,
19 => 1,
];
case 'UseDeclarationUnitTest.10.inc':
return [2 => 1];
default:
return [];
}//end switch
Expand Down

0 comments on commit 50dacfd

Please sign in to comment.