Skip to content

Commit

Permalink
Fixed bug squizlabs#1255 : Inconsistent indentation check results whe…
Browse files Browse the repository at this point in the history
…n ELSE on new line
  • Loading branch information
gsherwood committed Jan 18, 2017
1 parent a75e015 commit 06dd9c9
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,27 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$checkIndent = (int) (ceil($checkIndent / $this->indent) * $this->indent);
}

// Check the line indent.
// Special case for ELSE statements that are not on the same
// line as the previous IF statements closing brace. They still need
// to have the same indent or it will break code after the block.
if ($checkToken !== null && $tokens[$checkToken]['code'] === T_ELSE) {
$exact = true;
}

if ($checkIndent === null) {
$checkIndent = $currentIndent;
}

/*
The indent of the line is checked by the following IF block.
Up until now, we've just been figuring out what the indent
of this line should be.
After this IF block, we adjust the indent again for
the checking of future line.
*/

$adjusted = false;
if ($checkToken !== null
&& isset($this->_ignoreIndentationTokens[$tokens[$checkToken]['code']]) === false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,15 @@ $foo = foo(
return false;
}

?>
<?php
if (true) {
}
else if (true) {
}

$a = 1;

/*
$a = array(
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,15 @@ function foo()
return false;
}

?>
<?php
if (true) {
}
else if (true) {
}

$a = 1;

/*
$a = array(
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,15 @@ $foo = foo(
return false;
}

?>
<?php
if (true) {
}
else if (true) {
}

$a = 1;

/*
$a = array(
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,15 @@ function foo()
return false;
}

?>
<?php
if (true) {
}
else if (true) {
}

$a = 1;

/*
$a = array(
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
1176 => 1,
1178 => 1,
1181 => 1,
1185 => 1,
1186 => 1,
1187 => 1,
1188 => 1,
);

}//end getErrorList()
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #1249 : GitBlame report requires a .git directory
- Fixed bug #1252 : Squiz.Strings.ConcatenationSpacing fix creates syntax error when joining a number to a string
- Fixed bug #1253 : Generic.ControlStructures.InlineControlStructure fix creates syntax error fixing if-try/catch
- Fixed bug #1255 : Inconsistent indentation check results when ELSE on new line
- Fixed bug #1257 : Double dash in CSS class name can lead to "Named colours are forbidden" false positives
- Fixed bug #1260 : Syntax errors not being shown when error_prepend_string is set
-- Thanks to Juliette Reinders Folmer for the patch
Expand Down

0 comments on commit 06dd9c9

Please sign in to comment.