Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13977224
D10429.id25089.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D10429.id25089.diff
View Options
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
@@ -1985,8 +1985,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
Details
Attached
Mime Type
text/plain
Expires
Sat, Oct 19, 5:42 PM (3 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6733234
Default Alt Text
D10429.id25089.diff (1 KB)
Attached To
Mode
D10429: Fix linting for spacing around default parameter assignment in function/method declaration
Attached
Detach File
Event Timeline
Log In to Comment