diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 9b12f49d..4783a8d6 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -238,6 +238,7 @@ phutil_register_library_map(array( '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 @@ phutil_register_library_map(array( '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 index 00000000..6e08218e --- /dev/null +++ b/src/lint/linter/__tests__/xhpast/unary-postfix-expression-spacing.lint-test @@ -0,0 +1,9 @@ +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, + ''); + } + } + } + +} diff --git a/src/lint/linter/xhpast/rules/ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule.php index 2d398c4e..5fa91ffd 100644 --- a/src/lint/linter/xhpast/rules/ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/rules/ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule.php @@ -6,7 +6,7 @@ final class ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule 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 @@ final class ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule 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')), ''); }