1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-10 08:52:39 +01:00

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
This commit is contained in:
vrana 2012-09-13 11:19:25 -07:00
parent a5e2f81928
commit 7ee0f3e3b3
2 changed files with 16 additions and 1 deletions

View file

@ -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);
}

View file

@ -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
disabled:8:1
disabled:10:1