Skip to content

Commit

Permalink
Fixed bug #2943 : Redundant semicolon added to a file when fixing PSR…
Browse files Browse the repository at this point in the history
…2.Files.ClosingTag.NotAllowed
  • Loading branch information
gsherwood committed May 1, 2020
1 parent 4215a31 commit e6f5158
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Standards/PSR2/Sniffs/Files/ClosingTagSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function process(File $phpcsFile, $stackPtr)
$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($last - 1), null, true);
if ($tokens[$prev]['code'] !== T_SEMICOLON
&& $tokens[$prev]['code'] !== T_CLOSE_CURLY_BRACKET
&& $tokens[$prev]['code'] !== T_OPEN_TAG
) {
$phpcsFile->fixer->addContent($prev, ';');
}
Expand All @@ -77,7 +78,7 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->recordMetric($stackPtr, 'PHP closing tag at end of PHP-only file', 'yes');
} else {
$phpcsFile->recordMetric($stackPtr, 'PHP closing tag at end of PHP-only file', 'no');
}
}//end if

// Ignore the rest of the file.
return $phpcsFile->numTokens;
Expand Down
5 changes: 5 additions & 0 deletions src/Standards/PSR2/Tests/Files/ClosingTagUnitTest.7.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
/*
* Some comment goes here
*/
?>
5 changes: 5 additions & 0 deletions src/Standards/PSR2/Tests/Files/ClosingTagUnitTest.7.inc.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
/*
* Some comment goes here
*/

1 change: 1 addition & 0 deletions src/Standards/PSR2/Tests/Files/ClosingTagUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function getErrorList($testFile='')
return [1 => 1];

case 'ClosingTagUnitTest.6.inc':
case 'ClosingTagUnitTest.7.inc':
return [5 => 1];

default:
Expand Down

0 comments on commit e6f5158

Please sign in to comment.