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 8723383
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
7 changes: 7 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,13 @@ public function process(File $phpcsFile, $stackPtr)
}

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

// the end of the line is allowed to be a comment as well as a semi colon
if ($nextComment !== false && $tokens[$nextComment]['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,10 @@ 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 8723383

Please sign in to comment.