]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Lint short ternary as PHP 5.3 feature
authorvrana <jakubv@fb.com>
Thu, 13 Sep 2012 18:19:25 +0000 (11:19 -0700)
committervrana <jakubv@fb.com>
Thu, 13 Sep 2012 18:24:32 +0000 (11:24 -0700)
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
src/lint/linter/__tests__/xhpast/php53.lint-test

index 07b6bc2eecfd72416e850e8fc66e58fa9cea2ca6..5b0a4eeb906d07cc23b32a45b1f02c2cffe4d575 100644 (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);
   }
 
index cfe8254a80d747aa4a06c7ee4d2897af1b847f18..166e06e798fdea45ac4826b9d5cfad6d22a3ed2d 100644 (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
\ No newline at end of file
+disabled:8:1
+disabled:10:1
\ No newline at end of file