Page MenuHomePhabricator

D13842.id33423.diff
No OneTemporary

D13842.id33423.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -13,6 +13,7 @@
'ArcanistAliasWorkflow' => 'workflow/ArcanistAliasWorkflow.php',
'ArcanistAmendWorkflow' => 'workflow/ArcanistAmendWorkflow.php',
'ArcanistAnoidWorkflow' => 'workflow/ArcanistAnoidWorkflow.php',
+ 'ArcanistArrayElementXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistArrayElementXHPASTLinterRule.php',
'ArcanistArrayIndexSpacingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistArrayIndexSpacingXHPASTLinterRule.php',
'ArcanistArraySeparatorXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistArraySeparatorXHPASTLinterRule.php',
'ArcanistBackoutWorkflow' => 'workflow/ArcanistBackoutWorkflow.php',
@@ -289,6 +290,7 @@
'ArcanistAliasWorkflow' => 'ArcanistWorkflow',
'ArcanistAmendWorkflow' => 'ArcanistWorkflow',
'ArcanistAnoidWorkflow' => 'ArcanistWorkflow',
+ 'ArcanistArrayElementXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistArrayIndexSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistArraySeparatorXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistBackoutWorkflow' => 'ArcanistWorkflow',
diff --git a/src/lint/linter/__tests__/xhpast/array-element.lint-test b/src/lint/linter/__tests__/xhpast/array-element.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/array-element.lint-test
@@ -0,0 +1,26 @@
+<?php
+
+array(
+ 1, 2, 3,
+);
+
+array(
+ 'foo' => 'bar', 'bar' => 'baz',
+);
+~~~~~~~~~~
+warning:4:5
+warning:4:8
+warning:8:19
+~~~~~~~~~~
+<?php
+
+array(
+ 1,
+ 2,
+ 3,
+);
+
+array(
+ 'foo' => 'bar',
+ 'bar' => 'baz',
+);
diff --git a/src/lint/linter/xhpast/rules/ArcanistArrayElementXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistArrayElementXHPASTLinterRule.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/ArcanistArrayElementXHPASTLinterRule.php
@@ -0,0 +1,48 @@
+<?php
+
+final class ArcanistArrayElementXHPASTLinterRule
+ extends ArcanistXHPASTLinterRule {
+
+ const ID = 76;
+
+ public function getLintName() {
+ return pht('Array Element');
+ }
+
+ public function getLintSeverity() {
+ return ArcanistLintSeverity::SEVERITY_WARNING;
+ }
+
+ public function process(XHPASTNode $root) {
+ $arrays = $root->selectDescendantsOfType('n_ARRAY_LITERAL');
+
+ foreach ($arrays as $array) {
+ $values = $array
+ ->getChildOfType(0, 'n_ARRAY_VALUE_LIST')
+ ->getChildrenOfType('n_ARRAY_VALUE');
+
+ if (!$values) {
+ // There is no need to check an empty array.
+ continue;
+ }
+
+ $multiline = $array->getLineNumber() != $array->getEndLineNumber();
+
+ if (!$multiline) {
+ continue;
+ }
+
+ foreach ($values as $value) {
+ $before = head($value->getTokens())->getPrevToken();
+
+ if (strpos($before->getValue(), "\n") === false) {
+ $this->raiseLintAtToken(
+ $before,
+ pht('Array elements should each occupy a single line.'),
+ "\n".$value->getIndentation());
+ }
+ }
+ }
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Apr 17, 8:14 PM (6 d, 10 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7794812
Default Alt Text
D13842.id33423.diff (3 KB)

Event Timeline