Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14775176
D12422.id29830.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D12422.id29830.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D12422: Add a linter rule for alias functions
Attached
Detach File
Event Timeline
Log In to Comment