diff --git a/.editorconfig b/.editorconfig --- a/.editorconfig +++ b/.editorconfig @@ -13,7 +13,7 @@ indent_style = end_of_line = max_line_length = -trim_trailing_whitespace = +trim_trailing_whitespace = false [src/parser/__tests__/bundle/*] insert_final_newline = false diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -3223,29 +3223,39 @@ $value = last($values); $after = last($value->getTokens())->getNextToken(); - if ($multiline && (!$after || $after->getValue() != ',')) { - if ($value->getChildByIndex(1)->getTypeName() == 'n_HEREDOC') { - continue; - } + if ($multiline) { + if (!$after || $after->getValue() != ',') { + if ($value->getChildByIndex(1)->getTypeName() == 'n_HEREDOC') { + continue; + } - list($before, $after) = $value->getSurroundingNonsemanticTokens(); - $after = implode('', mpull($after, 'getValue')); + list($before, $after) = $value->getSurroundingNonsemanticTokens(); + $after = implode('', mpull($after, 'getValue')); - $original = $value->getConcreteString(); - $replacement = $value->getConcreteString().','; + $original = $value->getConcreteString(); + $replacement = $value->getConcreteString().','; - if (strpos($after, "\n") === false) { - $original .= $after; - $replacement .= rtrim($after)."\n".$array->getIndentation(); - } + if (strpos($after, "\n") === false) { + $original .= $after; + $replacement .= $after."\n".$array->getIndentation(); + } - $this->raiseLintAtOffset( - $value->getOffset(), - self::LINT_ARRAY_SEPARATOR, - pht('Multi-lined arrays should have trailing commas.'), - $original, - $replacement); - } else if (!$multiline && $after && $after->getValue() == ',') { + $this->raiseLintAtOffset( + $value->getOffset(), + self::LINT_ARRAY_SEPARATOR, + pht('Multi-lined arrays should have trailing commas.'), + $original, + $replacement); + } else if ($value->getLineNumber() == $array->getEndLineNumber()) { + $close = last($array->getTokens()); + + $this->raiseLintAtToken( + $close, + self::LINT_ARRAY_SEPARATOR, + pht('Closing parenthesis should be on a new line.'), + "\n".$array->getIndentation().$close->getValue()); + } + } else if ($after && $after->getValue() == ',') { $this->raiseLintAtToken( $after, self::LINT_ARRAY_SEPARATOR, diff --git a/src/lint/linter/__tests__/xhpast/array-comma.lint-test b/src/lint/linter/__tests__/xhpast/array-comma.lint-test --- a/src/lint/linter/__tests__/xhpast/array-comma.lint-test +++ b/src/lint/linter/__tests__/xhpast/array-comma.lint-test @@ -28,12 +28,17 @@ 1, 2, 3 /* comment */ ); +array( + 1, + 2, + 3, /* comment */ ); ~~~~~~~~~~ advice:3:14 advice:12:3 advice:16:3 advice:26:3 advice:30:3 +advice:34:20 ~~~~~~~~~~