Skip to content

Commit 42e2f04

Browse files
committed
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 f1a2cf2 commit 42e2f04

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
@@ -94,21 +94,6 @@ public function process(File $phpcsFile, $stackPtr)
9494
return;
9595
}
9696
}
97-
98-
// In Javascript DO WHILE loops without curly braces are legal. This
99-
// is only valid if a single statement is present between the DO and
100-
// the WHILE. We can detect this by checking only a single semicolon
101-
// is present between them.
102-
if ($tokens[$stackPtr]['code'] === T_WHILE && $phpcsFile->tokenizerType === 'JS') {
103-
$lastDo = $phpcsFile->findPrevious(T_DO, ($stackPtr - 1));
104-
$lastSemicolon = $phpcsFile->findPrevious(T_SEMICOLON, ($stackPtr - 1));
105-
if ($lastDo !== false && $lastSemicolon !== false && $lastDo < $lastSemicolon) {
106-
$precedingSemicolon = $phpcsFile->findPrevious(T_SEMICOLON, ($lastSemicolon - 1));
107-
if ($precedingSemicolon === false || $precedingSemicolon < $lastDo) {
108-
return;
109-
}
110-
}
111-
}
11297
}//end if
11398

11499
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)