mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-25 08:12: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:
parent
bf4e7d4ca8
commit
1e75302e77
3 changed files with 22 additions and 3 deletions
|
@ -32,6 +32,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistCSSLintLinterTestCase' => 'lint/linter/__tests__/ArcanistCSSLintLinterTestCase.php',
|
'ArcanistCSSLintLinterTestCase' => 'lint/linter/__tests__/ArcanistCSSLintLinterTestCase.php',
|
||||||
'ArcanistCSharpLinter' => 'lint/linter/ArcanistCSharpLinter.php',
|
'ArcanistCSharpLinter' => 'lint/linter/ArcanistCSharpLinter.php',
|
||||||
'ArcanistCallConduitWorkflow' => 'workflow/ArcanistCallConduitWorkflow.php',
|
'ArcanistCallConduitWorkflow' => 'workflow/ArcanistCallConduitWorkflow.php',
|
||||||
|
'ArcanistCallParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCallParenthesesXHPASTLinterRule.php',
|
||||||
'ArcanistCallTimePassByReferenceXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCallTimePassByReferenceXHPASTLinterRule.php',
|
'ArcanistCallTimePassByReferenceXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCallTimePassByReferenceXHPASTLinterRule.php',
|
||||||
'ArcanistCapabilityNotSupportedException' => 'workflow/exception/ArcanistCapabilityNotSupportedException.php',
|
'ArcanistCapabilityNotSupportedException' => 'workflow/exception/ArcanistCapabilityNotSupportedException.php',
|
||||||
'ArcanistCastSpacingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCastSpacingXHPASTLinterRule.php',
|
'ArcanistCastSpacingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCastSpacingXHPASTLinterRule.php',
|
||||||
|
@ -42,7 +43,6 @@ phutil_register_library_map(array(
|
||||||
'ArcanistClassNameLiteralXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistClassNameLiteralXHPASTLinterRule.php',
|
'ArcanistClassNameLiteralXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistClassNameLiteralXHPASTLinterRule.php',
|
||||||
'ArcanistCloseRevisionWorkflow' => 'workflow/ArcanistCloseRevisionWorkflow.php',
|
'ArcanistCloseRevisionWorkflow' => 'workflow/ArcanistCloseRevisionWorkflow.php',
|
||||||
'ArcanistCloseWorkflow' => 'workflow/ArcanistCloseWorkflow.php',
|
'ArcanistCloseWorkflow' => 'workflow/ArcanistCloseWorkflow.php',
|
||||||
'ArcanistClosingCallParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistClosingCallParenthesesXHPASTLinterRule.php',
|
|
||||||
'ArcanistClosureLinter' => 'lint/linter/ArcanistClosureLinter.php',
|
'ArcanistClosureLinter' => 'lint/linter/ArcanistClosureLinter.php',
|
||||||
'ArcanistClosureLinterTestCase' => 'lint/linter/__tests__/ArcanistClosureLinterTestCase.php',
|
'ArcanistClosureLinterTestCase' => 'lint/linter/__tests__/ArcanistClosureLinterTestCase.php',
|
||||||
'ArcanistCoffeeLintLinter' => 'lint/linter/ArcanistCoffeeLintLinter.php',
|
'ArcanistCoffeeLintLinter' => 'lint/linter/ArcanistCoffeeLintLinter.php',
|
||||||
|
@ -305,6 +305,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistCSSLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
|
'ArcanistCSSLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
|
||||||
'ArcanistCSharpLinter' => 'ArcanistLinter',
|
'ArcanistCSharpLinter' => 'ArcanistLinter',
|
||||||
'ArcanistCallConduitWorkflow' => 'ArcanistWorkflow',
|
'ArcanistCallConduitWorkflow' => 'ArcanistWorkflow',
|
||||||
|
'ArcanistCallParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||||
'ArcanistCallTimePassByReferenceXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
'ArcanistCallTimePassByReferenceXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||||
'ArcanistCapabilityNotSupportedException' => 'Exception',
|
'ArcanistCapabilityNotSupportedException' => 'Exception',
|
||||||
'ArcanistCastSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
'ArcanistCastSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||||
|
@ -315,7 +316,6 @@ phutil_register_library_map(array(
|
||||||
'ArcanistClassNameLiteralXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
'ArcanistClassNameLiteralXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||||
'ArcanistCloseRevisionWorkflow' => 'ArcanistWorkflow',
|
'ArcanistCloseRevisionWorkflow' => 'ArcanistWorkflow',
|
||||||
'ArcanistCloseWorkflow' => 'ArcanistWorkflow',
|
'ArcanistCloseWorkflow' => 'ArcanistWorkflow',
|
||||||
'ArcanistClosingCallParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
|
||||||
'ArcanistClosureLinter' => 'ArcanistExternalLinter',
|
'ArcanistClosureLinter' => 'ArcanistExternalLinter',
|
||||||
'ArcanistClosureLinterTestCase' => 'ArcanistExternalLinterTestCase',
|
'ArcanistClosureLinterTestCase' => 'ArcanistExternalLinterTestCase',
|
||||||
'ArcanistCoffeeLintLinter' => 'ArcanistExternalLinter',
|
'ArcanistCoffeeLintLinter' => 'ArcanistExternalLinter',
|
||||||
|
|
|
@ -16,9 +16,11 @@ The duck says, "Quack!"
|
||||||
The robot says, "Beep beep boop boop!"
|
The robot says, "Beep beep boop boop!"
|
||||||
EODOC
|
EODOC
|
||||||
);
|
);
|
||||||
|
f (1);
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
warning:4:4
|
warning:4:4
|
||||||
warning:9:4
|
warning:9:4
|
||||||
|
warning:19:2
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
@ -37,3 +39,4 @@ The duck says, "Quack!"
|
||||||
The robot says, "Beep beep boop boop!"
|
The robot says, "Beep beep boop boop!"
|
||||||
EODOC
|
EODOC
|
||||||
);
|
);
|
||||||
|
f(1);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class ArcanistClosingCallParenthesesXHPASTLinterRule
|
final class ArcanistCallParenthesesXHPASTLinterRule
|
||||||
extends ArcanistXHPASTLinterRule {
|
extends ArcanistXHPASTLinterRule {
|
||||||
|
|
||||||
const ID = 37;
|
const ID = 37;
|
||||||
|
@ -19,6 +19,22 @@ final class ArcanistClosingCallParenthesesXHPASTLinterRule
|
||||||
'n_METHOD_CALL',
|
'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) {
|
foreach ($calls as $call) {
|
||||||
// If the last parameter of a call is a HEREDOC, don't apply this rule.
|
// If the last parameter of a call is a HEREDOC, don't apply this rule.
|
||||||
$params = $call
|
$params = $call
|
Loading…
Reference in a new issue