mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-02-17 01:08: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;
|
const LINT_UNSAFE_DYNAMIC_STRING = 4;
|
||||||
|
|
||||||
private $xhpastLinter;
|
private $xhpastLinter;
|
||||||
|
private $deprecatedFunctions = array();
|
||||||
|
private $dynamicStringFunctions = array();
|
||||||
|
private $dynamicStringClasses = array();
|
||||||
|
|
||||||
public function setXHPASTLinter(ArcanistXHPASTLinter $linter) {
|
public function setXHPASTLinter(ArcanistXHPASTLinter $linter) {
|
||||||
$this->xhpastLinter = $linter;
|
$this->xhpastLinter = $linter;
|
||||||
return $this;
|
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) {
|
public function setEngine(ArcanistLintEngine $engine) {
|
||||||
if (!$this->xhpastLinter) {
|
if (!$this->xhpastLinter) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
|
@ -99,7 +117,7 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
|
|
||||||
|
|
||||||
private function lintUnsafeDynamicString($root) {
|
private function lintUnsafeDynamicString($root) {
|
||||||
$safe = array(
|
$safe = $this->dynamicStringFunctions + array(
|
||||||
'hsprintf' => 0,
|
'hsprintf' => 0,
|
||||||
|
|
||||||
'csprintf' => 0,
|
'csprintf' => 0,
|
||||||
|
@ -120,8 +138,8 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
$calls = $root->selectDescendantsOfType('n_FUNCTION_CALL');
|
$calls = $root->selectDescendantsOfType('n_FUNCTION_CALL');
|
||||||
$this->lintUnsafeDynamicStringCall($calls, $safe);
|
$this->lintUnsafeDynamicStringCall($calls, $safe);
|
||||||
|
|
||||||
$safe = array(
|
$safe = $this->dynamicStringClasses + array(
|
||||||
'execfuture' => 0,
|
'ExecFuture' => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
$news = $root->selectDescendantsOfType('n_NEW');
|
$news = $root->selectDescendantsOfType('n_NEW');
|
||||||
|
@ -132,6 +150,10 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
AASTNodeList $calls,
|
AASTNodeList $calls,
|
||||||
array $safe) {
|
array $safe) {
|
||||||
|
|
||||||
|
$safe = array_combine(
|
||||||
|
array_map('strtolower', array_keys($safe)),
|
||||||
|
$safe);
|
||||||
|
|
||||||
foreach ($calls as $call) {
|
foreach ($calls as $call) {
|
||||||
$name = $call->getChildByIndex(0)->getConcreteString();
|
$name = $call->getChildByIndex(0)->getConcreteString();
|
||||||
$param = idx($safe, strtolower($name));
|
$param = idx($safe, strtolower($name));
|
||||||
|
@ -183,25 +205,10 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function lintDeprecatedFunctions($root) {
|
private function lintDeprecatedFunctions($root) {
|
||||||
$map = array(
|
$map = $this->deprecatedFunctions + array(
|
||||||
// Silly; for unit testing.
|
|
||||||
'deprecated_function' => 'This function is most likely deprecated.',
|
|
||||||
|
|
||||||
'phutil_render_tag' =>
|
'phutil_render_tag' =>
|
||||||
'The phutil_render_tag() function is deprecated and unsafe. '.
|
'The phutil_render_tag() function is deprecated and unsafe. '.
|
||||||
'Use phutil_tag() instead.',
|
'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');
|
$function_calls = $root->selectDescendantsOfType('n_FUNCTION_CALL');
|
||||||
|
|
|
@ -9,6 +9,9 @@ final class ArcanistPhutilXHPASTLinterTestCase
|
||||||
public function testPhutilXHPASTLint() {
|
public function testPhutilXHPASTLint() {
|
||||||
$linter = new ArcanistPhutilXHPASTLinter();
|
$linter = new ArcanistPhutilXHPASTLinter();
|
||||||
$linter->setXHPASTLinter(new ArcanistXHPASTLinter());
|
$linter->setXHPASTLinter(new ArcanistXHPASTLinter());
|
||||||
|
$linter->setDeprecatedFunctions(array(
|
||||||
|
'deprecated_function' => 'This function is most likely deprecated.',
|
||||||
|
));
|
||||||
|
|
||||||
$working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
|
$working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
|
||||||
return $this->executeTestsInDirectory(
|
return $this->executeTestsInDirectory(
|
||||||
|
|
Loading…
Add table
Reference in a new issue