Chromium Code Reviews| Index: pkg/analyzer/lib/src/services/lint.dart |
| diff --git a/pkg/analyzer/lib/src/services/lint.dart b/pkg/analyzer/lib/src/services/lint.dart |
| index 5efc3eae5b4cfdef094b747c3fa4a547fb78fa0a..a6b55ccbdc4145f6db9ff1806c19eeb46860e0c1 100644 |
| --- a/pkg/analyzer/lib/src/services/lint.dart |
| +++ b/pkg/analyzer/lib/src/services/lint.dart |
| @@ -9,11 +9,25 @@ import 'package:analyzer/src/generated/engine.dart'; |
| import 'package:analyzer/src/generated/error.dart'; |
| import 'package:analyzer/src/generated/source.dart'; |
| import 'package:analyzer/src/generated/visitors.dart'; |
| +import 'package:analyzer/src/task/model.dart'; |
| +import 'package:analyzer/task/model.dart'; |
| -/// A registry containing mappings of contexts to their associated configured |
| -/// lints. |
| -final Map<AnalysisContext, List<Linter>> lintRegistry = |
| - <AnalysisContext, List<Linter>>{}; |
| +const List<Linter> _noLints = const <Linter>[]; |
| + |
| +/// The descriptor used to associate lints with analysis contexts in |
| +/// configuration data. |
| +final ResultDescriptor<List<Linter>> CONFIGURED_LINTS_KEY = |
| + new ResultDescriptorImpl('configured.lints', _noLints); |
| + |
| +/// Return lints associated with this [context], or an empty list if there are |
| +/// none. |
| +List<Linter> getLints(AnalysisContext context) => |
| + context.getConfigurationData(CONFIGURED_LINTS_KEY) ?? _noLints; |
| + |
| +/// Associate these [lints] with the given [context]. |
| +void setLints(AnalysisContext context, List<Linter> lints) { |
| + context.setConfigurationData(CONFIGURED_LINTS_KEY, lints); |
| +} |
| /// Implementers contribute lint warnings via the provided error [reporter]. |
| abstract class Linter { |
| @@ -32,9 +46,7 @@ abstract class Linter { |
| /// |
| /// See [LintCode]. |
| class LintGenerator { |
| - /// A global container for contributed linters. |
| - @deprecated // Use lintRegistry. |
| - static final List<Linter> LINTERS = <Linter>[]; |
| + static const List<Linter> _noLints = const <Linter>[]; |
|
Brian Wilkerson
2015/10/15 21:31:05
The rest of the code base generally defines consta
|
| final Iterable<CompilationUnit> _compilationUnits; |
| final AnalysisErrorListener _errorListener; |
| @@ -42,7 +54,7 @@ class LintGenerator { |
| LintGenerator(this._compilationUnits, this._errorListener, |
| [Iterable<Linter> linters]) |
| - : _linters = linters ?? LINTERS; |
| + : _linters = linters ?? _noLints; |
| void generate() { |
| PerformanceStatistics.lint.makeCurrentWhile(() { |