Page MenuHomePhabricator

D12321.diff
No OneTemporary

D12321.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
@@ -65,6 +65,7 @@
const LINT_USELESS_OVERRIDING_METHOD = 63;
const LINT_NO_PARENT_SCOPE = 64;
const LINT_ALIAS_FUNCTION = 65;
+ const LINT_CAST_SPACING = 66;
private $blacklistedFunctions = array();
private $naminghook;
@@ -203,6 +204,8 @@
=> pht('No Parent Scope'),
self::LINT_ALIAS_FUNCTION
=> pht('Alias Functions'),
+ self::LINT_CAST_SPACING
+ => pht('Cast Spacing'),
);
}
@@ -255,6 +258,7 @@
self::LINT_CLASS_NAME_LITERAL => $advice,
self::LINT_USELESS_OVERRIDING_METHOD => $advice,
self::LINT_ALIAS_FUNCTION => $advice,
+ self::LINT_CAST_SPACING => $advice,
);
}
@@ -322,7 +326,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '27';
+ return '28';
}
protected function resolveFuture($path, Future $future) {
@@ -414,6 +418,7 @@
'lintUselessOverridingMethods' => self::LINT_USELESS_OVERRIDING_METHOD,
'lintNoParentScope' => self::LINT_NO_PARENT_SCOPE,
'lintAliasFunctions' => self::LINT_ALIAS_FUNCTION,
+ 'lintCastSpacing' => self::LINT_CAST_SPACING,
);
foreach ($method_codes as $method => $codes) {
@@ -4100,6 +4105,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

Mime Type
text/plain
Expires
Sat, May 18, 7:22 AM (2 w, 12 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6299775
Default Alt Text
D12321.diff (2 KB)

Event Timeline