From: vrana Date: Thu, 13 Sep 2012 18:19:25 +0000 (-0700) Subject: Lint short ternary as PHP 5.3 feature X-Git-Tag: conduit-6~126 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=7ee0f3e3b31cdec790d0b0025d895d0123d43334;p=arcanist.git 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 --- 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