Page MenuHomePhabricator

D12422.id29830.diff
No OneTemporary

D12422.id29830.diff

diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php
--- a/src/lint/linter/ArcanistXHPASTLinter.php
+++ b/src/lint/linter/ArcanistXHPASTLinter.php
@@ -59,6 +59,7 @@
const LINT_SELF_MEMBER_REFERENCE = 57;
const LINT_LOGICAL_OPERATORS = 58;
const LINT_INNER_FUNCTION = 59;
+ const LINT_ALIAS_FUNCTION = 60;
private $blacklistedFunctions = array();
private $naminghook;
@@ -185,6 +186,8 @@
=> pht('Logical Operators'),
self::LINT_INNER_FUNCTION
=> pht('Inner Functions'),
+ self::LINT_ALIAS_FUNCTION
+ => pht('Alias Functions'),
);
}
@@ -232,6 +235,7 @@
self::LINT_SELF_MEMBER_REFERENCE => $advice,
self::LINT_LOGICAL_OPERATORS => $advice,
self::LINT_INNER_FUNCTION => $warning,
+ self::LINT_ALIAS_FUNCTION => $advice,
);
}
@@ -299,7 +303,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '22';
+ return '23';
}
protected function resolveFuture($path, Future $future) {
@@ -385,6 +389,7 @@
'lintSelfMemberReference' => self::LINT_SELF_MEMBER_REFERENCE,
'lintLogicalOperators' => self::LINT_LOGICAL_OPERATORS,
'lintInnerFunctions' => self::LINT_INNER_FUNCTION,
+ 'lintAliasFunctions' => self::LINT_ALIAS_FUNCTION,
);
foreach ($method_codes as $method => $codes) {
@@ -3650,6 +3655,29 @@
}
}
+ private function lintAliasFunctions(XHPASTNode $root) {
+ static $aliases = array(
+ 'chop' => 'rtrim',
+ 'join' => 'implode',
+ 'key_exists' => 'array_key_exists',
+ 'delete' => 'unset',
+ 'sizeof' => 'count',
+ 'strchr' => 'strstr',
+ );
+
+ $functions = $this->getFunctionCalls($root, array_keys($aliases));
+
+ foreach ($functions as $function) {
+ $function_name = $function->getChildByIndex(0);
+
+ $this->raiseLintAtNode(
+ $function_name,
+ self::LINT_ALIAS_FUNCTION,
+ pht('Alias functions should be avoided.'),
+ $aliases[$function_name->getConcreteString()]);
+ }
+ }
+
/**
* Retrieve all calls to some specified function(s).
*
diff --git a/src/lint/linter/__tests__/xhpast/alias-functions.lint-test b/src/lint/linter/__tests__/xhpast/alias-functions.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/alias-functions.lint-test
@@ -0,0 +1,14 @@
+<?php
+
+$x = array();
+sizeof($x);
+delete($x);
+~~~~~~~~~~
+advice:4:1
+advice:5:1
+~~~~~~~~~~
+<?php
+
+$x = array();
+count($x);
+unset($x);

File Metadata

Mime Type
text/plain
Expires
Sat, Jan 25, 2:39 AM (2 h, 11 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7045987
Default Alt Text
D12422.id29830.diff (2 KB)

Event Timeline