]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve brace formatting linter rule
authorJoshua Spence <josh@freelancer.com>
Mon, 7 Dec 2015 20:20:57 +0000 (20:20 +0000)
committerjoshuaspence <autocommitter@example.com>
Mon, 7 Dec 2015 20:20:57 +0000 (20:20 +0000)
Summary: Allow the brace formatting linter rule to complain about `class X{}`.

Test Plan: Updated unit tests.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

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

src/lint/linter/xhpast/rules/ArcanistBraceFormattingXHPASTLinterRule.php
src/lint/linter/xhpast/rules/__tests__/brace-formatting/brace-formatting.lint-test [deleted file]
src/lint/linter/xhpast/rules/__tests__/brace-formatting/class.lint-test [new file with mode: 0644]
src/lint/linter/xhpast/rules/__tests__/brace-formatting/control-statement.lint-test [new file with mode: 0644]
src/lint/linter/xhpast/rules/__tests__/brace-formatting/declare.lint-test [new file with mode: 0644]
src/lint/linter/xhpast/rules/__tests__/brace-formatting/function.lint-test [new file with mode: 0644]
src/lint/linter/xhpast/rules/__tests__/brace-formatting/try-catch.lint-test [new file with mode: 0644]

index 0a8c33b754117363fc3b22405beb4e32d54990f6..775c6f185177fbb2a2e7e05da2ca9b7f5d708150 100644 (file)
@@ -24,14 +24,6 @@ final class ArcanistBraceFormattingXHPASTLinterRule
       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,
           pht(
diff --git a/src/lint/linter/xhpast/rules/__tests__/brace-formatting/brace-formatting.lint-test b/src/lint/linter/xhpast/rules/__tests__/brace-formatting/brace-formatting.lint-test
deleted file mode 100644 (file)
index 725773f..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-<?php
-
-function f() {
-
-}
-
-function g()
-{
-
-}
-
-if (1)
-{}
-
-foreach (x() as $y)
-{}
-
-while (1)
-{}
-
-switch (1)
-{}
-
-try
-{}
-catch (Exception $x)
-{}
-
-function h(){}
-if ($x) foo();
-else bar();
-do baz(); while ($x);
-
-if ($x) {}
-else if ($y) {}
-else {}
-
-if ($x) {}else{}
-
-declare(ticks = 1);
-~~~~~~~~~~
-warning:7:13
-warning:12:7
-warning:15:20
-warning:18:10
-warning:21:11
-warning:24:4
-warning:26:21
-warning:29:13
-warning:30:9
-warning:31:6
-warning:32:4
-warning:34:11
-warning:35:16
-warning:38:11
-~~~~~~~~~~
-<?php
-
-function f() {
-
-}
-
-function g() {
-
-}
-
-if (1) {}
-
-foreach (x() as $y) {}
-
-while (1) {}
-
-switch (1) {}
-
-try {}
-catch (Exception $x) {}
-
-function h() {}
-if ($x) foo();
-else bar();
-do baz(); while ($x);
-
-if ($x) {} else if ($y) {} else {}
-
-if ($x) {} else{}
-
-declare(ticks = 1);
diff --git a/src/lint/linter/xhpast/rules/__tests__/brace-formatting/class.lint-test b/src/lint/linter/xhpast/rules/__tests__/brace-formatting/class.lint-test
new file mode 100644 (file)
index 0000000..37c94ec
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+
+class SomeClass {}
+class SomeOtherClass{}
+class YetAnotherClass extends SomeClass{}
+~~~~~~~~~~
+warning:4:21
+warning:5:40
+~~~~~~~~~~
+<?php
+
+class SomeClass {}
+class SomeOtherClass {}
+class YetAnotherClass extends SomeClass {}
diff --git a/src/lint/linter/xhpast/rules/__tests__/brace-formatting/control-statement.lint-test b/src/lint/linter/xhpast/rules/__tests__/brace-formatting/control-statement.lint-test
new file mode 100644 (file)
index 0000000..2454529
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+if (1)
+{}
+
+foreach (x() as $y)
+{}
+
+while (1)
+{}
+
+switch (1)
+{}
+
+if ($x) foo();
+else bar();
+do baz(); while ($x);
+
+if ($x) {}
+else if ($y) {}
+else {}
+
+if ($x) {}else{}
+~~~~~~~~~~
+warning:3:7
+warning:6:20
+warning:9:10
+warning:12:11
+warning:15:9
+warning:16:6
+warning:17:4
+warning:19:11
+warning:20:16
+warning:23:11
+warning:23:15
+~~~~~~~~~~
+<?php
+
+if (1) {}
+
+foreach (x() as $y) {}
+
+while (1) {}
+
+switch (1) {}
+
+if ($x) foo();
+else bar();
+do baz(); while ($x);
+
+if ($x) {} else if ($y) {} else {}
+
+if ($x) {} else {}
diff --git a/src/lint/linter/xhpast/rules/__tests__/brace-formatting/declare.lint-test b/src/lint/linter/xhpast/rules/__tests__/brace-formatting/declare.lint-test
new file mode 100644 (file)
index 0000000..da2694d
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+
+declare(ticks = 1);
+~~~~~~~~~~
diff --git a/src/lint/linter/xhpast/rules/__tests__/brace-formatting/function.lint-test b/src/lint/linter/xhpast/rules/__tests__/brace-formatting/function.lint-test
new file mode 100644 (file)
index 0000000..46ee807
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+function f() {
+
+}
+
+function g()
+{
+
+}
+
+function h(){}
+~~~~~~~~~~
+warning:7:13
+warning:12:13
+~~~~~~~~~~
+<?php
+
+function f() {
+
+}
+
+function g() {
+
+}
+
+function h() {}
diff --git a/src/lint/linter/xhpast/rules/__tests__/brace-formatting/try-catch.lint-test b/src/lint/linter/xhpast/rules/__tests__/brace-formatting/try-catch.lint-test
new file mode 100644 (file)
index 0000000..7b3f149
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+
+try
+{}
+catch (Exception $x)
+{}
+~~~~~~~~~~
+warning:3:4
+warning:5:21
+~~~~~~~~~~
+<?php
+
+try {}
+catch (Exception $x) {}