Differential D13895 Diff 33641 src/lint/linter/xhpast/rules/ArcanistCallParenthesesXHPASTLinterRule.php
Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/xhpast/rules/ArcanistCallParenthesesXHPASTLinterRule.php
| Show All 18 Lines | $nodes = $root->selectDescendantsOfTypes(array( | ||||
| 'n_FUNCTION_CALL', | 'n_FUNCTION_CALL', | ||||
| 'n_METHOD_CALL', | 'n_METHOD_CALL', | ||||
| 'n_LIST', | 'n_LIST', | ||||
| )); | )); | ||||
| foreach ($nodes as $node) { | foreach ($nodes as $node) { | ||||
| switch ($node->getTypeName()) { | switch ($node->getTypeName()) { | ||||
| case 'n_ARRAY_LITERAL': | case 'n_ARRAY_LITERAL': | ||||
| if (head($node->getTokens())->getTypeName() == '[') { | |||||
| // Short array syntax. | |||||
| continue 2; | |||||
| } | |||||
| $params = $node->getChildOfType(0, 'n_ARRAY_VALUE_LIST'); | $params = $node->getChildOfType(0, 'n_ARRAY_VALUE_LIST'); | ||||
| break; | break; | ||||
| case 'n_FUNCTION_CALL': | case 'n_FUNCTION_CALL': | ||||
| case 'n_METHOD_CALL': | case 'n_METHOD_CALL': | ||||
| $params = $node->getChildOfType(1, 'n_CALL_PARAMETER_LIST'); | $params = $node->getChildOfType(1, 'n_CALL_PARAMETER_LIST'); | ||||
| break; | break; | ||||
| case 'n_LIST': | case 'n_LIST': | ||||
| $params = $node->getChildOfType(0, 'n_ASSIGNMENT_LIST'); | $params = $node->getChildOfType(0, 'n_ASSIGNMENT_LIST'); | ||||
| break; | break; | ||||
| default: | default: | ||||
| throw new Exception( | throw new Exception( | ||||
| pht("Unexpected node of type '%s'!", $node->getTypeName())); | pht("Unexpected node of type '%s'!", $node->getTypeName())); | ||||
| } | } | ||||
| $tokens = $params->getTokens(); | $tokens = $params->getTokens(); | ||||
| $first = head($tokens); | $first = head($tokens); | ||||
| $leading = $first->getNonsemanticTokensBefore(); | $leading = $first->getNonsemanticTokensBefore(); | ||||
| $leading_text = implode('', mpull($leading, 'getValue')); | $leading_text = implode('', mpull($leading, 'getValue')); | ||||
| if (preg_match('/^\s+$/', $leading_text)) { | if (preg_match('/^\s+$/', $leading_text)) { | ||||
| $this->raiseLintAtOffset( | $this->raiseLintAtOffset( | ||||
| $first->getOffset() - strlen($leading_text), | $first->getOffset() - strlen($leading_text), | ||||
| pht('Convention: no spaces before opening parentheses.'), | pht('Convention: no spaces before opening parentheses.'), | ||||
| $leading_text, | $leading_text, | ||||
| ''); | ''); | ||||
| Show All 32 Lines | |||||