]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add lint warnings about use of phutil_render_tag and javelin_render_tag
authorepriestley <git@epriestley.com>
Sat, 9 Feb 2013 01:38:56 +0000 (17:38 -0800)
committerepriestley <git@epriestley.com>
Sat, 9 Feb 2013 01:38:56 +0000 (17:38 -0800)
Summary: Raise deprecation warnings for these methods. I won't commit this until the phutil_tag branch merges.

Test Plan: Unit tests.

Reviewers: vrana

Reviewed By: vrana

CC: aran
Maniphest Tasks: T2432

Differential Revision: https://secure.phabricator.com/D4770

src/lint/linter/ArcanistPhutilXHPASTLinter.php
src/lint/linter/__tests__/phlxhp/deprecated-function.lint-test [new file with mode: 0644]

index 5c8b91e762dcf999d00ee948fa4a6972b34dffdb..1a50300a66a271a132d1839556f714a754e349d1 100644 (file)
@@ -7,6 +7,7 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
 
   const LINT_PHT_WITH_DYNAMIC_STRING = 1;
   const LINT_ARRAY_COMBINE           = 2;
+  const LINT_DEPRECATED_FUNCTION     = 3;
   const LINT_UNSAFE_DYNAMIC_STRING   = 4;
 
   private $xhpastLinter;
@@ -29,15 +30,16 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
     return array(
       self::LINT_PHT_WITH_DYNAMIC_STRING => 'Use of pht() on Dynamic String',
       self::LINT_ARRAY_COMBINE           => 'array_combine() Unreliable',
+      self::LINT_DEPRECATED_FUNCTION     => 'Use of deprecated function',
       self::LINT_UNSAFE_DYNAMIC_STRING   => 'Unsafe Usage of Dynamic String',
     );
   }
 
   public function getLintSeverityMap() {
     $warning = ArcanistLintSeverity::SEVERITY_WARNING;
-
     return array(
       self::LINT_ARRAY_COMBINE           => $warning,
+      self::LINT_DEPRECATED_FUNCTION     => $warning,
       self::LINT_UNSAFE_DYNAMIC_STRING   => $warning,
     );
   }
@@ -47,7 +49,7 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
   }
 
   public function getCacheVersion() {
-    return 1;
+    return 2;
   }
 
   public function willLintPaths(array $paths) {
@@ -65,6 +67,7 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
     $this->lintPHT($root);
     $this->lintArrayCombine($root);
     $this->lintUnsafeDynamicString($root);
+    $this->lintDeprecatedFunctions($root);
   }
 
 
@@ -179,4 +182,38 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
     }
   }
 
+  private function lintDeprecatedFunctions($root) {
+    $map = array(
+      // Silly; for unit testing.
+      'deprecated_function' => 'This function is most likely deprecated.',
+
+      '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.',
+    );
+
+    $function_calls = $root->selectDescendantsOfType('n_FUNCTION_CALL');
+    foreach ($function_calls as $call) {
+      $name = $call->getChildByIndex(0)->getConcreteString();
+
+      $name = strtolower($name);
+      if (empty($map[$name])) {
+        continue;
+      }
+
+      $this->raiseLintAtNode(
+        $call,
+        self::LINT_DEPRECATED_FUNCTION,
+        $map[$name]);
+    }
+  }
+
 }
diff --git a/src/lint/linter/__tests__/phlxhp/deprecated-function.lint-test b/src/lint/linter/__tests__/phlxhp/deprecated-function.lint-test
new file mode 100644 (file)
index 0000000..f993c0a
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+
+deprecated_function();
+modern_function();
+~~~~~~~~~~
+warning:3:1
\ No newline at end of file