Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14874753
D13274.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D13274.id.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
@@ -261,6 +261,7 @@
'ArcanistXHPASTLintSwitchHook' => 'lint/linter/xhpast/ArcanistXHPASTLintSwitchHook.php',
'ArcanistXHPASTLinter' => 'lint/linter/ArcanistXHPASTLinter.php',
'ArcanistXHPASTLinterRule' => 'lint/linter/xhpast/ArcanistXHPASTLinterRule.php',
+ 'ArcanistXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/__tests__/ArcanistXHPASTLinterRuleTestCase.php',
'ArcanistXHPASTLinterTestCase' => 'lint/linter/__tests__/ArcanistXHPASTLinterTestCase.php',
'ArcanistXMLLinter' => 'lint/linter/ArcanistXMLLinter.php',
'ArcanistXMLLinterTestCase' => 'lint/linter/__tests__/ArcanistXMLLinterTestCase.php',
@@ -533,6 +534,7 @@
'ArcanistXHPASTLintSwitchHook' => 'Phobject',
'ArcanistXHPASTLinter' => 'ArcanistBaseXHPASTLinter',
'ArcanistXHPASTLinterRule' => 'Phobject',
+ 'ArcanistXHPASTLinterRuleTestCase' => 'PhutilTestCase',
'ArcanistXHPASTLinterTestCase' => 'ArcanistLinterTestCase',
'ArcanistXMLLinter' => 'ArcanistLinter',
'ArcanistXMLLinterTestCase' => 'ArcanistLinterTestCase',
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
@@ -8,7 +8,7 @@
private $rules = array();
public function __construct() {
- $this->rules = $this->getLinterRules();
+ $this->rules = ArcanistXHPASTLinterRule::loadAllRules();
}
public function __clone() {
@@ -66,32 +66,6 @@
return count($this->rules);
}
- public function getLinterRules() {
- $rules = array();
-
- $symbols = id(new PhutilSymbolLoader())
- ->setAncestorClass('ArcanistXHPASTLinterRule')
- ->loadObjects();
-
- foreach ($symbols as $class => $rule) {
- $id = $rule->getLintID();
-
- if (isset($rules[$id])) {
- throw new Exception(
- pht(
- 'Two linter rules (`%s`, `%s`) share the same lint ID (%d). '.
- 'Each linter rule must have a unique ID.',
- $class,
- get_class($rules[$id]),
- $id));
- }
-
- $rules[$id] = $rule;
- }
-
- return $rules;
- }
-
protected function resolveFuture($path, Future $future) {
$tree = $this->getXHPASTTreeForPath($path);
if (!$tree) {
diff --git a/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php b/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php
--- a/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php
@@ -4,6 +4,32 @@
private $linter = null;
+ final public static function loadAllRules() {
+ $rules = array();
+
+ $symbols = id(new PhutilSymbolLoader())
+ ->setAncestorClass(__CLASS__)
+ ->loadObjects();
+
+ foreach ($symbols as $class => $rule) {
+ $id = $rule->getLintID();
+
+ if (isset($rules[$id])) {
+ throw new Exception(
+ pht(
+ 'Two linter rules (`%s`, `%s`) share the same lint ID (%d). '.
+ 'Each linter rule must have a unique ID.',
+ $class,
+ get_class($rules[$id]),
+ $id));
+ }
+
+ $rules[$id] = $rule;
+ }
+
+ return $rules;
+ }
+
final public function getLintID() {
$class = new ReflectionClass($this);
diff --git a/src/lint/linter/xhpast/__tests__/ArcanistXHPASTLinterRuleTestCase.php b/src/lint/linter/xhpast/__tests__/ArcanistXHPASTLinterRuleTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/xhpast/__tests__/ArcanistXHPASTLinterRuleTestCase.php
@@ -0,0 +1,10 @@
+<?php
+
+final class ArcanistXHPASTLinterRuleTestCase extends PhutilTestCase {
+
+ public function testLoadAllRules() {
+ ArcanistXHPASTLinterRule::loadAllRules();
+ $this->assertTrue(true);
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Feb 9, 10:05 AM (6 h, 37 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7106889
Default Alt Text
D13274.id.diff (3 KB)
Attached To
Mode
D13274: Add some tests for subclasses
Attached
Detach File
Event Timeline
Log In to Comment