1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-26 07:20:56 +01:00

Stop XHPASTLinter from eating a newline after else

Summary:
If the else clause does not have braces (one-liner), XHPASTLinter eats the
newline and brings the body statement of the else clause to the same line.

Test Plan: added a new test to space-after-control-keywords.lint-test

Reviewers: epriestley

CC: aran, epriestley, kiyoto

Differential Revision: https://secure.phabricator.com/D1367
This commit is contained in:
Kiyoto Tamura 2012-01-11 18:03:56 -08:00 committed by epriestley
parent b61e4eacf1
commit 6dfa45a8b3
2 changed files with 30 additions and 0 deletions

View file

@ -973,6 +973,21 @@ class ArcanistXHPASTLinter extends ArcanistLinter {
$token->getValue().' ');
} else if (count($after) == 1) {
$space = head($after);
// If we have an else clause with braces, $space may not be
// a single white space. e.g.,
//
// if ($x)
// echo 'foo'
// else // <- $space is not " " but "\n ".
// echo 'bar'
//
// We just require it starts with either a whitespace or a newline.
if ($token->getTypeName() == 'T_ELSE' ||
$token->getTypeName() == 'T_DO') {
break;
}
if ($space->isAnyWhitespace() && $space->getValue() != ' ') {
$this->raiseLintAtToken(
$space,

View file

@ -14,6 +14,13 @@ if ($x) {}
if
($x) {}
if ($x)
echo 100;
else
echo 10;
do
echo 1;
while(true);
~~~~~~~~~~
warning:2:1
warning:3:1
@ -25,6 +32,7 @@ warning:7:6
warning:8:1
warning:13:3
warning:14:3
warning:23:1
~~~~~~~~~~
<?php
if ($x) {}
@ -40,3 +48,10 @@ else if ($z) {}
if ($x) {}
if ($x) {}
if ($x)
echo 100;
else
echo 10;
do
echo 1;
while (true);