Summary: Unary postfix expressions should not have a space before the operator.
Test Plan: Added test case.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: Korvin
Differential Revision: https://secure.phabricator.com/D13805
'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',
'ArcanistTodoWorkflow' => 'ArcanistWorkflow',
'ArcanistUSEnglishTranslation' => 'PhutilTranslation',
'ArcanistUnableToParseXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
+ 'ArcanistUnaryPostfixExpressionSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistUndeclaredVariableXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistUnitConsoleRenderer' => 'ArcanistUnitRenderer',
--- /dev/null
+<?php
+$x ++;
+$y--;
+~~~~~~~~~~
+warning:2:3
+~~~~~~~~~~
+<?php
+$x++;
+$y--;
--- /dev/null
+<?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 prefixed by whitespace.'),
+ $leading_text,
+ '');
+ }
+ }
+ }
+
+}
const ID = 73;
public function getLintName() {
- return pht('Space After Unary Operator');
+ return pht('Space After Unary Prefix Operator');
}
public function getLintSeverity() {
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')),
'');
}