mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 23:02:41 +01:00
Make XHPASTLinter correct too little space before opening braces
Summary: Previously, we would not correct missing space before "{". Test Plan: Ran unit tests. Reviewers: btrahan, jungejason, kiyoto Reviewed By: jungejason CC: aran, jungejason Differential Revision: https://secure.phabricator.com/D1313
This commit is contained in:
parent
6b22184712
commit
9cdaa6dc7a
2 changed files with 23 additions and 1 deletions
|
@ -168,7 +168,24 @@ class ArcanistXHPASTLinter extends ArcanistLinter {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
list($before, $after) = $list->getSurroundingNonsemanticTokens();
|
list($before, $after) = $list->getSurroundingNonsemanticTokens();
|
||||||
if (count($before) == 1) {
|
if (!$before) {
|
||||||
|
$first = head($tokens);
|
||||||
|
|
||||||
|
// Only insert the space if we're after a closing parenthesis. If
|
||||||
|
// we're in a construct like "else{}", other rules will insert space
|
||||||
|
// after the 'else' correctly.
|
||||||
|
$prev = $first->getPrevToken();
|
||||||
|
if (!$prev || $prev->getValue() != ')') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->raiseLintAtToken(
|
||||||
|
$first,
|
||||||
|
self::LINT_FORMATTING_CONVENTIONS,
|
||||||
|
'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);
|
$before = reset($before);
|
||||||
if ($before->getValue() != ' ') {
|
if ($before->getValue() != ' ') {
|
||||||
$this->raiseLintAtToken(
|
$this->raiseLintAtToken(
|
||||||
|
|
|
@ -25,6 +25,8 @@ try
|
||||||
{}
|
{}
|
||||||
catch (Exception $x)
|
catch (Exception $x)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
function h(){}
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
warning:7:13
|
warning:7:13
|
||||||
warning:12:7
|
warning:12:7
|
||||||
|
@ -33,6 +35,7 @@ warning:18:10
|
||||||
warning:21:11
|
warning:21:11
|
||||||
warning:24:4
|
warning:24:4
|
||||||
warning:26:21
|
warning:26:21
|
||||||
|
warning:29:13
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
@ -54,3 +57,5 @@ switch (1) {}
|
||||||
|
|
||||||
try {}
|
try {}
|
||||||
catch (Exception $x) {}
|
catch (Exception $x) {}
|
||||||
|
|
||||||
|
function h() {}
|
||||||
|
|
Loading…
Reference in a new issue