Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14774835
D12321.id29605.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D12321.id29605.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
@@ -56,6 +56,7 @@
const LINT_FORMATTED_STRING = 54;
const LINT_UNNECESSARY_FINAL_MODIFIER = 55;
const LINT_UNNECESSARY_SEMICOLON = 56;
+ const LINT_CAST_SPACING = 57;
private $blacklistedFunctions = array();
private $naminghook;
@@ -125,6 +126,7 @@
self::LINT_FORMATTED_STRING => 'Formatted String',
self::LINT_UNNECESSARY_FINAL_MODIFIER => 'Unnecessary Final Modifier',
self::LINT_UNNECESSARY_SEMICOLON => 'Unnecessary Semicolon',
+ self::LINT_CAST_SPACING => 'Cast Spacing',
);
}
@@ -169,6 +171,7 @@
self::LINT_IMPLICIT_VISIBILITY => $advice,
self::LINT_UNNECESSARY_FINAL_MODIFIER => $advice,
self::LINT_UNNECESSARY_SEMICOLON => $advice,
+ self::LINT_CAST_SPACING => $advice,
);
}
@@ -236,7 +239,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '18';
+ return '19';
}
protected function resolveFuture($path, Future $future) {
@@ -316,6 +319,7 @@
'lintFormattedString' => self::LINT_FORMATTED_STRING,
'lintUnnecessaryFinalModifier' => self::LINT_UNNECESSARY_FINAL_MODIFIER,
'lintUnnecessarySemicolons' => self::LINT_UNNECESSARY_SEMICOLON,
+ 'lintCastSpacing' => self::LINT_CAST_SPACING,
);
foreach ($method_codes as $method => $codes) {
@@ -1201,7 +1205,7 @@
foreach ($foreach_loops as $foreach_loop) {
$var_map = array();
- $foreach_expr = $foreach_loop->getChildOftype(0, 'n_FOREACH_EXPRESSION');
+ $foreach_expr = $foreach_loop->getChildOfType(0, 'n_FOREACH_EXPRESSION');
// We might use one or two vars, i.e. "foreach ($x as $y => $z)" or
// "foreach ($x as $y)".
@@ -3263,6 +3267,31 @@
}
}
+ 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->raiseLintAtNode(
+ $cast,
+ self::LINT_CAST_SPACING,
+ pht('A cast statement must be followed by a single space.'),
+ $cast->getConcreteString().' ');
+ } else if ($after->getValue() != ' ') {
+ $this->raiseLintAtToken(
+ $after,
+ self::LINT_CAST_SPACING,
+ pht('A cast statement must be followed by a single space.'),
+ ' ');
+ }
+ }
+ }
+
public function getSuperGlobalNames() {
return array(
'$GLOBALS',
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 (string)0;
+echo (string) 1;
+echo (string) 2;
+~~~~~~~~~~
+advice:2:6
+advice:4:14
+~~~~~~~~~~
+<?php
+echo (string) 0;
+echo (string) 1;
+echo (string) 2;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 25, 2:19 AM (2 h, 41 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7045856
Default Alt Text
D12321.id29605.diff (3 KB)
Attached To
Mode
D12321: Add a linter rule for spacing after a cast
Attached
Detach File
Event Timeline
Log In to Comment