Skip to content

Commit

Permalink
Fixed bug #2913 : Generic.WhiteSpace.ScopeIndent false positive when …
Browse files Browse the repository at this point in the history
…opening and closing tag on same line inside conditional
  • Loading branch information
gsherwood committed Nov 17, 2020
1 parent 99b0339 commit 8421eeb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed an issue that could occurr when checking files on network drives, such as with WSL2 on Windows 10
-- This works around a long-standing PHP bug with is_readable()
-- Thanks to Michael S for the patch
- Fixed bug #2913 : Generic.WhiteSpace.ScopeIndent false positive when opening and closing tag on same line inside conditional
- Fixed bug #3157 : PSR2.ControlStructures.SwitchDeclaration.BreakIndent false positive when case keyword is not indented
</notes>
<contents>
Expand Down
9 changes: 8 additions & 1 deletion src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,14 @@ public function process(File $phpcsFile, $stackPtr)
echo "\t* open tag is inside condition; using open tag *".PHP_EOL;
}

$checkIndent = ($tokens[$lastOpenTag]['column'] - 1);
$first = $phpcsFile->findFirstOnLine([T_WHITESPACE, T_INLINE_HTML], $lastOpenTag, true);
if ($this->debug === true) {
$line = $tokens[$first]['line'];
$type = $tokens[$first]['type'];
echo "\t* first token on line $line is $first ($type) *".PHP_EOL;
}

$checkIndent = ($tokens[$first]['column'] - 1);
if (isset($adjustments[$condition]) === true) {
$checkIndent += $adjustments[$condition];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,12 @@ echo $string?->append('foo')
?->outputUsing();
// phpcs:set Generic.WhiteSpace.ScopeIndent exact false

if (true) {
?><?php echo addslashes(
''
)?><?php
}

/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,12 @@ echo $string?->append('foo')
?->outputUsing();
// phpcs:set Generic.WhiteSpace.ScopeIndent exact false

if (true) {
?><?php echo addslashes(
''
)?><?php
}

/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,12 @@ echo $string?->append('foo')
?->outputUsing();
// phpcs:set Generic.WhiteSpace.ScopeIndent exact false

if (true) {
?><?php echo addslashes(
''
)?><?php
}

/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,12 @@ echo $string?->append('foo')
?->outputUsing();
// phpcs:set Generic.WhiteSpace.ScopeIndent exact false

if (true) {
?><?php echo addslashes(
''
)?><?php
}

/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
1340 => 1,
1342 => 1,
1345 => 1,
1473 => 1,
1474 => 1,
1475 => 1,
1476 => 1,
1479 => 1,
1480 => 1,
1481 => 1,
1482 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit 8421eeb

Please sign in to comment.