mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-10 08:52:39 +01:00
Extend LINT_BRACE_FORMATTING
to warn on missing braces
Summary: Extend the `ArcanistXHPASTLinter::LINT_BRACE_FORMATTING` rule to raise a warning when `n_STATEMENT` is used without having `n_STATEMENT_LIST` as a parent. Essentially, this means that `if ($x) { do_y(); }` is preferred over `if ($x) do_y();`. Test Plan: Added some test cases. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D10571
This commit is contained in:
parent
b46d4ed4ad
commit
ee2070fadb
4 changed files with 33 additions and 9 deletions
|
@ -890,6 +890,18 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$nodes = $root->selectDescendantsOfType('n_STATEMENT');
|
||||
foreach ($nodes as $node) {
|
||||
$parent = $node->getParentNode();
|
||||
|
||||
if ($parent && $parent->getTypeName() != 'n_STATEMENT_LIST') {
|
||||
$this->raiseLintAtNode(
|
||||
$node,
|
||||
self::LINT_BRACE_FORMATTING,
|
||||
'Use braces to surround a statement block.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function lintTautologicalExpressions(XHPASTNode $root) {
|
||||
|
|
|
@ -23,6 +23,7 @@ if ($var()) {}
|
|||
error:5:3
|
||||
error:7:3
|
||||
error:12:7
|
||||
warning:16:3
|
||||
~~~~~~~~~~
|
||||
~~~~~~~~~~
|
||||
{"config": {"xhpast.php-version": "5.3.0"}}
|
||||
|
|
|
@ -27,6 +27,9 @@ catch (Exception $x)
|
|||
{}
|
||||
|
||||
function h(){}
|
||||
if ($x) foo();
|
||||
else bar();
|
||||
do baz(); while ($x);
|
||||
~~~~~~~~~~
|
||||
advice:3:14
|
||||
warning:7:13
|
||||
|
@ -38,6 +41,9 @@ warning:21:11
|
|||
warning:24:4
|
||||
warning:26:21
|
||||
warning:29:13
|
||||
warning:30:9
|
||||
warning:31:6
|
||||
warning:32:4
|
||||
~~~~~~~~~~
|
||||
<?php
|
||||
|
||||
|
@ -57,3 +63,6 @@ try {}
|
|||
catch (Exception $x) {}
|
||||
|
||||
function h() {}
|
||||
if ($x) foo();
|
||||
else bar();
|
||||
do baz(); while ($x);
|
||||
|
|
|
@ -14,13 +14,14 @@ if ($x) {}
|
|||
if
|
||||
|
||||
($x) {}
|
||||
if ($x)
|
||||
if ($x) {
|
||||
echo 100;
|
||||
else
|
||||
} else {
|
||||
echo 10;
|
||||
do
|
||||
}
|
||||
do {
|
||||
echo 1;
|
||||
while(true);
|
||||
} while(true);
|
||||
~~~~~~~~~~
|
||||
warning:2:1
|
||||
warning:3:1
|
||||
|
@ -32,7 +33,7 @@ warning:7:6
|
|||
warning:8:1
|
||||
warning:13:3
|
||||
warning:14:3
|
||||
warning:23:1
|
||||
warning:24:3
|
||||
~~~~~~~~~~
|
||||
<?php
|
||||
if ($x) {}
|
||||
|
@ -48,10 +49,11 @@ else if ($z) {}
|
|||
|
||||
if ($x) {}
|
||||
if ($x) {}
|
||||
if ($x)
|
||||
if ($x) {
|
||||
echo 100;
|
||||
else
|
||||
} else {
|
||||
echo 10;
|
||||
do
|
||||
}
|
||||
do {
|
||||
echo 1;
|
||||
while (true);
|
||||
} while (true);
|
||||
|
|
Loading…
Reference in a new issue