Skip to content

Commit 0d51d6e

Browse files
committed
SingleLineArrayWhitespaceSniff: Fixed false positive
1 parent 82d6176 commit 0d51d6e

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

SlevomatCodingStandard/Sniffs/Arrays/SingleLineArrayWhitespaceSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ private function checkWhitespaceBeforeComma(File $phpcsFile, int $comma): void
146146
return;
147147
}
148148

149+
if ($tokens[$comma - 2]['code'] === T_COMMA) {
150+
return;
151+
}
152+
149153
$error = sprintf('Expected 0 spaces between "%s" and comma, %d found.', $tokens[$comma - 2]['content'], $tokens[$comma - 1]['length']);
150154
$fix = $phpcsFile->addFixableError($error, $comma, self::CODE_SPACE_BEFORE_COMMA);
151155
if (!$fix) {

tests/Sniffs/Arrays/data/singleLineArrayWhitespaceNoErrors.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@
2222

2323
$array = [1, run([1, 2], 3)];
2424
$array = [1,];
25+
26+
[$a, , $c] = $array;

0 commit comments

Comments
 (0)