Skip to content

Commit

Permalink
Comment Placement sniff - allow comments in the first column after PH…
Browse files Browse the repository at this point in the history
…P opening tag
  • Loading branch information
michalbundyra committed May 2, 2019
1 parent d0d09ff commit aaf8ca9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

if ($tokens[$stackPtr - 1]['code'] !== T_WHITESPACE
if ($tokens[$stackPtr]['column'] !== 1
&& $tokens[$stackPtr - 1]['code'] !== T_WHITESPACE
&& ($tokens[$stackPtr - 1]['code'] !== T_COMMENT
|| $tokens[$stackPtr - 1]['line'] === $tokens[$stackPtr]['line'])
) {
Expand Down
1 change: 1 addition & 0 deletions test/Sniffs/Commenting/PlacementUnitTest.inc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
/* comment */

echo /* 1 */ 'hey';
echo 'world';// hey
Expand Down
1 change: 1 addition & 0 deletions test/Sniffs/Commenting/PlacementUnitTest.inc.fixed
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
/* comment */

echo 'hey'; /* 1 */
echo 'world'; // hey
Expand Down
6 changes: 3 additions & 3 deletions test/Sniffs/Commenting/PlacementUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class PlacementUnitTest extends AbstractTestCase
protected function getErrorList(string $testFile = '') : array
{
return [
3 => 1,
4 => 1,
6 => 3,
8 => 3,
5 => 1,
7 => 3,
9 => 3,
];
}

Expand Down

0 comments on commit aaf8ca9

Please sign in to comment.