Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14775023
D12377.id30021.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
D12377.id30021.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
@@ -60,6 +60,7 @@
const LINT_LOGICAL_OPERATORS = 58;
const LINT_INNER_FUNCTION = 59;
const LINT_DEFAULT_PARAMETERS = 60;
+ const LINT_LOWERCASE_FUNCTIONS = 61;
private $blacklistedFunctions = array();
private $naminghook;
@@ -188,6 +189,8 @@
=> pht('Inner Functions'),
self::LINT_DEFAULT_PARAMETERS
=> pht('Default Parameters'),
+ self::LINT_LOWERCASE_FUNCTIONS
+ => pht('Lowercase Functions'),
);
}
@@ -236,6 +239,7 @@
self::LINT_LOGICAL_OPERATORS => $advice,
self::LINT_INNER_FUNCTION => $warning,
self::LINT_DEFAULT_PARAMETERS => $warning,
+ self::LINT_LOWERCASE_FUNCTIONS => $advice,
);
}
@@ -303,7 +307,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '23';
+ return '24';
}
protected function resolveFuture($path, Future $future) {
@@ -390,6 +394,7 @@
'lintLogicalOperators' => self::LINT_LOGICAL_OPERATORS,
'lintInnerFunctions' => self::LINT_INNER_FUNCTION,
'lintDefaultParameters' => self::LINT_DEFAULT_PARAMETERS,
+ 'lintLowercaseFunctions' => self::LINT_LOWERCASE_FUNCTIONS,
);
foreach ($method_codes as $method => $codes) {
@@ -3681,6 +3686,39 @@
}
}
+ private function lintLowercaseFunctions(XHPASTNode $root) {
+ static $builtin_functions = null;
+
+ if ($builtin_functions === null) {
+ $builtin_functions = array_fuse(
+ idx(get_defined_functions(), 'internal', array()));
+ }
+
+ $function_calls = $root->selectDescendantsOfType('n_FUNCTION_CALL');
+
+ foreach ($function_calls as $function_call) {
+ $function = $function_call->getChildByIndex(0);
+
+ if ($function->getTypeName() != 'n_SYMBOL_NAME') {
+ continue;
+ }
+
+ $function_name = $function->getConcreteString();
+
+ if (!idx($builtin_functions, strtolower($function_name))) {
+ continue;
+ }
+
+ if ($function_name != strtolower($function_name)) {
+ $this->raiseLintAtNode(
+ $function,
+ self::LINT_LOWERCASE_FUNCTIONS,
+ pht('Calls to built-in PHP functions should be lowercase.'),
+ strtolower($function_name));
+ }
+ }
+ }
+
/**
* Retrieve all calls to some specified function(s).
*
diff --git a/src/lint/linter/__tests__/xhpast/lowercase-functions.lint-test b/src/lint/linter/__tests__/xhpast/lowercase-functions.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/lowercase-functions.lint-test
@@ -0,0 +1,9 @@
+<?php
+var_dump('');
+Var_Dump('');
+~~~~~~~~~~
+advice:3:1
+~~~~~~~~~~
+<?php
+var_dump('');
+var_dump('');
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 25, 2:29 AM (2 h, 46 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7045925
Default Alt Text
D12377.id30021.diff (2 KB)
Attached To
Mode
D12377: Add a linter rule for lowercase function names
Attached
Detach File
Event Timeline
Log In to Comment