diff --git a/src/lint/linter/__tests__/xhpast/call-time-pass-by-reference.lint-test b/src/lint/linter/__tests__/xhpast/call-time-pass-by-reference.lint-test --- a/src/lint/linter/__tests__/xhpast/call-time-pass-by-reference.lint-test +++ b/src/lint/linter/__tests__/xhpast/call-time-pass-by-reference.lint-test @@ -1,8 +1,8 @@ getTokens(); $first = head($tokens); - $last = last($tokens); + $last = last($tokens); $leading = $first->getNonsemanticTokensBefore(); $leading_text = implode('', mpull($leading, 'getValue')); @@ -32,14 +32,27 @@ $trailing = $last->getNonsemanticTokensBefore(); $trailing_text = implode('', mpull($trailing, 'getValue')); - if (preg_match('/^\s+$/', $leading_text)) { - $this->raiseLintAtOffset( - $first->getOffset() - strlen($leading_text), - pht( - 'Convention: no spaces before opening parenthesis in '. - 'function and method declarations.'), - $leading_text, - ''); + if ($dec->getChildByIndex(2)->getTypeName() == 'n_EMPTY') { + // Anonymous functions. + if ($leading_text != ' ') { + $this->raiseLintAtOffset( + $first->getOffset() - strlen($leading_text), + pht( + 'Convention: space before opening parenthesis in '. + 'anonymous function declarations.'), + $leading_text, + ' '); + } + } else { + if (preg_match('/^\s+$/', $leading_text)) { + $this->raiseLintAtOffset( + $first->getOffset() - strlen($leading_text), + pht( + 'Convention: no spaces before opening parenthesis in '. + 'function and method declarations.'), + $leading_text, + ''); + } } if (preg_match('/^\s+$/', $trailing_text)) { @@ -51,6 +64,33 @@ $trailing_text, ''); } + + $use_list = $dec->getChildByIndex(4); + if ($use_list->getTypeName() == 'n_EMPTY') { + continue; + } + $use_token = $use_list->selectTokensOfType('T_USE'); + + foreach ($use_token as $use) { + $before = $use->getNonsemanticTokensBefore(); + $after = $use->getNonsemanticTokensAfter(); + + if (!$before) { + $this->raiseLintAtOffset( + $use->getOffset(), + pht('Convention: space before `%s` token.', 'use'), + '', + ' '); + } + + if (!$after) { + $this->raiseLintAtOffset( + $use->getOffset() + strlen($use->getValue()), + pht('Convention: space after `%s` token.', 'use'), + '', + ' '); + } + } } }