diff --git a/src/lint/linter/ArcanistPhutilXHPASTLinter.php b/src/lint/linter/ArcanistPhutilXHPASTLinter.php index 5c8b91e7..1a50300a 100644 --- a/src/lint/linter/ArcanistPhutilXHPASTLinter.php +++ b/src/lint/linter/ArcanistPhutilXHPASTLinter.php @@ -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 index 00000000..f993c0a3 --- /dev/null +++ b/src/lint/linter/__tests__/phlxhp/deprecated-function.lint-test @@ -0,0 +1,6 @@ +