diff --git a/src/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php b/src/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php index bc4a916d20..ff1738328f 100644 --- a/src/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php +++ b/src/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php @@ -95,21 +95,6 @@ public function process(File $phpcsFile, $stackPtr) return; } } - - // 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 ($tokens[$stackPtr]['code'] === T_WHILE && $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 if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false diff --git a/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.js b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.js similarity index 100% rename from src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.js rename to src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.js diff --git a/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.js.fixed b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.js.fixed similarity index 100% rename from src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.js.fixed rename to src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.js.fixed diff --git a/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.2.js b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.2.js new file mode 100644 index 0000000000..e26c331270 --- /dev/null +++ b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.2.js @@ -0,0 +1,5 @@ +// Intentional parse error (missing closing parenthesis). +// This should be the only test in this file. +// Testing that the sniff is *not* triggered. + +do i++; while (i < 5 diff --git a/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.3.js b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.3.js new file mode 100644 index 0000000000..9ccedcda33 --- /dev/null +++ b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.3.js @@ -0,0 +1,5 @@ +// Intentional parse error (missing opening parenthesis). +// This should be the only test in this file. +// Testing that the sniff is *not* triggered. + +do i++; while diff --git a/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php index 5d42d1122a..afcaa3a335 100644 --- a/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php +++ b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php @@ -81,7 +81,7 @@ public function getErrorList($testFile='') 278 => 1, ]; - case 'InlineControlStructureUnitTest.js': + case 'InlineControlStructureUnitTest.1.js': return [ 3 => 1, 7 => 1,