mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-25 16:22:42 +01:00
Add an XHPAST lint rule for brace formatting
Summary: See D753. Let's just have lint fix this. Depends on D754 (it fails to detect all the blocks without that patch, but doesn't do anything bad). Test Plan: Ran unit tests. Reviewed By: jungejason Reviewers: jungejason, tuomaspelkonen, aran CC: hunterbridges, aran, epriestley, jungejason Differential Revision: 755
This commit is contained in:
parent
57ff80e6c4
commit
17c82ff03c
2 changed files with 80 additions and 0 deletions
|
@ -155,6 +155,30 @@ class ArcanistXHPASTLinter extends ArcanistLinter {
|
|||
$this->lintPlusOperatorOnStrings($root);
|
||||
$this->lintDuplicateKeysInArray($root);
|
||||
$this->lintReusedIterators($root);
|
||||
$this->lintBraceFormatting($root);
|
||||
}
|
||||
|
||||
private function lintBraceFormatting($root) {
|
||||
|
||||
foreach ($root->selectDescendantsOfType('n_STATEMENT_LIST') as $list) {
|
||||
$tokens = $list->getTokens();
|
||||
if (!$tokens || head($tokens)->getValue() != '{') {
|
||||
continue;
|
||||
}
|
||||
list($before, $after) = $list->getSurroundingNonsemanticTokens();
|
||||
if (count($before) == 1) {
|
||||
$before = reset($before);
|
||||
if ($before->getValue() != ' ') {
|
||||
$this->raiseLintAtToken(
|
||||
$before,
|
||||
self::LINT_FORMATTING_CONVENTIONS,
|
||||
'Put opening braces on the same line as control statements and '.
|
||||
'declarations, with a single space before them.',
|
||||
' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function lintTautologicalExpressions($root) {
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
function f() {
|
||||
|
||||
}
|
||||
|
||||
function g()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (1)
|
||||
{}
|
||||
|
||||
foreach (x() as $y)
|
||||
{}
|
||||
|
||||
while (1)
|
||||
{}
|
||||
|
||||
switch (1)
|
||||
{}
|
||||
|
||||
try
|
||||
{}
|
||||
catch (Exception $x)
|
||||
{}
|
||||
~~~~~~~~~~
|
||||
warning:7:13
|
||||
warning:12:7
|
||||
warning:15:20
|
||||
warning:18:10
|
||||
warning:21:11
|
||||
warning:24:4
|
||||
warning:26:21
|
||||
~~~~~~~~~~
|
||||
<?php
|
||||
|
||||
function f() {
|
||||
|
||||
}
|
||||
|
||||
function g() {
|
||||
|
||||
}
|
||||
|
||||
if (1) {}
|
||||
|
||||
foreach (x() as $y) {}
|
||||
|
||||
while (1) {}
|
||||
|
||||
switch (1) {}
|
||||
|
||||
try {}
|
||||
catch (Exception $x) {}
|
Loading…
Reference in a new issue