Skip to content

Commit

Permalink
Merge branch 'js-braceless-do-while' of https://github.com/pfrenssen/…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Nov 9, 2015
2 parents bb10769 + d3aba2f commit 57b7187
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,22 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}
}
}
}

// In Javascript DO WHILE loops without curly braces are legal. This
// is only valid if a single statement is present between the DO and
// the WHILE. We can detect this by checking only a single semicolon
// is present between them.
if ($phpcsFile->tokenizerType === 'JS') {
$lastDo = $phpcsFile->findPrevious(T_DO, ($stackPtr - 1));
$lastSemicolon = $phpcsFile->findPrevious(T_SEMICOLON, ($stackPtr - 1));
if ($lastDo !== false && $lastSemicolon !== false && $lastDo < $lastSemicolon) {
$precedingSemicolon = $phpcsFile->findPrevious(T_SEMICOLON, ($lastSemicolon - 1));
if ($precedingSemicolon === false || $precedingSemicolon < $lastDo) {
return;
}
}
}
}//end if

// This is a control structure without an opening brace,
// so it is an inline statement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ while (something) print 'hello';
do {
i--;
} while (something);

do i++; while (i < 5);
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ while (something) { print 'hello'; }
do {
i--;
} while (something);

do { i++; } while (i < 5);
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function getErrorList($testFile='InlineControlStructureUnitTest.inc')
11 => 1,
13 => 1,
15 => 1,
21 => 1,
);
break;
default:
Expand Down

0 comments on commit 57b7187

Please sign in to comment.