mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 06:42:41 +01:00
Improve the declaration parentheses linting
Summary: Improve `ArcanistClosingDeclarationParenthesesXHPASTLinterRule` (and rename it to `ArcanistDeclarationParenthesesXHPASTLinterRule`) to ensure that there is no whitespace before the opening parenthesis of a function/method declaration. Test Plan: Added test cases. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D13675
This commit is contained in:
parent
b7e87e959c
commit
e286ef66c8
3 changed files with 31 additions and 13 deletions
|
@ -43,7 +43,6 @@ phutil_register_library_map(array(
|
|||
'ArcanistCloseRevisionWorkflow' => 'workflow/ArcanistCloseRevisionWorkflow.php',
|
||||
'ArcanistCloseWorkflow' => 'workflow/ArcanistCloseWorkflow.php',
|
||||
'ArcanistClosingCallParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistClosingCallParenthesesXHPASTLinterRule.php',
|
||||
'ArcanistClosingDeclarationParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistClosingDeclarationParenthesesXHPASTLinterRule.php',
|
||||
'ArcanistClosureLinter' => 'lint/linter/ArcanistClosureLinter.php',
|
||||
'ArcanistClosureLinterTestCase' => 'lint/linter/__tests__/ArcanistClosureLinterTestCase.php',
|
||||
'ArcanistCoffeeLintLinter' => 'lint/linter/ArcanistCoffeeLintLinter.php',
|
||||
|
@ -67,6 +66,7 @@ phutil_register_library_map(array(
|
|||
'ArcanistCppcheckLinterTestCase' => 'lint/linter/__tests__/ArcanistCppcheckLinterTestCase.php',
|
||||
'ArcanistCpplintLinter' => 'lint/linter/ArcanistCpplintLinter.php',
|
||||
'ArcanistCpplintLinterTestCase' => 'lint/linter/__tests__/ArcanistCpplintLinterTestCase.php',
|
||||
'ArcanistDeclarationParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistDeclarationParenthesesXHPASTLinterRule.php',
|
||||
'ArcanistDefaultParametersXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistDefaultParametersXHPASTLinterRule.php',
|
||||
'ArcanistDiffChange' => 'parser/diff/ArcanistDiffChange.php',
|
||||
'ArcanistDiffChangeType' => 'parser/diff/ArcanistDiffChangeType.php',
|
||||
|
@ -316,7 +316,6 @@ phutil_register_library_map(array(
|
|||
'ArcanistCloseRevisionWorkflow' => 'ArcanistWorkflow',
|
||||
'ArcanistCloseWorkflow' => 'ArcanistWorkflow',
|
||||
'ArcanistClosingCallParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||
'ArcanistClosingDeclarationParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||
'ArcanistClosureLinter' => 'ArcanistExternalLinter',
|
||||
'ArcanistClosureLinterTestCase' => 'ArcanistExternalLinterTestCase',
|
||||
'ArcanistCoffeeLintLinter' => 'ArcanistExternalLinter',
|
||||
|
@ -340,6 +339,7 @@ phutil_register_library_map(array(
|
|||
'ArcanistCppcheckLinterTestCase' => 'ArcanistExternalLinterTestCase',
|
||||
'ArcanistCpplintLinter' => 'ArcanistExternalLinter',
|
||||
'ArcanistCpplintLinterTestCase' => 'ArcanistExternalLinterTestCase',
|
||||
'ArcanistDeclarationParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||
'ArcanistDefaultParametersXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||
'ArcanistDiffChange' => 'Phobject',
|
||||
'ArcanistDiffChangeType' => 'Phobject',
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
function f($x) {}
|
||||
function g($x ) {}
|
||||
function h ($x) {}
|
||||
|
||||
function &h($x) {}
|
||||
function &i($x ) {}
|
||||
function &i($x) {}
|
||||
function &j($x ) {}
|
||||
|
||||
final class X {
|
||||
|
||||
|
@ -24,21 +25,23 @@ f(function($x ) {});
|
|||
f(function($x ) use ($z) {});
|
||||
~~~~~~~~~~
|
||||
warning:4:14
|
||||
warning:7:15
|
||||
error:9:13
|
||||
warning:12:23
|
||||
warning:15:31
|
||||
warning:18:33
|
||||
warning:23:14
|
||||
warning:5:11
|
||||
warning:8:15
|
||||
error:10:13
|
||||
warning:11:23
|
||||
warning:16:31
|
||||
warning:19:33
|
||||
warning:24:14
|
||||
warning:25:14
|
||||
~~~~~~~~~~
|
||||
<?php
|
||||
|
||||
function f($x) {}
|
||||
function g($x) {}
|
||||
function h($x) {}
|
||||
|
||||
function &h($x) {}
|
||||
function &i($x) {}
|
||||
function &j($x) {}
|
||||
|
||||
final class X {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ArcanistClosingDeclarationParenthesesXHPASTLinterRule
|
||||
final class ArcanistDeclarationParenthesesXHPASTLinterRule
|
||||
extends ArcanistXHPASTLinterRule {
|
||||
|
||||
const ID = 38;
|
||||
|
@ -22,11 +22,26 @@ final class ArcanistClosingDeclarationParenthesesXHPASTLinterRule
|
|||
foreach ($decs as $dec) {
|
||||
$params = $dec->getChildOfType(3, 'n_DECLARATION_PARAMETER_LIST');
|
||||
$tokens = $params->getTokens();
|
||||
$last = array_pop($tokens);
|
||||
|
||||
$first = head($tokens);
|
||||
$last = last($tokens);
|
||||
|
||||
$leading = $first->getNonsemanticTokensBefore();
|
||||
$leading_text = implode('', mpull($leading, 'getValue'));
|
||||
|
||||
$trailing = $last->getNonsemanticTokensBefore();
|
||||
$trailing_text = implode('', mpull($trailing, 'getValue'));
|
||||
|
||||
if (preg_match('/^\s+$/', $leading_text)) {
|
||||
$this->raiseLintAtOffset(
|
||||
$first->getOffset() - strlen($leading_text),
|
||||
pht(
|
||||
'Convention: no spaces before opening parenthesis in '.
|
||||
'function and method declarations.'),
|
||||
$leading_text,
|
||||
'');
|
||||
}
|
||||
|
||||
if (preg_match('/^\s+$/', $trailing_text)) {
|
||||
$this->raiseLintAtOffset(
|
||||
$last->getOffset() - strlen($trailing_text),
|
Loading…
Reference in a new issue