Summary: Add some tests to ensure that `ArcanistXHPASTLinterRule` subclasses are properly implemented. This should catch issues such as two linter rules having the same `ID` value. See D13272 for a similar change.
Test Plan: `arc unit`
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: epriestley, Korvin
Differential Revision: https://secure.phabricator.com/D13274
'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',
'ArcanistXHPASTLintSwitchHook' => 'Phobject',
'ArcanistXHPASTLinter' => 'ArcanistBaseXHPASTLinter',
'ArcanistXHPASTLinterRule' => 'Phobject',
+ 'ArcanistXHPASTLinterRuleTestCase' => 'PhutilTestCase',
'ArcanistXHPASTLinterTestCase' => 'ArcanistLinterTestCase',
'ArcanistXMLLinter' => 'ArcanistLinter',
'ArcanistXMLLinterTestCase' => 'ArcanistLinterTestCase',
private $rules = array();
public function __construct() {
- $this->rules = $this->getLinterRules();
+ $this->rules = ArcanistXHPASTLinterRule::loadAllRules();
}
public function __clone() {
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) {
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);
--- /dev/null
+<?php
+
+final class ArcanistXHPASTLinterRuleTestCase extends PhutilTestCase {
+
+ public function testLoadAllRules() {
+ ArcanistXHPASTLinterRule::loadAllRules();
+ $this->assertTrue(true);
+ }
+
+}