Skip to content

Commit

Permalink
Fixed bug #3195 : Generic.WhiteSpace.ScopeIndent confusing message wh…
Browse files Browse the repository at this point in the history
…en combination of tabs and spaces found
  • Loading branch information
gsherwood committed Apr 8, 2021
1 parent 97f7898 commit b245bb3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #3192 : findStartOfStatement doesn't work correctly inside switch
-- Thanks to Vincent Langlet for the patch
- Fixed bug #3195 : Generic.WhiteSpace.ScopeIndent confusing message when combination of tabs and spaces found
- Fixed bug #3197 : Squiz.NamingConventions.ValidVariableName does not use correct error code for all member vars
- Fixed bug #3219 : Generic.Formatting.MultipleStatementAlignment false positive for empty anonymous classes and closures
- Fixed bug #3258 : Squiz.Formatting.OperatorBracket duplicate error messages for unary minus
Expand Down
32 changes: 26 additions & 6 deletions src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -973,18 +973,38 @@ public function process(File $phpcsFile, $stackPtr)
}

if ($this->tabIndent === true) {
$error .= '%s tabs, found %s';
$data = [
floor($checkIndent / $this->tabWidth),
floor($tokenIndent / $this->tabWidth),
];
$expectedTabs = floor($checkIndent / $this->tabWidth);
$foundTabs = floor($tokenIndent / $this->tabWidth);
$foundSpaces = ($tokenIndent - ($foundTabs * $this->tabWidth));
if ($foundSpaces > 0) {
if ($foundTabs > 0) {
$error .= '%s tabs, found %s tabs and %s spaces';
$data = [
$expectedTabs,
$foundTabs,
$foundSpaces,
];
} else {
$error .= '%s tabs, found %s spaces';
$data = [
$expectedTabs,
$foundSpaces,
];
}
} else {
$error .= '%s tabs, found %s';
$data = [
$expectedTabs,
$foundTabs,
];
}//end if
} else {
$error .= '%s spaces, found %s';
$data = [
$checkIndent,
$tokenIndent,
];
}
}//end if

if ($this->debug === true) {
$line = $tokens[$checkToken]['line'];
Expand Down

0 comments on commit b245bb3

Please sign in to comment.