Skip to content

Commit 9168f53

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/InlineControlStructure: remove redundant condition
This commit removes a redundant condition that was added in fbea319 to support JS braceless do-while loops. A subsequent commit added similar code to support braceless do-while loops (plus for/while loops without body) for PHP, but it also works for JS (13c803b). There are a few syntax error cases that were handled by the code that is removed by this commit and are not handled by the code introduced in 13c803b. Without the removed code, they are now handled in a if condition right below. I added two tests with those cases to ensure the sniff continues working as expected.
1 parent 38b4646 commit 9168f53

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

src/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,6 @@ public function process(File $phpcsFile, $stackPtr)
9595
return;
9696
}
9797
}
98-
99-
// In Javascript DO WHILE loops without curly braces are legal. This
100-
// is only valid if a single statement is present between the DO and
101-
// the WHILE. We can detect this by checking only a single semicolon
102-
// is present between them.
103-
if ($tokens[$stackPtr]['code'] === T_WHILE && $phpcsFile->tokenizerType === 'JS') {
104-
$lastDo = $phpcsFile->findPrevious(T_DO, ($stackPtr - 1));
105-
$lastSemicolon = $phpcsFile->findPrevious(T_SEMICOLON, ($stackPtr - 1));
106-
if ($lastDo !== false && $lastSemicolon !== false && $lastDo < $lastSemicolon) {
107-
$precedingSemicolon = $phpcsFile->findPrevious(T_SEMICOLON, ($lastSemicolon - 1));
108-
if ($precedingSemicolon === false || $precedingSemicolon < $lastDo) {
109-
return;
110-
}
111-
}
112-
}
11398
}//end if
11499

115100
if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Intentional parse error (missing closing parenthesis).
2+
// This should be the only test in this file.
3+
// Testing that the sniff is *not* triggered.
4+
5+
do i++; while (i < 5
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Intentional parse error (missing opening parenthesis).
2+
// This should be the only test in this file.
3+
// Testing that the sniff is *not* triggered.
4+
5+
do i++; while

0 commit comments

Comments
 (0)