mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-10 00:42:40 +01:00
Extend LINT_BRACE_FORMATTING
to support more scenarios
Summary: Extend the `ArcanistXHPASTLinter::LINT_BRACE_FORMATTING` rule to support a bunch of extra cases. Test Plan: Added test cases. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D10572
This commit is contained in:
parent
ee2070fadb
commit
4ca3463df6
4 changed files with 61 additions and 22 deletions
|
@ -902,6 +902,39 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
|||
'Use braces to surround a statement block.');
|
||||
}
|
||||
}
|
||||
|
||||
$nodes = $root->selectDescendantsOfTypes(array(
|
||||
'n_DO_WHILE',
|
||||
'n_ELSE',
|
||||
'n_ELSEIF',
|
||||
));
|
||||
foreach ($nodes as $list) {
|
||||
$tokens = $list->getTokens();
|
||||
if (!$tokens || last($tokens)->getValue() != '}') {
|
||||
continue;
|
||||
}
|
||||
list($before, $after) = $list->getSurroundingNonsemanticTokens();
|
||||
if (!$before) {
|
||||
$first = last($tokens);
|
||||
|
||||
$this->raiseLintAtToken(
|
||||
$first,
|
||||
self::LINT_BRACE_FORMATTING,
|
||||
'Put opening braces on the same line as control statements and '.
|
||||
'declarations, with a single space before them.',
|
||||
' '.$first->getValue());
|
||||
} else if (count($before) === 1) {
|
||||
$before = reset($before);
|
||||
if ($before->getValue() !== ' ') {
|
||||
$this->raiseLintAtToken(
|
||||
$before,
|
||||
self::LINT_BRACE_FORMATTING,
|
||||
'Put opening braces on the same line as control statements and '.
|
||||
'declarations, with a single space before them.',
|
||||
' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function lintTautologicalExpressions(XHPASTNode $root) {
|
||||
|
|
|
@ -30,6 +30,10 @@ function h(){}
|
|||
if ($x) foo();
|
||||
else bar();
|
||||
do baz(); while ($x);
|
||||
|
||||
if ($x) {}
|
||||
else if ($y) {}
|
||||
else {}
|
||||
~~~~~~~~~~
|
||||
advice:3:14
|
||||
warning:7:13
|
||||
|
@ -44,6 +48,8 @@ warning:29:13
|
|||
warning:30:9
|
||||
warning:31:6
|
||||
warning:32:4
|
||||
warning:34:11
|
||||
warning:35:16
|
||||
~~~~~~~~~~
|
||||
<?php
|
||||
|
||||
|
@ -66,3 +72,5 @@ function h() {}
|
|||
if ($x) foo();
|
||||
else bar();
|
||||
do baz(); while ($x);
|
||||
|
||||
if ($x) {} else if ($y) {} else {}
|
||||
|
|
|
@ -3,8 +3,7 @@ if ( $x ) {}
|
|||
f( );
|
||||
q( );
|
||||
g();
|
||||
if ($x) {}
|
||||
else if ( $y ) {}
|
||||
if ($x) {} else if ( $y ) {}
|
||||
|
||||
$obj->m(
|
||||
$x,
|
||||
|
@ -25,27 +24,26 @@ warning:2:5
|
|||
warning:2:8
|
||||
warning:3:3
|
||||
warning:4:3
|
||||
warning:7:10
|
||||
warning:7:13
|
||||
warning:13:6
|
||||
warning:13:30
|
||||
warning:14:10
|
||||
warning:14:19
|
||||
warning:15:12
|
||||
warning:15:15
|
||||
error:16:13 XHP19 Class-Filename Mismatch
|
||||
warning:17:21
|
||||
warning:17:24
|
||||
warning:19:10
|
||||
warning:19:25
|
||||
warning:6:21
|
||||
warning:6:24
|
||||
warning:12:6
|
||||
warning:12:30
|
||||
warning:13:10
|
||||
warning:13:19
|
||||
warning:14:12
|
||||
warning:14:15
|
||||
error:15:13 XHP19 Class-Filename Mismatch
|
||||
warning:16:21
|
||||
warning:16:24
|
||||
warning:18:10
|
||||
warning:18:25
|
||||
~~~~~~~~~~
|
||||
<?php
|
||||
if ($x) {}
|
||||
f();
|
||||
q();
|
||||
g();
|
||||
if ($x) {}
|
||||
else if ($y) {}
|
||||
if ($x) {} else if ($y) {}
|
||||
|
||||
$obj->m(
|
||||
$x,
|
||||
|
|
|
@ -24,6 +24,7 @@ do {
|
|||
} while(true);
|
||||
~~~~~~~~~~
|
||||
warning:2:1
|
||||
warning:2:10
|
||||
warning:3:1
|
||||
warning:4:1
|
||||
warning:5:1
|
||||
|
@ -31,21 +32,20 @@ warning:6:1
|
|||
warning:7:1
|
||||
warning:7:6
|
||||
warning:8:1
|
||||
warning:9:11
|
||||
warning:10:16
|
||||
warning:13:3
|
||||
warning:14:3
|
||||
warning:24:3
|
||||
~~~~~~~~~~
|
||||
<?php
|
||||
if ($x) {}
|
||||
else {}
|
||||
if ($x) {} else {}
|
||||
for (;;) {}
|
||||
foreach ($x as $y) {}
|
||||
while ($x) {}
|
||||
do {} while ($x);
|
||||
switch ($x) {}
|
||||
if ($x) {}
|
||||
else if ($y) {}
|
||||
else if ($z) {}
|
||||
if ($x) {} else if ($y) {} else if ($z) {}
|
||||
|
||||
if ($x) {}
|
||||
if ($x) {}
|
||||
|
|
Loading…
Reference in a new issue