Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14096790
D13870.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
D13870.diff
View Options
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
@@ -156,6 +156,7 @@
'ArcanistLinter' => 'lint/linter/ArcanistLinter.php',
'ArcanistLinterTestCase' => 'lint/linter/__tests__/ArcanistLinterTestCase.php',
'ArcanistLintersWorkflow' => 'workflow/ArcanistLintersWorkflow.php',
+ 'ArcanistListAssignmentXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistListAssignmentXHPASTLinterRule.php',
'ArcanistListWorkflow' => 'workflow/ArcanistListWorkflow.php',
'ArcanistLogicalOperatorsXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistLogicalOperatorsXHPASTLinterRule.php',
'ArcanistLowercaseFunctionsXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistLowercaseFunctionsXHPASTLinterRule.php',
@@ -435,6 +436,7 @@
'ArcanistLinter' => 'Phobject',
'ArcanistLinterTestCase' => 'PhutilTestCase',
'ArcanistLintersWorkflow' => 'ArcanistWorkflow',
+ 'ArcanistListAssignmentXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistListWorkflow' => 'ArcanistWorkflow',
'ArcanistLogicalOperatorsXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistLowercaseFunctionsXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
diff --git a/src/lint/linter/__tests__/xhpast/list-assignment.lint-test b/src/lint/linter/__tests__/xhpast/list-assignment.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/list-assignment.lint-test
@@ -0,0 +1,11 @@
+<?php
+list($x, $y, , ,) = array();
+list($x, $y, , , $z) = array();
+~~~~~~~~~~
+warning:2:12
+warning:2:14
+warning:2:16
+~~~~~~~~~~
+<?php
+list($x, $y ) = array();
+list($x, $y, , , $z) = array();
diff --git a/src/lint/linter/xhpast/rules/ArcanistListAssignmentXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistListAssignmentXHPASTLinterRule.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/ArcanistListAssignmentXHPASTLinterRule.php
@@ -0,0 +1,38 @@
+<?php
+
+final class ArcanistListAssignmentXHPASTLinterRule
+ extends ArcanistXHPASTLinterRule {
+
+ const ID = 77;
+
+ public function getLintName() {
+ return pht('List Assignment');
+ }
+
+ public function getLintSeverity() {
+ return ArcanistLintSeverity::SEVERITY_WARNING;
+ }
+
+ public function process(XHPASTNode $root) {
+ $assignment_lists = $root->selectDescendantsOfType('n_ASSIGNMENT_LIST');
+
+ foreach ($assignment_lists as $assignment_list) {
+ $tokens = array_slice($assignment_list->getTokens(), 1, -1);
+
+ foreach (array_reverse($tokens) as $token) {
+ if ($token->getTypeName() == ',') {
+ $this->raiseLintAtToken(
+ $token,
+ pht('Unnecessary comma in list assignment.'),
+ '');
+ continue;
+ }
+
+ if ($token->isSemantic()) {
+ break;
+ }
+ }
+ }
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 5:14 AM (15 h, 33 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6792049
Default Alt Text
D13870.diff (2 KB)
Attached To
Mode
D13870: Add a linter rule for list assignments
Attached
Detach File
Event Timeline
Log In to Comment