OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import 'dart:collection'; | |
6 | |
7 import 'package:analyzer/src/lint/config.dart'; | |
8 import 'package:analyzer/src/lint/linter.dart'; | |
9 | |
10 /** | |
11 * Registry of contributed lint rules. | |
12 */ | |
13 class Registry extends Object with IterableMixin<LintRule> { | |
14 /** | |
15 * The default registry to be used by clients. | |
16 */ | |
17 static final Registry ruleRegistry = new Registry(); | |
18 | |
19 Map<String, LintRule> _ruleMap = <String, LintRule>{}; | |
20 | |
21 @override | |
22 Iterator<LintRule> get iterator => _ruleMap.values.iterator; | |
23 | |
24 Iterable<LintRule> get rules => _ruleMap.values; | |
25 | |
26 LintRule operator [](String key) => _ruleMap[key]; | |
27 | |
28 /// All lint rules explicitly enabled by the given [config]. | |
29 /// | |
30 /// For example: | |
31 /// my_rule: true | |
32 /// | |
33 /// enables `my_rule`. | |
34 /// | |
35 /// Unspecified rules are treated as disabled by default. | |
36 Iterable<LintRule> enabled(LintConfig config) => rules | |
37 .where((rule) => config.ruleConfigs.any((rc) => rc.enables(rule.name))); | |
38 | |
39 void register(LintRule rule) { | |
40 _ruleMap[rule.name] = rule; | |
41 } | |
42 } | |
OLD | NEW |