Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14774839
D12321.id30878.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D12321.id30878.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
@@ -64,6 +64,7 @@
const LINT_CLASS_NAME_LITERAL = 62;
const LINT_USELESS_OVERRIDING_METHOD = 63;
const LINT_NO_PARENT_SCOPE = 64;
+ const LINT_CAST_SPACING = 65;
private $blacklistedFunctions = array();
private $naminghook;
@@ -200,6 +201,8 @@
=> pht('Useless Overriding Method'),
self::LINT_NO_PARENT_SCOPE
=> pht('No Parent Scope'),
+ self::LINT_CAST_SPACING
+ => pht('Cast Spacing'),
);
}
@@ -251,6 +254,7 @@
self::LINT_LOWERCASE_FUNCTIONS => $advice,
self::LINT_CLASS_NAME_LITERAL => $advice,
self::LINT_USELESS_OVERRIDING_METHOD => $advice,
+ self::LINT_CAST_SPACING => $advice,
);
}
@@ -318,7 +322,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '26';
+ return '27';
}
protected function resolveFuture($path, Future $future) {
@@ -409,6 +413,7 @@
'lintClassNameLiteral' => self::LINT_CLASS_NAME_LITERAL,
'lintUselessOverridingMethods' => self::LINT_USELESS_OVERRIDING_METHOD,
'lintNoParentScope' => self::LINT_NO_PARENT_SCOPE,
+ 'lintCastSpacing' => self::LINT_CAST_SPACING,
);
foreach ($method_codes as $method => $codes) {
@@ -3887,6 +3892,25 @@
}
}
+ private function lintCastSpacing(XHPASTNode $root) {
+ $cast_expressions = $root->selectDescendantsOfType('n_CAST_EXPRESSION');
+
+ foreach ($cast_expressions as $cast_expression) {
+ $cast = $cast_expression->getChildOfType(0, 'n_CAST');
+
+ list($before, $after) = $cast->getSurroundingNonsemanticTokens();
+ $after = head($after);
+
+ if ($after) {
+ $this->raiseLintAtToken(
+ $after,
+ self::LINT_CAST_SPACING,
+ pht('A cast statement must not be followed by a space.'),
+ '');
+ }
+ }
+ }
+
/**
* Retrieve all calls to some specified function(s).
diff --git a/src/lint/linter/__tests__/xhpast/cast-spacing.lint-test b/src/lint/linter/__tests__/xhpast/cast-spacing.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/cast-spacing.lint-test
@@ -0,0 +1,12 @@
+<?php
+echo (double)0;
+echo (int) 1;
+echo (string) 2;
+~~~~~~~~~~
+advice:3:11
+advice:4:14
+~~~~~~~~~~
+<?php
+echo (double)0;
+echo (int)1;
+echo (string)2;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 25, 2:19 AM (2 h, 37 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7045860
Default Alt Text
D12321.id30878.diff (2 KB)
Attached To
Mode
D12321: Add a linter rule for spacing after a cast
Attached
Detach File
Event Timeline
Log In to Comment