Skip to content

Commit e46cb5f

Browse files
committed
Fixed bug #2810 : PHPCBF fails to fix file with empty statement at start on control structure
1 parent 6a8941f commit e46cb5f

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/Standards/Squiz/Sniffs/WhiteSpace/SemicolonSpacingSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function process(File $phpcsFile, $stackPtr)
4949

5050
$nonSpace = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 2), null, true);
5151

52-
// Detect whether this is a semi-colons for a conditions in a `for()` control structure.
52+
// Detect whether this is a semi-colon for a condition in a `for()` control structure.
5353
$forCondition = false;
5454
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
5555
$nestedParens = $tokens[$stackPtr]['nested_parenthesis'];
@@ -67,6 +67,7 @@ public function process(File $phpcsFile, $stackPtr)
6767

6868
if ($tokens[$nonSpace]['code'] === T_SEMICOLON
6969
|| ($forCondition === true && $nonSpace === $tokens[$owner]['parenthesis_opener'])
70+
|| (isset($tokens[$nonSpace]['scope_opener']) === true)
7071
) {
7172
// Empty statement.
7273
return;

src/Standards/Squiz/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ for ( ; ; ) {}
2828
// But it should when the semi-colon in a `for` follows a comment (but shouldn't move the semi-colon).
2929
for ( /* Deliberately left empty. */ ; $ptr >= 0; $ptr-- ) {}
3030
for ( $i = 1 ; /* Deliberately left empty. */ ; $i++ ) {}
31+
32+
// This is an empty statement and should be ignored.
33+
if ($foo) {
34+
;
35+
}

src/Standards/Squiz/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ for ( ; ; ) {}
2828
// But it should when the semi-colon in a `for` follows a comment (but shouldn't move the semi-colon).
2929
for ( /* Deliberately left empty. */; $ptr >= 0; $ptr-- ) {}
3030
for ( $i = 1; /* Deliberately left empty. */; $i++ ) {}
31+
32+
// This is an empty statement and should be ignored.
33+
if ($foo) {
34+
;
35+
}

0 commit comments

Comments
 (0)