]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix brace formatting linter rule
authorJoshua Spence <josh@joshuaspence.com>
Fri, 17 Jul 2015 06:40:45 +0000 (16:40 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Fri, 17 Jul 2015 06:40:46 +0000 (16:40 +1000)
Summary: Fixes T8847.

Test Plan:
Ran `arc lint` on a test file:

```lang=php
<?php

if ($x) {
  echo 'foo';
}else {
  echo 'bar';
}
```

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T8847

Differential Revision: https://secure.phabricator.com/D13633

src/lint/linter/__tests__/xhpast/creative-brace-use.lint-test
src/lint/linter/xhpast/rules/ArcanistBraceFormattingXHPASTLinterRule.php

index 969417cc64d382051b1fda023b852f5d016fbc6b..1832ec1ef5d8f8f49244673ffb3942551f8d206b 100644 (file)
@@ -35,6 +35,8 @@ if ($x) {}
 else if ($y) {}
 else {}
 
+if ($x) {}else{}
+
 declare(ticks = 1);
 ~~~~~~~~~~
 advice:3:14
@@ -52,6 +54,7 @@ warning:31:6
 warning:32:4
 warning:34:11
 warning:35:16
+warning:38:11
 ~~~~~~~~~~
 <?php
 
@@ -77,4 +80,6 @@ do baz(); while ($x);
 
 if ($x) {} else if ($y) {} else {}
 
+if ($x) {} else{}
+
 declare(ticks = 1);
index b1bbedc40f59574ab555d3d569b7541d694e52d6..d29081541617f297d27cfa8e41af51c0ed71f32b 100644 (file)
@@ -20,6 +20,7 @@ final class ArcanistBraceFormattingXHPASTLinterRule
         continue;
       }
       list($before, $after) = $list->getSurroundingNonsemanticTokens();
+
       if (!$before) {
         $first = head($tokens);
 
@@ -39,6 +40,7 @@ final class ArcanistBraceFormattingXHPASTLinterRule
           ' '.$first->getValue());
       } else if (count($before) === 1) {
         $before = reset($before);
+
         if ($before->getValue() !== ' ') {
           $this->raiseLintAtToken(
             $before,
@@ -78,7 +80,7 @@ final class ArcanistBraceFormattingXHPASTLinterRule
       }
       list($before, $after) = $list->getSurroundingNonsemanticTokens();
       if (!$before) {
-        $first = last($tokens);
+        $first = head($tokens);
 
         $this->raiseLintAtToken(
           $first,