Skip to content

Commit

Permalink
Ignore the previous element's T_COMMA when looking up the beginning o…
Browse files Browse the repository at this point in the history
…f the previous expression
  • Loading branch information
morozov committed Sep 5, 2020
1 parent 1371c59 commit 1697fac
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
// Determine how far indented the entire array declaration should be.
$ignore = Tokens::$emptyTokens;
$ignore[] = T_DOUBLE_ARROW;
$ignore[] = T_COMMA;
$prev = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true);
$start = $phpcsFile->findStartOfStatement($prev);
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $start, true);
Expand Down
11 changes: 11 additions & 0 deletions src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,14 @@ $var = [
2 => 'two',
/* three */ 3 => 'three',
];

// phpcs:set Generic.Arrays.ArrayIndent indent 4

$foo = [
'foo'
. 'bar',
[
'baz',
'qux',
],
];
11 changes: 11 additions & 0 deletions src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,14 @@ $var = [
2 => 'two',
/* three */ 3 => 'three',
];

// phpcs:set Generic.Arrays.ArrayIndent indent 4

$foo = [
'foo'
. 'bar',
[
'baz',
'qux',
],
];
3 changes: 3 additions & 0 deletions src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public function getErrorList()
77 => 1,
78 => 1,
79 => 1,
87 => 1,
88 => 1,
89 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit 1697fac

Please sign in to comment.