From 6b22184712917169e5fd7d500f3e500d07420504 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 4 Jan 2012 10:59:00 -0800 Subject: [PATCH] Make XHPAST linter correct too much space after control keywords like "if" 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 | 11 ++++++++++- .../data/space-after-control-keywords.lint-test | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/lint/linter/xhpast/ArcanistXHPASTLinter.php b/src/lint/linter/xhpast/ArcanistXHPASTLinter.php index 28b26811..c552a32c 100644 --- a/src/lint/linter/xhpast/ArcanistXHPASTLinter.php +++ b/src/lint/linter/xhpast/ArcanistXHPASTLinter.php @@ -1,7 +1,7 @@ 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; } diff --git a/src/lint/linter/xhpast/__tests__/data/space-after-control-keywords.lint-test b/src/lint/linter/xhpast/__tests__/data/space-after-control-keywords.lint-test index 2d0a21a0..0febb585 100644 --- a/src/lint/linter/xhpast/__tests__/data/space-after-control-keywords.lint-test +++ b/src/lint/linter/xhpast/__tests__/data/space-after-control-keywords.lint-test @@ -10,6 +10,10 @@ if ($x) {} else if ($y) {} else if ($z) {} if; +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 ~~~~~~~~~~ if; +if ($x) {} +if ($x) {} -- 2.43.0