Summary: Currently, linting PHP short array syntax (i.e. `[...]`) throws an exception ("Expected open parentheses"). This diff relaxes some restrictions which prevent short array syntax from linting with `ArcanistParenthesesSpacingXHPASTLinterRule`.
Test Plan: Modified test cases.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: agenticarus, Korvin
Differential Revision: https://secure.phabricator.com/D13895
array ( 1, 2, 3 );
list ( $x, $y ) = array();
+[ 1, 2 , 3 ];
~~~~~~~~~~
warning:3:6
warning:3:8
warning:4:5
warning:4:7
warning:4:14
+warning:5:2
+warning:5:11
~~~~~~~~~~
<?php
array(1, 2, 3);
list($x, $y) = array();
+[1, 2 , 3];
foreach ($nodes as $node) {
switch ($node->getTypeName()) {
case 'n_ARRAY_LITERAL':
+ if (head($node->getTokens())->getTypeName() == '[') {
+ // Short array syntax.
+ continue 2;
+ }
+
$params = $node->getChildOfType(0, 'n_ARRAY_VALUE_LIST');
break;
$tokens = $params->getTokens();
$first = head($tokens);
+
$leading = $first->getNonsemanticTokensBefore();
$leading_text = implode('', mpull($leading, 'getValue'));
if (preg_match('/^\s+$/', $leading_text)) {
$token_o = array_shift($tokens);
$token_c = array_pop($tokens);
- if ($token_o->getTypeName() !== '(') {
- throw new Exception(pht('Expected open parentheses.'));
- }
- if ($token_c->getTypeName() !== ')') {
- throw new Exception(pht('Expected close parentheses.'));
- }
$nonsem_o = $token_o->getNonsemanticTokensAfter();
$nonsem_c = $token_c->getNonsemanticTokensBefore();