Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15395948
D13805.id33343.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D13805.id33343.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -238,6 +238,7 @@
'ArcanistTodoWorkflow' => 'workflow/ArcanistTodoWorkflow.php',
'ArcanistUSEnglishTranslation' => 'internationalization/ArcanistUSEnglishTranslation.php',
'ArcanistUnableToParseXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistUnableToParseXHPASTLinterRule.php',
+ 'ArcanistUnaryPostfixExpressionSpacingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistUnaryPostfixExpressionSpacingXHPASTLinterRule.php',
'ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule.php',
'ArcanistUndeclaredVariableXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistUndeclaredVariableXHPASTLinterRule.php',
'ArcanistUnitConsoleRenderer' => 'unit/renderer/ArcanistUnitConsoleRenderer.php',
@@ -513,6 +514,7 @@
'ArcanistTodoWorkflow' => 'ArcanistWorkflow',
'ArcanistUSEnglishTranslation' => 'PhutilTranslation',
'ArcanistUnableToParseXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
+ 'ArcanistUnaryPostfixExpressionSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistUndeclaredVariableXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistUnitConsoleRenderer' => 'ArcanistUnitRenderer',
diff --git a/src/lint/linter/__tests__/xhpast/unary-postfix-expression-spacing.lint-test b/src/lint/linter/__tests__/xhpast/unary-postfix-expression-spacing.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/unary-postfix-expression-spacing.lint-test
@@ -0,0 +1,9 @@
+<?php
+$x ++;
+$y--;
+~~~~~~~~~~
+warning:2:3
+~~~~~~~~~~
+<?php
+$x++;
+$y--;
diff --git a/src/lint/linter/xhpast/rules/ArcanistUnaryPostfixExpressionSpacingXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistUnaryPostfixExpressionSpacingXHPASTLinterRule.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/ArcanistUnaryPostfixExpressionSpacingXHPASTLinterRule.php
@@ -0,0 +1,36 @@
+<?php
+
+final class ArcanistUnaryPostfixExpressionSpacingXHPASTLinterRule
+ extends ArcanistXHPASTLinterRule {
+
+ const ID = 75;
+
+ public function getLintName() {
+ return pht('Space Before Unary Postfix Operator');
+ }
+
+ public function getLintSeverity() {
+ return ArcanistLintSeverity::SEVERITY_WARNING;
+ }
+
+ public function process(XHPASTNode $root) {
+ $expressions = $root->selectDescendantsOfType('n_UNARY_POSTFIX_EXPRESSION');
+
+ foreach ($expressions as $expression) {
+ $operator = $expression->getChildOfType(1, 'n_OPERATOR');
+ $operator_value = $operator->getConcreteString();
+ list($before, $after) = $operator->getSurroundingNonsemanticTokens();
+
+ if (!empty($before)) {
+ $leading_text = implode('', mpull($before, 'getValue'));
+
+ $this->raiseLintAtOffset(
+ $operator->getOffset() - strlen($leading_text),
+ pht('Unary postfix operators should not be followed by whitespace.'),
+ $leading_text,
+ '');
+ }
+ }
+ }
+
+}
diff --git a/src/lint/linter/xhpast/rules/ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule.php
--- a/src/lint/linter/xhpast/rules/ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/rules/ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule.php
@@ -6,7 +6,7 @@
const ID = 73;
public function getLintName() {
- return pht('Space After Unary Operator');
+ return pht('Space After Unary Prefix Operator');
}
public function getLintSeverity() {
@@ -31,7 +31,8 @@
if (!empty($after)) {
$this->raiseLintAtOffset(
$operator->getOffset() + strlen($operator->getConcreteString()),
- pht('Unary operators should not be followed by whitespace.'),
+ pht(
+ 'Unary prefix operators should not be followed by whitespace.'),
implode('', mpull($after, 'getValue')),
'');
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Mar 17, 10:55 AM (5 d, 20 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7708262
Default Alt Text
D13805.id33343.diff (4 KB)
Attached To
Mode
D13805: Add a linter rule for unary postfix expression spacing
Attached
Detach File
Event Timeline
Log In to Comment