Page MenuHomePhabricator

D10429.diff
No OneTemporary

D10429.diff

diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php
--- a/src/lint/linter/ArcanistXHPASTLinter.php
+++ b/src/lint/linter/ArcanistXHPASTLinter.php
@@ -1989,8 +1989,34 @@
}
}
- // 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) {
diff --git a/src/lint/linter/__tests__/xhpast/space-around-operators.lint-test b/src/lint/linter/__tests__/xhpast/space-around-operators.lint-test
--- a/src/lint/linter/__tests__/xhpast/space-around-operators.lint-test
+++ b/src/lint/linter/__tests__/xhpast/space-around-operators.lint-test
@@ -31,6 +31,7 @@
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;
-function x($n=null) {}
+function x($n = null) {}
function x($n = null) {}
$y /* ! */ += // ?

File Metadata

Mime Type
text/plain
Expires
Thu, Nov 7, 7:08 PM (5 d, 7 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6727669
Default Alt Text
D10429.diff (1 KB)

Event Timeline