Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15345322
D12321.id30693.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.id30693.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
@@ -61,6 +61,7 @@
const LINT_INNER_FUNCTION = 59;
const LINT_DEFAULT_PARAMETERS = 60;
const LINT_LOWERCASE_FUNCTIONS = 61;
+ const LINT_CAST_SPACING = 62;
private $blacklistedFunctions = array();
private $naminghook;
@@ -191,6 +192,8 @@
=> pht('Default Parameters'),
self::LINT_LOWERCASE_FUNCTIONS
=> pht('Lowercase Functions'),
+ self::LINT_CAST_SPACING
+ => pht('Cast Spacing'),
);
}
@@ -240,6 +243,7 @@
self::LINT_INNER_FUNCTION => $warning,
self::LINT_DEFAULT_PARAMETERS => $warning,
self::LINT_LOWERCASE_FUNCTIONS => $advice,
+ self::LINT_CAST_SPACING => $advice,
);
}
@@ -307,7 +311,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '24';
+ return '25';
}
protected function resolveFuture($path, Future $future) {
@@ -395,6 +399,7 @@
'lintInnerFunctions' => self::LINT_INNER_FUNCTION,
'lintDefaultParameters' => self::LINT_DEFAULT_PARAMETERS,
'lintLowercaseFunctions' => self::LINT_LOWERCASE_FUNCTIONS,
+ 'lintCastSpacing' => self::LINT_CAST_SPACING,
);
foreach ($method_codes as $method => $codes) {
@@ -3727,6 +3732,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
Tue, Mar 11, 9:49 AM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7517421
Default Alt Text
D12321.id30693.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