'linter is intended for use in Phabricator libraries and extensions.');
}
- public function setDeprecatedFunctions(array $map) {
- $this->deprecatedFunctions = $map;
- return $this;
- }
-
- public function setDynamicStringFunctions(array $map) {
- $this->dynamicStringFunctions = $map;
- return $this;
- }
-
- public function setDynamicStringClasses(array $map) {
- $this->dynamicStringClasses = $map;
- return $this;
- }
-
public function getLintNameMap() {
return array(
self::LINT_ARRAY_COMBINE => pht(
);
}
- 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,
- self::LINT_RAGGED_CLASSTREE_EDGE => $warning,
- );
- }
-
public function getLinterName() {
return 'PHLXHP';
}
return 'phutil-xhpast';
}
- public function getVersion() {
- // The version number should be incremented whenever a new rule is added.
- return '3';
+ 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,
+ self::LINT_RAGGED_CLASSTREE_EDGE => $warning,
+ );
}
public function getLinterConfigurationOptions() {
case 'phutil-xhpast.dynamic-string.classes':
$this->setDynamicStringClasses($value);
return;
+ default:
+ parent::setLinterConfigurationValue($key, $value);
+ return;
}
+ }
- return parent::setLinterConfigurationValue($key, $value);
+ public function getVersion() {
+ // The version number should be incremented whenever a new rule is added.
+ return '3';
}
protected function resolveFuture($path, Future $future) {
}
}
+
+/* -( Setters )------------------------------------------------------------ */
+
+ public function setDeprecatedFunctions(array $map) {
+ $this->deprecatedFunctions = $map;
+ return $this;
+ }
+
+ public function setDynamicStringClasses(array $map) {
+ $this->dynamicStringClasses = $map;
+ return $this;
+ }
+
+ public function setDynamicStringFunctions(array $map) {
+ $this->dynamicStringFunctions = $map;
+ return $this;
+ }
+
+
+/* -( Linter Rules )------------------------------------------------------- */
+
private function lintUnsafeDynamicString(XHPASTNode $root) {
$safe = $this->dynamicStringFunctions + array(
'pht' => 0,
}
private function lintArrayCombine(XHPASTNode $root) {
- $function_calls = $root->selectDescendantsOfType('n_FUNCTION_CALL');
+ $function_calls = $this->getFunctionCalls($root, array('array_combine'));
+
foreach ($function_calls as $call) {
$name = $call->getChildByIndex(0)->getConcreteString();
- if (strcasecmp($name, 'array_combine') == 0) {
- $parameter_list = $call->getChildOfType(1, 'n_CALL_PARAMETER_LIST');
- if (count($parameter_list->getChildren()) !== 2) {
- // Wrong number of parameters, but raise that elsewhere if we want.
- continue;
- }
+ $parameter_list = $call->getChildOfType(1, 'n_CALL_PARAMETER_LIST');
- $first = $parameter_list->getChildByIndex(0);
- $second = $parameter_list->getChildByIndex(1);
-
- if ($first->getConcreteString() == $second->getConcreteString()) {
- $this->raiseLintAtNode(
- $call,
- self::LINT_ARRAY_COMBINE,
- pht(
- 'Prior to PHP 5.4, `%s` fails when given empty arrays. '.
- 'Prefer to write `%s` as `%s`.',
- 'array_combine()',
- 'array_combine(x, x)',
- 'array_fuse(x)'));
- }
+ if (count($parameter_list->getChildren()) !== 2) {
+ // Wrong number of parameters, but raise that elsewhere if we want.
+ continue;
+ }
+
+ $first = $parameter_list->getChildByIndex(0);
+ $second = $parameter_list->getChildByIndex(1);
+
+ if ($first->getConcreteString() == $second->getConcreteString()) {
+ $this->raiseLintAtNode(
+ $call,
+ self::LINT_ARRAY_COMBINE,
+ pht(
+ 'Prior to PHP 5.4, `%s` fails when given empty arrays. '.
+ 'Prefer to write `%s` as `%s`.',
+ 'array_combine()',
+ 'array_combine(x, x)',
+ 'array_fuse(x)'));
}
}
}
private function lintDeprecatedFunctions(XHPASTNode $root) {
$map = $this->deprecatedFunctions;
+ $function_calls = $this->getFunctionCalls($root, array_keys($map));
- $function_calls = $root->selectDescendantsOfType('n_FUNCTION_CALL');
foreach ($function_calls as $call) {
- $name = $call->getChildByIndex(0)->getConcreteString();
+ $name = $call
+ ->getChildByIndex(0)
+ ->getConcreteString();
$name = strtolower($name);
if (empty($map[$name])) {