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.linter; | 5 library linter.src.linter; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
10 import 'package:analyzer/src/generated/engine.dart' | 10 import 'package:analyzer/src/generated/engine.dart' |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 final LinterOptions options; | 54 final LinterOptions options; |
55 final Reporter reporter; | 55 final Reporter reporter; |
56 | 56 |
57 /// The total number of sources that were analyzed. Only valid after | 57 /// The total number of sources that were analyzed. Only valid after |
58 /// [lintFiles] has been called. | 58 /// [lintFiles] has been called. |
59 int numSourcesAnalyzed; | 59 int numSourcesAnalyzed; |
60 | 60 |
61 /// Creates a new linter. | 61 /// Creates a new linter. |
62 DartLinter(this.options, {this.reporter: const PrintingReporter()}); | 62 DartLinter(this.options, {this.reporter: const PrintingReporter()}); |
63 | 63 |
64 factory DartLinter.forRules(Iterable<LintRule> ruleSet) => | |
65 new DartLinter(new LinterOptions(ruleSet)); | |
66 | |
67 Iterable<AnalysisErrorInfo> lintFiles(List<File> files) { | 64 Iterable<AnalysisErrorInfo> lintFiles(List<File> files) { |
68 List<AnalysisErrorInfo> errors = []; | 65 List<AnalysisErrorInfo> errors = []; |
69 var analysisDriver = new AnalysisDriver(options); | 66 var analysisDriver = new AnalysisDriver(options); |
70 errors.addAll(analysisDriver.analyze(files.where((f) => isDartFile(f)))); | 67 errors.addAll(analysisDriver.analyze(files.where((f) => isDartFile(f)))); |
71 numSourcesAnalyzed = analysisDriver.numSourcesAnalyzed; | 68 numSourcesAnalyzed = analysisDriver.numSourcesAnalyzed; |
72 files.where((f) => isPubspecFile(f)).forEach((p) { | 69 files.where((f) => isPubspecFile(f)).forEach((p) { |
73 numSourcesAnalyzed++; | 70 numSourcesAnalyzed++; |
74 return errors.addAll(_lintPubspecFile(p)); | 71 return errors.addAll(_lintPubspecFile(p)); |
75 }); | 72 }); |
76 return errors; | 73 return errors; |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 } | 428 } |
432 | 429 |
433 class _LintCode extends LintCode { | 430 class _LintCode extends LintCode { |
434 static final registry = <String, LintCode>{}; | 431 static final registry = <String, LintCode>{}; |
435 | 432 |
436 factory _LintCode(String name, String message) => registry.putIfAbsent( | 433 factory _LintCode(String name, String message) => registry.putIfAbsent( |
437 name + message, () => new _LintCode._(name, message)); | 434 name + message, () => new _LintCode._(name, message)); |
438 | 435 |
439 _LintCode._(String name, String message) : super(name, message); | 436 _LintCode._(String name, String message) : super(name, message); |
440 } | 437 } |
OLD | NEW |