Skip to content

Commit

Permalink
Further fix for #3060 (ref #3061, #3112)
Browse files Browse the repository at this point in the history
Sniff wasn't ignore static arrow functions, or fixing the indent correctly when it actually was incorrect
  • Loading branch information
gsherwood committed Sep 24, 2020
1 parent 9a9676f commit 136ba51
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,9 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
];
$ignoreTokens += Tokens::$castTokens;

if ($tokens[$valuePointer]['code'] === T_CLOSURE) {
if ($tokens[$valuePointer]['code'] === T_CLOSURE
|| $tokens[$valuePointer]['code'] === T_FN
) {
$ignoreTokens += [T_STATIC => T_STATIC];
}

Expand Down Expand Up @@ -667,12 +669,12 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
$found,
];

$fix = $phpcsFile->addFixableError($error, $valuePointer, 'ValueNotAligned', $data);
$fix = $phpcsFile->addFixableError($error, $first, 'ValueNotAligned', $data);
if ($fix === true) {
if ($found === 0) {
$phpcsFile->fixer->addContent(($valuePointer - 1), str_repeat(' ', $expected));
$phpcsFile->fixer->addContent(($first - 1), str_repeat(' ', $expected));
} else {
$phpcsFile->fixer->replaceToken(($valuePointer - 1), str_repeat(' ', $expected));
$phpcsFile->fixer->replaceToken(($first - 1), str_repeat(' ', $expected));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,14 @@ array(
,
);

yield array(
static fn () : string => '',
);

yield array(
static fn () : string => '',
);

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

yield array(
static fn () : string => '',
);

yield array(
static fn () : string => '',
);

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

yield [
static fn () : string => '',
];

yield [
static fn () : string => '',
];

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

yield [
static fn () : string => '',
];

yield [
static fn () : string => '',
];

// Intentional syntax error.
$a = [
'a' =>
Expand Down
4 changes: 4 additions & 0 deletions src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public function getErrorList($testFile='')
447 => 2,
448 => 3,
467 => 1,
471 => 1,
472 => 1,
];
case 'ArrayDeclarationUnitTest.2.inc':
return [
Expand Down Expand Up @@ -206,6 +208,8 @@ public function getErrorList($testFile='')
436 => 2,
437 => 3,
456 => 1,
460 => 1,
461 => 1,
];
default:
return [];
Expand Down

0 comments on commit 136ba51

Please sign in to comment.