'Use braces to surround a statement block.');
}
}
+
+ $nodes = $root->selectDescendantsOfTypes(array(
+ 'n_DO_WHILE',
+ 'n_ELSE',
+ 'n_ELSEIF',
+ ));
+ foreach ($nodes as $list) {
+ $tokens = $list->getTokens();
+ if (!$tokens || last($tokens)->getValue() != '}') {
+ continue;
+ }
+ list($before, $after) = $list->getSurroundingNonsemanticTokens();
+ if (!$before) {
+ $first = last($tokens);
+
+ $this->raiseLintAtToken(
+ $first,
+ self::LINT_BRACE_FORMATTING,
+ '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);
+ if ($before->getValue() !== ' ') {
+ $this->raiseLintAtToken(
+ $before,
+ self::LINT_BRACE_FORMATTING,
+ 'Put opening braces on the same line as control statements and '.
+ 'declarations, with a single space before them.',
+ ' ');
+ }
+ }
+ }
}
private function lintTautologicalExpressions(XHPASTNode $root) {
f( );
q( );
g();
-if ($x) {}
-else if ( $y ) {}
+if ($x) {} else if ( $y ) {}
$obj->m(
$x,
warning:2:8
warning:3:3
warning:4:3
-warning:7:10
-warning:7:13
-warning:13:6
-warning:13:30
-warning:14:10
-warning:14:19
-warning:15:12
-warning:15:15
-error:16:13 XHP19 Class-Filename Mismatch
-warning:17:21
-warning:17:24
-warning:19:10
-warning:19:25
+warning:6:21
+warning:6:24
+warning:12:6
+warning:12:30
+warning:13:10
+warning:13:19
+warning:14:12
+warning:14:15
+error:15:13 XHP19 Class-Filename Mismatch
+warning:16:21
+warning:16:24
+warning:18:10
+warning:18:25
~~~~~~~~~~
<?php
if ($x) {}
f();
q();
g();
-if ($x) {}
-else if ($y) {}
+if ($x) {} else if ($y) {}
$obj->m(
$x,