]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow configuring PhutilXHPAST linter
authorvrana <jakubv@fb.com>
Sun, 10 Feb 2013 14:35:25 +0000 (06:35 -0800)
committervrana <jakubv@fb.com>
Mon, 11 Feb 2013 18:41:26 +0000 (10:41 -0800)
Summary: Also move Phabricator stuff outside.

Test Plan: Updated unit test.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D4894

src/lint/linter/ArcanistPhutilXHPASTLinter.php
src/lint/linter/__tests__/ArcanistPhutilXHPASTLinterTestCase.php

index 9a0e9d47ba4d89a2ac74e21f14ddd9967922c948..636c836c719a773f6c8bb2de3d14015ca65fc215 100644 (file)
@@ -11,12 +11,30 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
   const LINT_UNSAFE_DYNAMIC_STRING   = 4;
 
   private $xhpastLinter;
+  private $deprecatedFunctions = array();
+  private $dynamicStringFunctions = array();
+  private $dynamicStringClasses = array();
 
   public function setXHPASTLinter(ArcanistXHPASTLinter $linter) {
     $this->xhpastLinter = $linter;
     return $this;
   }
 
+  public function setDeprecatedFunctions($map) {
+    $this->deprecatedFunctions = $map;
+    return $this;
+  }
+
+  public function setDynamicStringFunctions($map) {
+    $this->dynamicStringFunctions = $map;
+    return $this;
+  }
+
+  public function setDynamicStringClasses($map) {
+    $this->dynamicStringClasses = $map;
+    return $this;
+  }
+
   public function setEngine(ArcanistLintEngine $engine) {
     if (!$this->xhpastLinter) {
       throw new Exception(
@@ -99,7 +117,7 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
 
 
   private function lintUnsafeDynamicString($root) {
-    $safe = array(
+    $safe = $this->dynamicStringFunctions + array(
       'hsprintf' => 0,
 
       'csprintf' => 0,
@@ -120,8 +138,8 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
     $calls = $root->selectDescendantsOfType('n_FUNCTION_CALL');
     $this->lintUnsafeDynamicStringCall($calls, $safe);
 
-    $safe = array(
-      'execfuture' => 0,
+    $safe = $this->dynamicStringClasses + array(
+      'ExecFuture' => 0,
     );
 
     $news = $root->selectDescendantsOfType('n_NEW');
@@ -132,6 +150,10 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
     AASTNodeList $calls,
     array $safe) {
 
+    $safe = array_combine(
+      array_map('strtolower', array_keys($safe)),
+      $safe);
+
     foreach ($calls as $call) {
       $name = $call->getChildByIndex(0)->getConcreteString();
       $param = idx($safe, strtolower($name));
@@ -183,25 +205,10 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
   }
 
   private function lintDeprecatedFunctions($root) {
-    $map = array(
-      // Silly; for unit testing.
-      'deprecated_function' => 'This function is most likely deprecated.',
-
+    $map = $this->deprecatedFunctions + array(
       'phutil_render_tag' =>
         'The phutil_render_tag() function is deprecated and unsafe. '.
         'Use phutil_tag() instead.',
-
-      'javelin_render_tag' =>
-        'The javelin_render_tag() function is deprecated and unsafe. '.
-        'Use javelin_tag() instead.',
-
-      'phabricator_render_form' =>
-        'The phabricator_render_form() function is deprecated and unsafe. '.
-        'Use phabricator_form() instead.',
-
-      'phutil_escape_html' =>
-        'The phutil_escape_html() function is deprecated. Raw strings passed '.
-        'to phutil_tag() or hsprintf() are escaped automatically.',
     );
 
     $function_calls = $root->selectDescendantsOfType('n_FUNCTION_CALL');
index 4f42f825c2187f028389ceac092d9f964e0444b9..01c9fa459efaca22fa6efbebcc520f70fb5250c7 100644 (file)
@@ -9,6 +9,9 @@ final class ArcanistPhutilXHPASTLinterTestCase
   public function testPhutilXHPASTLint() {
     $linter = new ArcanistPhutilXHPASTLinter();
     $linter->setXHPASTLinter(new ArcanistXHPASTLinter());
+    $linter->setDeprecatedFunctions(array(
+      'deprecated_function' => 'This function is most likely deprecated.',
+    ));
 
     $working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
     return $this->executeTestsInDirectory(