Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15354306
D12296.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D12296.id.diff
View Options
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
@@ -2951,11 +2951,23 @@
continue;
}
- $this->raiseLintAtNode(
- $value,
+ list($before, $after) = $value->getSurroundingNonsemanticTokens();
+ $after = implode('', mpull($after, 'getValue'));
+
+ $original = $value->getConcreteString();
+ $replacement = $value->getConcreteString().',';
+
+ if (strpos($after, "\n") === false) {
+ $original .= $after;
+ $replacement .= rtrim($after)."\n".$array->getIndentation();
+ }
+
+ $this->raiseLintAtOffset(
+ $value->getOffset(),
self::LINT_ARRAY_SEPARATOR,
pht('Multi-lined arrays should have trailing commas.'),
- $value->getConcreteString().',');
+ $original,
+ $replacement);
} else if (!$multiline && $after && $after->getValue() == ',') {
$this->raiseLintAtToken(
$after,
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
@@ -9,7 +9,7 @@
array(
1,
2,
- 3
+ 3 // comment
);
array(
'foo',
@@ -20,10 +20,20 @@
This is some heredoc text.
EOTEXT
);
+array(
+ 1,
+ 2,
+ 3);
+array(
+ 1,
+ 2,
+ 3 /* comment */ );
~~~~~~~~~~
advice:3:14
advice:12:3
advice:16:3
+advice:26:3
+advice:30:3
~~~~~~~~~~
<?php
array(1, 2, 3);
@@ -36,7 +46,7 @@
array(
1,
2,
- 3,
+ 3, // comment
);
array(
'foo',
@@ -47,3 +57,13 @@
This is some heredoc text.
EOTEXT
);
+array(
+ 1,
+ 2,
+ 3,
+);
+array(
+ 1,
+ 2,
+ 3, /* comment */
+);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 12, 3:15 AM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7356754
Default Alt Text
D12296.id.diff (1 KB)
Attached To
Mode
D12296: Improve array comma rule
Attached
Detach File
Event Timeline
Log In to Comment