Skip to content

Commit

Permalink
Try to remove whitespace when fixing single line array
Browse files Browse the repository at this point in the history
Also refactor whitespace a little
  • Loading branch information
grongor committed Mar 16, 2020
1 parent 2914011 commit 6c31390
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,13 @@ public function processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arra
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->addNewline($arrayStart);
$phpcsFile->fixer->addNewlineBefore($arrayEnd);

if ($tokens[($arrayEnd - 1)]['code'] === T_WHITESPACE) {
$phpcsFile->fixer->replaceToken(($arrayEnd - 1), $phpcsFile->eolChar);
} else {
$phpcsFile->fixer->addNewlineBefore($arrayEnd);
}

$phpcsFile->fixer->endChangeset();
}

Expand Down Expand Up @@ -394,9 +400,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
continue;
}//end if

if ($tokens[$nextToken]['code'] !== T_DOUBLE_ARROW
&& $tokens[$nextToken]['code'] !== T_COMMA
) {
if ($tokens[$nextToken]['code'] !== T_DOUBLE_ARROW && $tokens[$nextToken]['code'] !== T_COMMA) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,12 @@ $a = array
// comment
(
'a',
'b',
'b',
);

$a = array /* comment */ (
'a',
'b',
'b',
);

$x = array('a' => false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ $listItems[$aliasPath] = [
'itemContent' => implode('<br/>', $aliases)
];

$x =
$x =
[
$x,
$y,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ $listItems[$aliasPath] = [
'itemContent' => implode('<br/>', $aliases),
];

$x =
$x =
[
$x,
$y,
Expand Down

0 comments on commit 6c31390

Please sign in to comment.