mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 14:52:40 +01:00
Allow configuring PhutilXHPAST linter
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
This commit is contained in:
parent
8b1215ffcf
commit
e1d906ea18
2 changed files with 29 additions and 19 deletions
|
@ -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');
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue