]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve lint handling of `declare()` special statement blocks
authorJoshua Spence <josh@joshuaspence.com>
Mon, 12 Jan 2015 20:23:01 +0000 (07:23 +1100)
committerJoshua Spence <josh@joshuaspence.com>
Mon, 12 Jan 2015 20:23:01 +0000 (07:23 +1100)
Summary: Fixes T6830. Don't require `n_STATEMENT` nested under `n_DECLARE` to be written using braces.

Test Plan: Added a test case.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T6830

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

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

index 2e2ec06645bdcfe8e033cd75a7f83d478530560c..9ea605051fda46781902bdd5869b7c67875a85a7 100644 (file)
@@ -974,7 +974,12 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
     foreach ($nodes as $node) {
       $parent = $node->getParentNode();
 
-      if ($parent && $parent->getTypeName() != 'n_STATEMENT_LIST') {
+      if (!$parent) {
+        continue;
+      }
+
+      $type = $parent->getTypeName();
+      if ($type != 'n_STATEMENT_LIST' && $type != 'n_DECLARE') {
         $this->raiseLintAtNode(
             $node,
             self::LINT_BRACE_FORMATTING,
index 7d010c6cb2ec086d49b82505c2ead898d43c6678..969417cc64d382051b1fda023b852f5d016fbc6b 100644 (file)
@@ -34,6 +34,8 @@ do baz(); while ($x);
 if ($x) {}
 else if ($y) {}
 else {}
+
+declare(ticks = 1);
 ~~~~~~~~~~
 advice:3:14
 warning:7:13
@@ -74,3 +76,5 @@ else bar();
 do baz(); while ($x);
 
 if ($x) {} else if ($y) {} else {}
+
+declare(ticks = 1);