Index: pkg/analyzer/lib/src/lint/registry.dart |
diff --git a/pkg/analyzer/lib/src/lint/registry.dart b/pkg/analyzer/lib/src/lint/registry.dart |
index 20ce0367efcde1c8de0713ed4fbab4a15ec2d616..172767ba598e2f68d70fb65bc8c080cfab55045b 100644 |
--- a/pkg/analyzer/lib/src/lint/registry.dart |
+++ b/pkg/analyzer/lib/src/lint/registry.dart |
@@ -8,7 +8,7 @@ import 'package:analyzer/src/lint/config.dart'; |
import 'package:analyzer/src/lint/linter.dart'; |
/** |
- * Registry of contributed lint rules. |
+ * Registry of lint rules. |
*/ |
class Registry extends Object with IterableMixin<LintRule> { |
/** |
@@ -16,27 +16,60 @@ class Registry extends Object with IterableMixin<LintRule> { |
*/ |
static final Registry ruleRegistry = new Registry(); |
+ /** |
+ * A table mapping rule names to rules. |
+ */ |
Map<String, LintRule> _ruleMap = <String, LintRule>{}; |
+ /** |
+ * A list of the default lint rules. |
+ */ |
+ List<LintRule> _defaultRules = <LintRule>[]; |
+ |
+ /** |
+ * Return a list of the default lint rules. |
+ */ |
+ List<LintRule> get defaultRules => _defaultRules; |
+ |
@override |
Iterator<LintRule> get iterator => _ruleMap.values.iterator; |
+ /** |
+ * Return a list of the rules that are defined. |
+ */ |
Iterable<LintRule> get rules => _ruleMap.values; |
- LintRule operator [](String key) => _ruleMap[key]; |
+ /** |
+ * Return the lint rule with the given [name]. |
+ */ |
+ LintRule operator [](String name) => _ruleMap[name]; |
- /// All lint rules explicitly enabled by the given [config]. |
- /// |
- /// For example: |
- /// my_rule: true |
- /// |
- /// enables `my_rule`. |
- /// |
- /// Unspecified rules are treated as disabled by default. |
+ /** |
+ * Return a list of the lint rules explicitly enabled by the given [config]. |
+ * |
+ * For example: |
+ * my_rule: true |
+ * |
+ * enables `my_rule`. |
+ * |
+ * Unspecified rules are treated as disabled by default. |
+ */ |
Iterable<LintRule> enabled(LintConfig config) => rules |
.where((rule) => config.ruleConfigs.any((rc) => rc.enables(rule.name))); |
+ /** |
+ * Add the given lint [rule] to this registry. |
+ */ |
void register(LintRule rule) { |
_ruleMap[rule.name] = rule; |
} |
+ |
+ /** |
+ * Add the given lint [rule] to this registry and mark it as being a default |
+ * lint (one that will be run if lints are requested but no rules are enabled. |
+ */ |
+ void registerDefault(LintRule rule) { |
+ register(rule); |
+ _defaultRules.add(rule); |
+ } |
} |