Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Side by Side Diff: packages/analyzer/lib/src/services/lint.dart

Issue 1521693002: Roll Observatory deps (charted -> ^0.3.0) (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 lint; 5 library lint;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/engine.dart'; 8 import 'package:analyzer/src/generated/engine.dart';
9 import 'package:analyzer/src/generated/error.dart'; 9 import 'package:analyzer/src/generated/error.dart';
10 import 'package:analyzer/src/generated/source.dart'; 10 import 'package:analyzer/src/generated/source.dart';
11 import 'package:analyzer/src/generated/visitors.dart'; 11 import 'package:analyzer/src/generated/visitors.dart';
12 import 'package:analyzer/src/task/model.dart';
13 import 'package:analyzer/task/model.dart';
12 14
13 /// A registry containing mappings of contexts to their associated configured 15 const List<Linter> _noLints = const <Linter>[];
14 /// lints. 16
15 final Map<AnalysisContext, List<Linter>> lintRegistry = 17 /// The descriptor used to associate lints with analysis contexts in
16 <AnalysisContext, List<Linter>>{}; 18 /// configuration data.
19 final ResultDescriptor<List<Linter>> CONFIGURED_LINTS_KEY =
20 new ResultDescriptorImpl('configured.lints', _noLints);
21
22 /// Return lints associated with this [context], or an empty list if there are
23 /// none.
24 List<Linter> getLints(AnalysisContext context) =>
25 context.getConfigurationData(CONFIGURED_LINTS_KEY) ?? _noLints;
26
27 /// Associate these [lints] with the given [context].
28 void setLints(AnalysisContext context, List<Linter> lints) {
29 context.setConfigurationData(CONFIGURED_LINTS_KEY, lints);
30 }
17 31
18 /// Implementers contribute lint warnings via the provided error [reporter]. 32 /// Implementers contribute lint warnings via the provided error [reporter].
19 abstract class Linter { 33 abstract class Linter {
20 /// Used to report lint warnings. 34 /// Used to report lint warnings.
21 /// NOTE: this is set by the framework before visit begins. 35 /// NOTE: this is set by the framework before visit begins.
22 ErrorReporter reporter; 36 ErrorReporter reporter;
23 37
24 /// Return a visitor to be passed to compilation units to perform lint 38 /// Return a visitor to be passed to compilation units to perform lint
25 /// analysis. 39 /// analysis.
26 /// Lint errors are reported via this [Linter]'s error [reporter]. 40 /// Lint errors are reported via this [Linter]'s error [reporter].
27 AstVisitor getVisitor(); 41 AstVisitor getVisitor();
28 } 42 }
29 43
30 /// Traverses a library's worth of dart code at a time to generate lint warnings 44 /// Traverses a library's worth of dart code at a time to generate lint warnings
31 /// over the set of sources. 45 /// over the set of sources.
32 /// 46 ///
33 /// See [LintCode]. 47 /// See [LintCode].
34 class LintGenerator { 48 class LintGenerator {
35 /// A global container for contributed linters. 49 static const List<Linter> _noLints = const <Linter>[];
36 @deprecated // Use lintRegistry.
37 static final List<Linter> LINTERS = <Linter>[];
38 50
39 final Iterable<CompilationUnit> _compilationUnits; 51 final Iterable<CompilationUnit> _compilationUnits;
40 final AnalysisErrorListener _errorListener; 52 final AnalysisErrorListener _errorListener;
41 final Iterable<Linter> _linters; 53 final Iterable<Linter> _linters;
42 54
43 LintGenerator(this._compilationUnits, this._errorListener, 55 LintGenerator(this._compilationUnits, this._errorListener,
44 [Iterable<Linter> linters]) 56 [Iterable<Linter> linters])
45 : _linters = linters ?? LINTERS; 57 : _linters = linters ?? _noLints;
46 58
47 void generate() { 59 void generate() {
48 PerformanceStatistics.lint.makeCurrentWhile(() { 60 PerformanceStatistics.lint.makeCurrentWhile(() {
49 _compilationUnits.forEach((cu) { 61 _compilationUnits.forEach((cu) {
50 if (cu.element != null) { 62 if (cu.element != null) {
51 _generate(cu, cu.element.source); 63 _generate(cu, cu.element.source);
52 } 64 }
53 }); 65 });
54 }); 66 });
55 } 67 }
56 68
57 void _generate(CompilationUnit unit, Source source) { 69 void _generate(CompilationUnit unit, Source source) {
58 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); 70 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source);
59 _linters.forEach((l) => l.reporter = errorReporter); 71 _linters.forEach((l) => l.reporter = errorReporter);
60 Iterable<AstVisitor> visitors = _linters.map((l) => l.getVisitor()); 72 Iterable<AstVisitor> visitors = _linters.map((l) => l.getVisitor());
61 unit.accept(new DelegatingAstVisitor(visitors.where((v) => v != null))); 73 unit.accept(new DelegatingAstVisitor(visitors.where((v) => v != null)));
62 } 74 }
63 } 75 }
OLDNEW
« no previous file with comments | « packages/analyzer/lib/src/plugin/options_plugin.dart ('k') | packages/analyzer/lib/src/task/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698