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
$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,
if
($x) {}
+if ($x)
+ echo 100;
+else
+ echo 10;
+do
+ echo 1;
+while(true);
~~~~~~~~~~
warning:2:1
warning:3:1
warning:8:1
warning:13:3
warning:14:3
+warning:23:1
~~~~~~~~~~
<?php
if ($x) {}
if ($x) {}
if ($x) {}
+if ($x)
+ echo 100;
+else
+ echo 10;
+do
+ echo 1;
+while (true);