]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Make XHPAST linter correct too much space after control keywords like "if"
authorepriestley <git@epriestley.com>
Wed, 4 Jan 2012 18:59:00 +0000 (10:59 -0800)
committerepriestley <git@epriestley.com>
Wed, 4 Jan 2012 22:14:40 +0000 (14:14 -0800)
Summary: Previously, we would not correct excessive space after "if", etc.

Test Plan: Ran test case.

Reviewers: btrahan, jungejason, kiyoto

Reviewed By: jungejason

CC: aran, jungejason, epriestley
Differential Revision: https://secure.phabricator.com/D1311

src/lint/linter/xhpast/ArcanistXHPASTLinter.php
src/lint/linter/xhpast/__tests__/data/space-after-control-keywords.lint-test

index 28b26811c78e3776d131f50ce7ecae857533af80..c552a32cbf3d92f75796259b3595306ce80dd029 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -954,6 +954,15 @@ class ArcanistXHPASTLinter extends ArcanistLinter {
               self::LINT_FORMATTING_CONVENTIONS,
               'Convention: put a space after control statements.',
               $token->getValue().' ');
+          } else if (count($after) == 1) {
+            $space = head($after);
+            if ($space->isAnyWhitespace() && $space->getValue() != ' ') {
+              $this->raiseLintAtToken(
+                $space,
+                self::LINT_FORMATTING_CONVENTIONS,
+                'Convention: put a single space after control statements.',
+                ' ');
+            }
           }
           break;
       }
index 2d0a21a02f0ad9f62fffca40f7225c73c0420833..0febb585e7bfd897e434d2f53a8db26f6d9c0a62 100644 (file)
@@ -10,6 +10,10 @@ if ($x) {}
 else if ($y) {}
 else if ($z) {}
 <strong>if</strong>;
+if  ($x) {}
+if
+
+($x) {}
 ~~~~~~~~~~
 warning:2:1
 warning:3:1
@@ -19,6 +23,8 @@ warning:6:1
 warning:7:1
 warning:7:6
 warning:8:1
+warning:13:3
+warning:14:3
 ~~~~~~~~~~
 <?php
 if ($x) {}
@@ -32,3 +38,5 @@ if ($x) {}
 else if ($y) {}
 else if ($z) {}
 <strong>if</strong>;
+if ($x) {}
+if ($x) {}