From af4ab07381a571c3649b805b6227252c96446751 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Tue, 13 Jan 2015 07:23:01 +1100 Subject: [PATCH] Improve lint handling of `declare()` special statement blocks 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 | 7 ++++++- .../linter/__tests__/xhpast/creative-brace-use.lint-test | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php index 2e2ec066..9ea60505 100644 --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -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, diff --git a/src/lint/linter/__tests__/xhpast/creative-brace-use.lint-test b/src/lint/linter/__tests__/xhpast/creative-brace-use.lint-test index 7d010c6c..969417cc 100644 --- a/src/lint/linter/__tests__/xhpast/creative-brace-use.lint-test +++ b/src/lint/linter/__tests__/xhpast/creative-brace-use.lint-test @@ -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);