1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-29 02:02:40 +01:00

Add a linter rule for spacing before opening parenthesis in function calls

Summary: Repurpose `ArcanistClosingCallParenthesesXHPASTLinterRule` (and rename it to `ArcanistCallParenthesesXHPASTLinterRule`) to ensure that there is no spacing before opening parenthesis in function calls.

Test Plan: Added test case.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D13796
This commit is contained in:
Joshua Spence 2015-08-06 06:57:46 +10:00
parent bf4e7d4ca8
commit 1e75302e77
3 changed files with 22 additions and 3 deletions

View file

@ -32,6 +32,7 @@ phutil_register_library_map(array(
'ArcanistCSSLintLinterTestCase' => 'lint/linter/__tests__/ArcanistCSSLintLinterTestCase.php',
'ArcanistCSharpLinter' => 'lint/linter/ArcanistCSharpLinter.php',
'ArcanistCallConduitWorkflow' => 'workflow/ArcanistCallConduitWorkflow.php',
'ArcanistCallParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCallParenthesesXHPASTLinterRule.php',
'ArcanistCallTimePassByReferenceXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCallTimePassByReferenceXHPASTLinterRule.php',
'ArcanistCapabilityNotSupportedException' => 'workflow/exception/ArcanistCapabilityNotSupportedException.php',
'ArcanistCastSpacingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCastSpacingXHPASTLinterRule.php',
@ -42,7 +43,6 @@ phutil_register_library_map(array(
'ArcanistClassNameLiteralXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistClassNameLiteralXHPASTLinterRule.php',
'ArcanistCloseRevisionWorkflow' => 'workflow/ArcanistCloseRevisionWorkflow.php',
'ArcanistCloseWorkflow' => 'workflow/ArcanistCloseWorkflow.php',
'ArcanistClosingCallParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistClosingCallParenthesesXHPASTLinterRule.php',
'ArcanistClosureLinter' => 'lint/linter/ArcanistClosureLinter.php',
'ArcanistClosureLinterTestCase' => 'lint/linter/__tests__/ArcanistClosureLinterTestCase.php',
'ArcanistCoffeeLintLinter' => 'lint/linter/ArcanistCoffeeLintLinter.php',
@ -305,6 +305,7 @@ phutil_register_library_map(array(
'ArcanistCSSLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistCSharpLinter' => 'ArcanistLinter',
'ArcanistCallConduitWorkflow' => 'ArcanistWorkflow',
'ArcanistCallParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistCallTimePassByReferenceXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistCapabilityNotSupportedException' => 'Exception',
'ArcanistCastSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
@ -315,7 +316,6 @@ phutil_register_library_map(array(
'ArcanistClassNameLiteralXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistCloseRevisionWorkflow' => 'ArcanistWorkflow',
'ArcanistCloseWorkflow' => 'ArcanistWorkflow',
'ArcanistClosingCallParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistClosureLinter' => 'ArcanistExternalLinter',
'ArcanistClosureLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistCoffeeLintLinter' => 'ArcanistExternalLinter',

View file

@ -16,9 +16,11 @@ The duck says, "Quack!"
The robot says, "Beep beep boop boop!"
EODOC
);
f (1);
~~~~~~~~~~
warning:4:4
warning:9:4
warning:19:2
~~~~~~~~~~
<?php
@ -37,3 +39,4 @@ The duck says, "Quack!"
The robot says, "Beep beep boop boop!"
EODOC
);
f(1);

View file

@ -1,6 +1,6 @@
<?php
final class ArcanistClosingCallParenthesesXHPASTLinterRule
final class ArcanistCallParenthesesXHPASTLinterRule
extends ArcanistXHPASTLinterRule {
const ID = 37;
@ -19,6 +19,22 @@ final class ArcanistClosingCallParenthesesXHPASTLinterRule
'n_METHOD_CALL',
));
foreach ($calls as $call) {
$params = $call->getChildOfType(1, 'n_CALL_PARAMETER_LIST');
$tokens = $params->getTokens();
$first = head($tokens);
$leading = $first->getNonsemanticTokensBefore();
$leading_text = implode('', mpull($leading, 'getValue'));
if (preg_match('/^\s+$/', $leading_text)) {
$this->raiseLintAtOffset(
$first->getOffset() - strlen($leading_text),
pht('Convention: no spaces before opening parenthesis in calls.'),
$leading_text,
'');
}
}
foreach ($calls as $call) {
// If the last parameter of a call is a HEREDOC, don't apply this rule.
$params = $call