Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13979843
D14517.id35117.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D14517.id35117.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -346,6 +346,8 @@
'ArcanistUpgradeWorkflow' => 'workflow/ArcanistUpgradeWorkflow.php',
'ArcanistUploadWorkflow' => 'workflow/ArcanistUploadWorkflow.php',
'ArcanistUsageException' => 'exception/ArcanistUsageException.php',
+ 'ArcanistUseStatementNamespacePrefixXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistUseStatementNamespacePrefixXHPASTLinterRule.php',
+ 'ArcanistUseStatementNamespacePrefixXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistUseStatementNamespacePrefixXHPASTLinterRuleTestCase.php',
'ArcanistUselessOverridingMethodXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistUselessOverridingMethodXHPASTLinterRule.php',
'ArcanistUselessOverridingMethodXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistUselessOverridingMethodXHPASTLinterRuleTestCase.php',
'ArcanistUserAbortException' => 'exception/usage/ArcanistUserAbortException.php',
@@ -718,6 +720,8 @@
'ArcanistUpgradeWorkflow' => 'ArcanistWorkflow',
'ArcanistUploadWorkflow' => 'ArcanistWorkflow',
'ArcanistUsageException' => 'Exception',
+ 'ArcanistUseStatementNamespacePrefixXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
+ 'ArcanistUseStatementNamespacePrefixXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistUselessOverridingMethodXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistUselessOverridingMethodXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistUserAbortException' => 'ArcanistUsageException',
diff --git a/src/lint/linter/xhpast/rules/ArcanistUseStatementNamespacePrefixXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistUseStatementNamespacePrefixXHPASTLinterRule.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/ArcanistUseStatementNamespacePrefixXHPASTLinterRule.php
@@ -0,0 +1,38 @@
+<?php
+
+final class ArcanistUseStatementNamespacePrefixXHPASTLinterRule
+ extends ArcanistXHPASTLinterRule {
+
+ const ID = 93;
+
+ public function getLintName() {
+ return pht('`%s` Statement Namespace Prefix', 'use');
+ }
+
+ public function getLintSeverity() {
+ return ArcanistLintSeverity::SEVERITY_WARNING;
+ }
+
+ public function process(XHPASTNode $root) {
+ $use_lists = $root->selectDescendantsOfType('n_USE_LIST');
+
+ foreach ($use_lists as $use_list) {
+ $uses = $use_list->selectDescendantsOfType('n_USE');
+
+ foreach ($uses as $use) {
+ $symbol = $use->getChildOfType(0, 'n_SYMBOL_NAME');
+ $symbol_name = $symbol->getConcreteString();
+
+ if ($symbol_name[0] == '\\') {
+ $this->raiseLintAtNode(
+ $symbol,
+ pht(
+ 'Imported symbols should not be prefixed with `%s`.',
+ '\\'),
+ substr($symbol_name, 1));
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/lint/linter/xhpast/rules/__tests__/ArcanistUseStatementNamespacePrefixXHPASTLinterRuleTestCase.php b/src/lint/linter/xhpast/rules/__tests__/ArcanistUseStatementNamespacePrefixXHPASTLinterRuleTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/ArcanistUseStatementNamespacePrefixXHPASTLinterRuleTestCase.php
@@ -0,0 +1,11 @@
+<?php
+
+final class ArcanistUseStatementNamespacePrefixXHPASTLinterRuleTestCase
+ extends ArcanistXHPASTLinterRuleTestCase {
+
+ public function testLinter() {
+ $this->executeTestsInDirectory(
+ dirname(__FILE__).'/use-statement-namespace-prefix/');
+ }
+
+}
diff --git a/src/lint/linter/xhpast/rules/__tests__/use-statement-namespace-prefix/use.lint-test b/src/lint/linter/xhpast/rules/__tests__/use-statement-namespace-prefix/use.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/rules/__tests__/use-statement-namespace-prefix/use.lint-test
@@ -0,0 +1,11 @@
+<?php
+namespace SomeNamespace;
+use X\Y\Z;
+use \X\Y\Z;
+~~~~~~~~~~
+warning:4:5
+~~~~~~~~~~
+<?php
+namespace SomeNamespace;
+use X\Y\Z;
+use X\Y\Z;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Oct 20, 6:52 AM (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6735545
Default Alt Text
D14517.id35117.diff (4 KB)
Attached To
Mode
D14517: Add a linter rule for `use` statement namespace prefixes
Attached
Detach File
Event Timeline
Log In to Comment