Page MenuHomePhabricator

D12296.diff
No OneTemporary

D12296.diff

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

Mime Type
text/plain
Expires
Sat, Mar 15, 8:42 PM (6 d, 23 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7356754
Default Alt Text
D12296.diff (1 KB)

Event Timeline