| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library linter.src.plugin.linter_plugin; | 5 library linter.src.plugin.linter_plugin; |
| 6 | 6 |
| 7 import 'package:analyzer/plugin/options.dart'; | 7 import 'package:analyzer/plugin/options.dart'; |
| 8 import 'package:analyzer/src/generated/engine.dart'; | 8 import 'package:analyzer/src/generated/engine.dart'; |
| 9 import 'package:analyzer/src/services/lint.dart'; | 9 import 'package:analyzer/src/services/lint.dart'; |
| 10 import 'package:linter/plugin/linter.dart'; | 10 import 'package:linter/plugin/linter.dart'; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 static const List<Linter> _noLints = const <Linter>[]; | 33 static const List<Linter> _noLints = const <Linter>[]; |
| 34 | 34 |
| 35 /// The unique identifier of this plugin. | 35 /// The unique identifier of this plugin. |
| 36 static const String UNIQUE_IDENTIFIER = 'linter.core'; | 36 static const String UNIQUE_IDENTIFIER = 'linter.core'; |
| 37 | 37 |
| 38 /// The simple identifier of the extension point that allows plugins to | 38 /// The simple identifier of the extension point that allows plugins to |
| 39 /// register new lint rules. | 39 /// register new lint rules. |
| 40 static const String LINT_RULE_EXTENSION_POINT = 'rule'; | 40 static const String LINT_RULE_EXTENSION_POINT = 'rule'; |
| 41 | 41 |
| 42 /// The extension point that allows plugins to register new lint rules. | 42 /// The extension point that allows plugins to register new lint rules. |
| 43 ExtensionPoint lintRuleExtensionPoint; | 43 ExtensionPoint<LintRule> lintRuleExtensionPoint; |
| 44 | 44 |
| 45 /// An options processor for creating lint configs from analysis options. | 45 /// An options processor for creating lint configs from analysis options. |
| 46 AnalysisOptionsProcessor _optionsProcessor; | 46 AnalysisOptionsProcessor _optionsProcessor; |
| 47 | 47 |
| 48 /// Cached config (temporary to support legacy `lintRules` getter). | 48 /// Cached config (temporary to support legacy `lintRules` getter). |
| 49 LintConfig _config; | 49 LintConfig _config; |
| 50 | 50 |
| 51 LinterPlugin() { | 51 LinterPlugin() { |
| 52 _optionsProcessor = new AnalysisOptionsProcessor(this); | 52 _optionsProcessor = new AnalysisOptionsProcessor(this); |
| 53 } | 53 } |
| 54 | 54 |
| 55 /// Return a list of all contributed lint rules. | 55 /// Return a list of all contributed lint rules. |
| 56 List<LintRule> get contributedRules => lintRuleExtensionPoint.extensions; | 56 List<LintRule> get contributedRules => lintRuleExtensionPoint.extensions; |
| 57 | 57 |
| 58 /// Return a list of enabled lint rules. | 58 /// Return a list of enabled lint rules. |
| 59 /// | 59 /// |
| 60 /// By default this list includes all [contributedRules]. Specific lints | 60 /// By default this list includes all [contributedRules]. Specific lints |
| 61 /// can be enabled/disabled (and in the future further configured) through | 61 /// can be enabled/disabled (and in the future further configured) through |
| 62 /// a specified analysis options file. | 62 /// a specified analysis options file. |
| 63 @deprecated // Use context.getConfigurationData(..) | 63 @deprecated // Use context.getConfigurationData(..) |
| 64 List<LintRule> get lintRules => _getRules(_config); | 64 List<LintRule> get lintRules => _getRules(_config); |
| 65 | 65 |
| 66 @override | 66 @override |
| 67 String get uniqueIdentifier => UNIQUE_IDENTIFIER; | 67 String get uniqueIdentifier => UNIQUE_IDENTIFIER; |
| 68 | 68 |
| 69 @override | 69 @override |
| 70 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { | 70 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { |
| 71 lintRuleExtensionPoint = registerExtensionPoint( | 71 lintRuleExtensionPoint = |
| 72 LINT_RULE_EXTENSION_POINT, _validateTaskExtension); | 72 new ExtensionPoint<LintRule>(this, LINT_RULE_EXTENSION_POINT, null); |
| 73 registerExtensionPoint(lintRuleExtensionPoint); |
| 73 } | 74 } |
| 74 | 75 |
| 75 @override | 76 @override |
| 76 void registerExtensions(RegisterExtension registerExtension) { | 77 void registerExtensions(RegisterExtension registerExtension) { |
| 77 // A subset of rules that we are considering enabled by "default". | 78 // A subset of rules that we are considering enabled by "default". |
| 78 [ | 79 [ |
| 79 new CamelCaseTypes(), | 80 new CamelCaseTypes(), |
| 80 new ConstantIdentifierNames(), | 81 new ConstantIdentifierNames(), |
| 81 new EmptyConstructorBodies(), | 82 new EmptyConstructorBodies(), |
| 82 new LibraryNames(), | 83 new LibraryNames(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 94 | 95 |
| 95 List<Linter> registerLints(AnalysisContext context, LintConfig config) { | 96 List<Linter> registerLints(AnalysisContext context, LintConfig config) { |
| 96 _config = config; | 97 _config = config; |
| 97 List<Linter> lints = _getRules(config); | 98 List<Linter> lints = _getRules(config); |
| 98 setLints(context, lints); | 99 setLints(context, lints); |
| 99 return lints; | 100 return lints; |
| 100 } | 101 } |
| 101 | 102 |
| 102 List<Linter> _getRules(LintConfig config) => | 103 List<Linter> _getRules(LintConfig config) => |
| 103 config != null ? ruleRegistry.enabled(config).toList() : _noLints; | 104 config != null ? ruleRegistry.enabled(config).toList() : _noLints; |
| 104 | |
| 105 void _validateTaskExtension(Object extension) { | |
| 106 if (extension is! LintRule) { | |
| 107 String id = lintRuleExtensionPoint.uniqueIdentifier; | |
| 108 throw new ExtensionError('Extensions to $id must implement LintRule'); | |
| 109 } | |
| 110 } | |
| 111 } | 105 } |
| OLD | NEW |