Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14053931
D10558.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D10558.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
@@ -2722,37 +2722,28 @@
$arrays = $root->selectDescendantsOfType('n_ARRAY_LITERAL');
foreach ($arrays as $array) {
- $commas = $array->selectTokensOfType(',');
- $values = $array->selectDescendantsOfType('n_ARRAY_VALUE');
+ $value_list = $array->getChildOfType(0, 'n_ARRAY_VALUE_LIST');
+ $values = $value_list->getChildrenOfType('n_ARRAY_VALUE');
- if ($values->count() == 0) {
+ if (!$values) {
// There is no need to check an empty array.
continue;
}
- // This is a little messy... we want to do `last($values)` but
- // `$values` is an `AASTNodeList`.
- $last = null;
- foreach ($values as $value) {
- $last = $value;
- }
-
$multiline = $array->getLineNumber() != $array->getEndLineNumber();
- if ($multiline && count($commas) != count($values)) {
+ $value = last($values);
+ $after = last($value->getTokens())->getNextToken();
+
+ if ($multiline && (!$after || $after->getValue() != ',')) {
$this->raiseLintAtNode(
- $last,
+ $value,
self::LINT_ARRAY_SEPARATOR,
pht('Multi-lined arrays should have trailing commas.'),
- $last->getConcreteString().',');
- } else if (!$multiline && count($commas) == count($values)) {
- $last_comma = null;
- foreach ($commas as $comma) {
- $last_comma = $comma;
- }
-
+ $value->getConcreteString().',');
+ } else if (!$multiline && $after && $after->getValue() == ',') {
$this->raiseLintAtToken(
- $last_comma,
+ $after,
self::LINT_ARRAY_SEPARATOR,
pht('Single lined arrays should not have a trailing comma.'),
'');
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
@@ -11,9 +11,14 @@
2,
3
);
+array(
+ 'foo',
+ array('foo')
+);
~~~~~~~~~~
advice:3:14
advice:12:3
+advice:16:3
~~~~~~~~~~
<?php
array(1, 2, 3);
@@ -28,3 +33,7 @@
2,
3,
);
+array(
+ 'foo',
+ array('foo'),
+);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 16, 8:45 PM (16 h, 11 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6713798
Default Alt Text
D10558.diff (2 KB)
Attached To
Mode
D10558: Fix `LINT_ARRAY_SEPARATOR` for nested arrays
Attached
Detach File
Event Timeline
Log In to Comment