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

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

Issue 2545553007: Add support for generating lints when using the new driver (Closed)
Patch Set: fix some tests Created 4 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
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/status.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 analyzer.src.services.lint; 5 library analyzer.src.services.lint;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/error/listener.dart'; 10 import 'package:analyzer/error/listener.dart';
11 import 'package:analyzer/src/dart/error/lint_codes.dart';
11 import 'package:analyzer/src/generated/engine.dart'; 12 import 'package:analyzer/src/generated/engine.dart';
12 13
13 /// Shared lint registry. 14 /// Shared lint registry.
14 LintRegistry lintRegistry = new LintRegistry(); 15 LintRegistry lintRegistry = new LintRegistry();
15 16
16 /// Return lints associated with this [context], or an empty list if there are 17 /// Return lints associated with this [context], or an empty list if there are
17 /// none. 18 /// none.
18 List<Linter> getLints(AnalysisContext context) => 19 List<Linter> getLints(AnalysisContext context) =>
19 context.analysisOptions.lintRules; 20 context.analysisOptions.lintRules;
20 21
21 /// Associate these [lints] with the given [context]. 22 /// Associate these [lints] with the given [context].
22 void setLints(AnalysisContext context, List<Linter> lints) { 23 void setLints(AnalysisContext context, List<Linter> lints) {
23 AnalysisOptionsImpl options = 24 AnalysisOptionsImpl options =
24 new AnalysisOptionsImpl.from(context.analysisOptions); 25 new AnalysisOptionsImpl.from(context.analysisOptions);
25 options.lintRules = lints; 26 options.lintRules = lints;
26 context.analysisOptions = options; 27 context.analysisOptions = options;
27 } 28 }
28 29
29 /// Implementers contribute lint warnings via the provided error [reporter]. 30 /// Implementers contribute lint warnings via the provided error [reporter].
30 abstract class Linter { 31 abstract class Linter {
31 /// Used to report lint warnings. 32 /// Used to report lint warnings.
32 /// NOTE: this is set by the framework before visit begins. 33 /// NOTE: this is set by the framework before visit begins.
33 ErrorReporter reporter; 34 ErrorReporter reporter;
34 35
36 /**
37 * Return the lint code associated with this linter.
38 */
39 LintCode get lintCode => null;
40
35 /// Linter name. 41 /// Linter name.
36 String get name; 42 String get name;
37 43
38 /// Return a visitor to be passed to compilation units to perform lint 44 /// Return a visitor to be passed to compilation units to perform lint
39 /// analysis. 45 /// analysis.
40 /// Lint errors are reported via this [Linter]'s error [reporter]. 46 /// Lint errors are reported via this [Linter]'s error [reporter].
41 AstVisitor getVisitor(); 47 AstVisitor getVisitor();
42 } 48 }
43 49
44 /// Manages lint timing. 50 /// Manages lint timing.
45 class LintRegistry { 51 class LintRegistry {
46 /// Dictionary mapping lints (by name) to timers. 52 /// Dictionary mapping lints (by name) to timers.
47 final Map<String, Stopwatch> timers = new HashMap<String, Stopwatch>(); 53 final Map<String, Stopwatch> timers = new HashMap<String, Stopwatch>();
48 54
49 /// Get a timer associated with the given lint rule (or create one if none 55 /// Get a timer associated with the given lint rule (or create one if none
50 /// exists). 56 /// exists).
51 Stopwatch getTimer(Linter linter) => 57 Stopwatch getTimer(Linter linter) =>
52 timers.putIfAbsent(linter.name, () => new Stopwatch()); 58 timers.putIfAbsent(linter.name, () => new Stopwatch());
53 } 59 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/status.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698