Page MenuHomePhabricator

D13805.id33343.diff
No OneTemporary

D13805.id33343.diff

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

Mime Type
text/plain
Expires
Fri, Oct 11, 9:22 PM (21 h, 48 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6695794
Default Alt Text
D13805.id33343.diff (4 KB)

Event Timeline