From 7ee0f3e3b31cdec790d0b0025d895d0123d43334 Mon Sep 17 00:00:00 2001 From: vrana Date: Thu, 13 Sep 2012 11:19:25 -0700 Subject: [PATCH] Lint short ternary as PHP 5.3 feature Summary: I don't offer a replacement because `f() ?: 1` converted to `f() ? f() : 1` can cause side effects and whitespace issues. Test Plan: New test. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3489 --- src/lint/linter/ArcanistXHPASTLinter.php | 12 ++++++++++++ src/lint/linter/__tests__/xhpast/php53.lint-test | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php index 07b6bc2e..5b0a4eeb 100644 --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -404,6 +404,18 @@ final class ArcanistXHPASTLinter extends ArcanistLinter { } } + $ternaries = $root->selectDescendantsOfType('n_TERNARY_EXPRESSION'); + foreach ($ternaries as $ternary) { + $yes = $ternary->getChildByIndex(1); + if ($yes->getTypeName() == 'n_EMPTY') { + $this->raiseLintAtNode( + $ternary, + self::LINT_PHP_53_FEATURES, + 'This codebase targets PHP 5.2, but short ternary was not '. + 'introduced until PHP 5.3.'); + } + } + $this->lintPHP53Functions($root); } diff --git a/src/lint/linter/__tests__/xhpast/php53.lint-test b/src/lint/linter/__tests__/xhpast/php53.lint-test index cfe8254a..166e06e7 100644 --- a/src/lint/linter/__tests__/xhpast/php53.lint-test +++ b/src/lint/linter/__tests__/xhpast/php53.lint-test @@ -6,10 +6,13 @@ f(function() {}); g(function() use ($c) {}); h(function /* ! */ () use ($c) {}); static::m(); +1 ? 1 : 2; +1 ?: 2; ~~~~~~~~~~ disabled:3:1 disabled:4:5 disabled:5:3 disabled:6:3 disabled:7:3 -disabled:8:1 \ No newline at end of file +disabled:8:1 +disabled:10:1 \ No newline at end of file -- 2.43.0