Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Sep 21, 2020
2 parents 466297a + 42052ff commit 6804dbd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,14 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
$error = 'Expected 0 spaces before comma; %s found';
$data = [$spaceLength];

$fix = $phpcsFile->addFixableError($error, $nextToken, 'SpaceBeforeComma', $data);
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($nextToken - 1), '');
// The error is only fixable if there is only whitespace between the tokens.
if ($prev === $phpcsFile->findPrevious(T_WHITESPACE, ($nextToken - 1), null, true)) {
$fix = $phpcsFile->addFixableError($error, $nextToken, 'SpaceBeforeComma', $data);
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($nextToken - 1), '');
}
} else {
$phpcsFile->addError($error, $nextToken, 'SpaceBeforeComma', $data);
}
}
}//end if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,13 @@ array()
(unset) array(),
);

array(
'foo',
'bar'
// This is a non-fixable error.
,
);

// Intentional syntax error.
$a = array(
'a' =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,13 @@ array()
(unset) array(),
);

array(
'foo',
'bar'
// This is a non-fixable error.
,
);

// Intentional syntax error.
$a = array(
'a' =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,13 @@ $c];
(unset) [],
];

[
'foo',
'bar'
// This is a non-fixable error.
,
];

// Intentional syntax error.
$a = [
'a' =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,13 @@ $foo = [
(unset) [],
];

[
'foo',
'bar'
// This is a non-fixable error.
,
];

// Intentional syntax error.
$a = [
'a' =>
Expand Down
2 changes: 2 additions & 0 deletions src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function getErrorList($testFile='')
445 => 2,
447 => 2,
448 => 3,
467 => 1,
];
case 'ArrayDeclarationUnitTest.2.inc':
return [
Expand Down Expand Up @@ -204,6 +205,7 @@ public function getErrorList($testFile='')
434 => 2,
436 => 2,
437 => 3,
456 => 1,
];
default:
return [];
Expand Down

0 comments on commit 6804dbd

Please sign in to comment.