mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 00:32:41 +01:00
Fix linting for spacing around default parameter assignment in function/method declaration
Summary: Fix linting for spacing around default parameter assignment in function/method declaration so that `function foo($x = null) {}` is preferred in favor of `function foo($x=null) {}`. Test Plan: Modified existing unit tests. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D10429
This commit is contained in:
parent
38502ba910
commit
16770ed210
2 changed files with 30 additions and 3 deletions
|
@ -1989,8 +1989,34 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Spacing around default parameter assignment in function/method
|
||||
// declarations (which is not n_BINARY_EXPRESSION).
|
||||
$parameters = $root->selectDescendantsOfType('n_DECLARATION_PARAMETER');
|
||||
foreach ($parameters as $parameter) {
|
||||
if ($parameter->getChildByIndex(2)->getTypeName() == 'n_EMPTY') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$operator = head($parameter->selectTokensOfType('='));
|
||||
$before = $operator->getNonsemanticTokensBefore();
|
||||
$after = $operator->getNonsemanticTokensAfter();
|
||||
|
||||
$replace = null;
|
||||
if (empty($before) && empty($after)) {
|
||||
$replace = ' = ';
|
||||
} else if (empty($before)) {
|
||||
$replace = ' =';
|
||||
} else if (empty($after)) {
|
||||
$replace = '= ';
|
||||
}
|
||||
|
||||
if ($replace !== null) {
|
||||
$this->raiseLintAtToken(
|
||||
$operator,
|
||||
self::LINT_BINARY_EXPRESSION_SPACING,
|
||||
'Convention: logical and arithmetic operators should be '.
|
||||
'surrounded by whitespace.',
|
||||
$replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function lintSpaceAroundConcatenationOperators(XHPASTNode $root) {
|
||||
|
|
|
@ -31,6 +31,7 @@ warning:8:3
|
|||
warning:9:4
|
||||
warning:10:3
|
||||
warning:11:3
|
||||
warning:13:14
|
||||
warning:20:52
|
||||
warning:21:54
|
||||
warning:22:21
|
||||
|
@ -48,7 +49,7 @@ $a -= $b;
|
|||
$a -= $b;
|
||||
$a === $b;
|
||||
$a.$b;
|
||||
function x($n=null) {}
|
||||
function x($n = null) {}
|
||||
function x($n = null) {}
|
||||
|
||||
$y /* ! */ += // ?
|
||||
|
|
Loading…
Reference in a new issue