diff --git a/src/lint/linter/__tests__/xhpast/array-value.lint-test b/src/lint/linter/__tests__/xhpast/array-value.lint-test index a1339798..9ab10ad7 100644 --- a/src/lint/linter/__tests__/xhpast/array-value.lint-test +++ b/src/lint/linter/__tests__/xhpast/array-value.lint-test @@ -1,48 +1,56 @@ 'bar', 'bar' => 'baz', ); array( 1, /* quack */ 2, /* quack */3, ); array( /* OPEN */ 1, /* CLOSED */ 2, ); + +array('quack', +); ~~~~~~~~~~ warning:4:5 warning:4:8 warning:8:18 warning:12:17 warning:12:32 +warning:20:7 ~~~~~~~~~~ 'bar', 'bar' => 'baz', ); array( 1, /* quack */ 2, /* quack */ 3, ); array( /* OPEN */ 1, /* CLOSED */ 2, ); + +array( +'quack', +); diff --git a/src/lint/linter/xhpast/rules/ArcanistArrayValueXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistArrayValueXHPASTLinterRule.php index 21f50928..6b960d74 100644 --- a/src/lint/linter/xhpast/rules/ArcanistArrayValueXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/rules/ArcanistArrayValueXHPASTLinterRule.php @@ -1,56 +1,56 @@ selectDescendantsOfType('n_ARRAY_LITERAL'); foreach ($arrays as $array) { $array_values = $array ->getChildOfType(0, 'n_ARRAY_VALUE_LIST') ->getChildrenOfType('n_ARRAY_VALUE'); if (!$array_values) { // There is no need to check an empty array. continue; } $multiline = $array->getLineNumber() != $array->getEndLineNumber(); if (!$multiline) { continue; } foreach ($array_values as $value) { list($before, $after) = $value->getSurroundingNonsemanticTokens(); if (strpos(implode('', mpull($before, 'getValue')), "\n") === false) { - if (last($before)->isAnyWhitespace()) { + if (last($before) && last($before)->isAnyWhitespace()) { $token = last($before); $replacement = "\n".$value->getIndentation(); } else { $token = head($value->getTokens()); $replacement = "\n".$value->getIndentation().$token->getValue(); } $this->raiseLintAtToken( $token, pht('Array elements should each occupy a single line.'), $replacement); } } } } }