Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14399607
D12308.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D12308.diff
View Options
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
~~~~~~~~~~
<?php
array(1, 2, 3);
@@ -67,3 +72,8 @@
2,
3, /* comment */
);
+array(
+ 1,
+ 2,
+ 3, /* comment */
+);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 5:24 PM (19 h, 18 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6919672
Default Alt Text
D12308.diff (3 KB)
Attached To
Mode
D12308: Further improvements to array comma linter rule
Attached
Detach File
Event Timeline
Log In to Comment