]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Make XHPASTLinter correct too little space before opening braces
authorepriestley <git@epriestley.com>
Wed, 4 Jan 2012 19:15:33 +0000 (11:15 -0800)
committerepriestley <git@epriestley.com>
Wed, 4 Jan 2012 22:14:47 +0000 (14:14 -0800)
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

src/lint/linter/xhpast/ArcanistXHPASTLinter.php
src/lint/linter/xhpast/__tests__/data/creative-brace-use.lint-test

index c552a32cbf3d92f75796259b3595306ce80dd029..0ff6c3051a4acbdfc6f4a635dbd569abf08af982 100644 (file)
@@ -168,7 +168,24 @@ class ArcanistXHPASTLinter extends ArcanistLinter {
         continue;
       }
       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);
         if ($before->getValue() != ' ') {
           $this->raiseLintAtToken(
index dc4f8bc4d25739818b4d08f98bf71b5a503d0222..3a5ef0ce6462825be8684ba54405a2c276ff632e 100644 (file)
@@ -25,6 +25,8 @@ try
 {}
 catch (Exception $x)
 {}
+
+function h(){}
 ~~~~~~~~~~
 warning:7:13
 warning:12:7
@@ -33,6 +35,7 @@ warning:18:10
 warning:21:11
 warning:24:4
 warning:26:21
+warning:29:13
 ~~~~~~~~~~
 <?php
 
@@ -54,3 +57,5 @@ switch (1) {}
 
 try {}
 catch (Exception $x) {}
+
+function h() {}