From 1697fac33c6c049fa6ec778b33f45d1ffee82f72 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 4 Sep 2020 19:56:57 -0700 Subject: [PATCH] Ignore the previous element's T_COMMA when looking up the beginning of the previous expression --- .../Generic/Sniffs/Arrays/ArrayIndentSniff.php | 1 + .../Generic/Tests/Arrays/ArrayIndentUnitTest.inc | 11 +++++++++++ .../Tests/Arrays/ArrayIndentUnitTest.inc.fixed | 11 +++++++++++ .../Generic/Tests/Arrays/ArrayIndentUnitTest.php | 3 +++ 4 files changed, 26 insertions(+) diff --git a/src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php b/src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php index 22258ad598..adb74ec8cb 100644 --- a/src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php +++ b/src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php @@ -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); diff --git a/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc b/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc index 77d967745f..44398effb0 100644 --- a/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc +++ b/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc @@ -77,3 +77,14 @@ $var = [ 2 => 'two', /* three */ 3 => 'three', ]; + +// phpcs:set Generic.Arrays.ArrayIndent indent 4 + +$foo = [ + 'foo' + . 'bar', + [ + 'baz', + 'qux', + ], +]; diff --git a/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed b/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed index ac06a68158..d32d9e3a6d 100644 --- a/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed +++ b/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed @@ -78,3 +78,14 @@ $var = [ 2 => 'two', /* three */ 3 => 'three', ]; + +// phpcs:set Generic.Arrays.ArrayIndent indent 4 + +$foo = [ + 'foo' + . 'bar', + [ + 'baz', + 'qux', + ], +]; diff --git a/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.php b/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.php index 42dff594af..a4b89294b4 100644 --- a/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.php +++ b/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.php @@ -40,6 +40,9 @@ public function getErrorList() 77 => 1, 78 => 1, 79 => 1, + 87 => 1, + 88 => 1, + 89 => 1, ]; }//end getErrorList()