| 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 import 'dart:async'; |
| 5 import 'dart:io'; | 6 import 'dart:io'; |
| 6 | 7 |
| 7 import 'package:analyzer/analyzer.dart'; | 8 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
| 10 import 'package:analyzer/file_system/file_system.dart' as file_system; |
| 9 import 'package:analyzer/src/generated/engine.dart' | 11 import 'package:analyzer/src/generated/engine.dart' |
| 10 show AnalysisErrorInfo, AnalysisErrorInfoImpl, Logger; | 12 show AnalysisErrorInfo, AnalysisErrorInfoImpl, Logger; |
| 11 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; | 13 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; |
| 12 import 'package:analyzer/src/generated/source.dart' show LineInfo; | 14 import 'package:analyzer/src/generated/source.dart' show LineInfo; |
| 13 import 'package:analyzer/src/generated/source_io.dart'; | 15 import 'package:analyzer/src/generated/source_io.dart'; |
| 14 import 'package:analyzer/src/lint/analysis.dart'; | 16 import 'package:analyzer/src/lint/analysis.dart'; |
| 15 import 'package:analyzer/src/lint/config.dart'; | 17 import 'package:analyzer/src/lint/config.dart'; |
| 16 import 'package:analyzer/src/lint/io.dart'; | 18 import 'package:analyzer/src/lint/io.dart'; |
| 17 import 'package:analyzer/src/lint/project.dart'; | 19 import 'package:analyzer/src/lint/project.dart'; |
| 18 import 'package:analyzer/src/lint/pub.dart'; | 20 import 'package:analyzer/src/lint/pub.dart'; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 final LinterOptions options; | 55 final LinterOptions options; |
| 54 final Reporter reporter; | 56 final Reporter reporter; |
| 55 | 57 |
| 56 /// The total number of sources that were analyzed. Only valid after | 58 /// The total number of sources that were analyzed. Only valid after |
| 57 /// [lintFiles] has been called. | 59 /// [lintFiles] has been called. |
| 58 int numSourcesAnalyzed; | 60 int numSourcesAnalyzed; |
| 59 | 61 |
| 60 /// Creates a new linter. | 62 /// Creates a new linter. |
| 61 DartLinter(this.options, {this.reporter: const PrintingReporter()}); | 63 DartLinter(this.options, {this.reporter: const PrintingReporter()}); |
| 62 | 64 |
| 63 Iterable<AnalysisErrorInfo> lintFiles(List<File> files) { | 65 Future<Iterable<AnalysisErrorInfo>> lintFiles(List<File> files) async { |
| 64 List<AnalysisErrorInfo> errors = []; | 66 List<AnalysisErrorInfo> errors = []; |
| 65 var analysisDriver = new LintDriver(options); | 67 final lintDriver = new LintDriver(options); |
| 66 errors.addAll(analysisDriver.analyze(files.where((f) => isDartFile(f)))); | 68 errors.addAll(await lintDriver.analyze(files.where((f) => isDartFile(f)))); |
| 67 numSourcesAnalyzed = analysisDriver.numSourcesAnalyzed; | 69 numSourcesAnalyzed = lintDriver.numSourcesAnalyzed; |
| 68 files.where((f) => isPubspecFile(f)).forEach((p) { | 70 files.where((f) => isPubspecFile(f)).forEach((p) { |
| 69 numSourcesAnalyzed++; | 71 numSourcesAnalyzed++; |
| 70 return errors.addAll(_lintPubspecFile(p)); | 72 return errors.addAll(_lintPubspecFile(p)); |
| 71 }); | 73 }); |
| 72 return errors; | 74 return errors; |
| 73 } | 75 } |
| 74 | 76 |
| 75 Iterable<AnalysisErrorInfo> lintPubspecSource( | 77 Iterable<AnalysisErrorInfo> lintPubspecSource( |
| 76 {String contents, String sourcePath}) { | 78 {String contents, String sourcePath}) { |
| 77 var results = <AnalysisErrorInfo>[]; | 79 var results = <AnalysisErrorInfo>[]; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 188 |
| 187 @override | 189 @override |
| 188 String toString() => | 190 String toString() => |
| 189 message == null ? "LinterException" : "LinterException: $message"; | 191 message == null ? "LinterException" : "LinterException: $message"; |
| 190 } | 192 } |
| 191 | 193 |
| 192 /// Linter options. | 194 /// Linter options. |
| 193 class LinterOptions extends DriverOptions { | 195 class LinterOptions extends DriverOptions { |
| 194 Iterable<LintRule> enabledLints; | 196 Iterable<LintRule> enabledLints; |
| 195 LintFilter filter; | 197 LintFilter filter; |
| 198 file_system.ResourceProvider resourceProvider; |
| 196 LinterOptions([this.enabledLints]) { | 199 LinterOptions([this.enabledLints]) { |
| 197 enabledLints ??= Registry.ruleRegistry; | 200 enabledLints ??= Registry.ruleRegistry; |
| 198 } | 201 } |
| 199 void configure(LintConfig config) { | 202 void configure(LintConfig config) { |
| 200 // TODO(pquitslund): revisit these default-to-on semantics. | 203 // TODO(pquitslund): revisit these default-to-on semantics. |
| 201 enabledLints = Registry.ruleRegistry.where((LintRule rule) => | 204 enabledLints = Registry.ruleRegistry.where((LintRule rule) => |
| 202 !config.ruleConfigs.any((rc) => rc.disables(rule.name))); | 205 !config.ruleConfigs.any((rc) => rc.disables(rule.name))); |
| 203 filter = new FileGlobFilter(config.fileIncludes, config.fileExcludes); | 206 filter = new FileGlobFilter(config.fileIncludes, config.fileExcludes); |
| 204 } | 207 } |
| 205 } | 208 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 final LinterOptions options; | 357 final LinterOptions options; |
| 355 @override | 358 @override |
| 356 final Reporter reporter; | 359 final Reporter reporter; |
| 357 | 360 |
| 358 @override | 361 @override |
| 359 int numSourcesAnalyzed; | 362 int numSourcesAnalyzed; |
| 360 | 363 |
| 361 SourceLinter(this.options, {this.reporter: const PrintingReporter()}); | 364 SourceLinter(this.options, {this.reporter: const PrintingReporter()}); |
| 362 | 365 |
| 363 @override | 366 @override |
| 364 Iterable<AnalysisErrorInfo> lintFiles(List<File> files) { | 367 Future<Iterable<AnalysisErrorInfo>> lintFiles(List<File> files) async { |
| 365 List<AnalysisErrorInfo> errors = []; | 368 List<AnalysisErrorInfo> errors = []; |
| 366 var analysisDriver = new LintDriver(options); | 369 final lintDriver = new LintDriver(options); |
| 367 errors.addAll(analysisDriver.analyze(files.where((f) => isDartFile(f)))); | 370 errors.addAll(await lintDriver.analyze(files.where((f) => isDartFile(f)))); |
| 368 numSourcesAnalyzed = analysisDriver.numSourcesAnalyzed; | 371 numSourcesAnalyzed = lintDriver.numSourcesAnalyzed; |
| 369 files.where((f) => isPubspecFile(f)).forEach((p) { | 372 files.where((f) => isPubspecFile(f)).forEach((p) { |
| 370 numSourcesAnalyzed++; | 373 numSourcesAnalyzed++; |
| 371 return errors.addAll(_lintPubspecFile(p)); | 374 return errors.addAll(_lintPubspecFile(p)); |
| 372 }); | 375 }); |
| 373 return errors; | 376 return errors; |
| 374 } | 377 } |
| 375 | 378 |
| 376 @override | 379 @override |
| 377 Iterable<AnalysisErrorInfo> lintPubspecSource( | 380 Iterable<AnalysisErrorInfo> lintPubspecSource( |
| 378 {String contents, String sourcePath}) { | 381 {String contents, String sourcePath}) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 } | 423 } |
| 421 | 424 |
| 422 class _LintCode extends LintCode { | 425 class _LintCode extends LintCode { |
| 423 static final registry = <String, LintCode>{}; | 426 static final registry = <String, LintCode>{}; |
| 424 | 427 |
| 425 factory _LintCode(String name, String message) => registry.putIfAbsent( | 428 factory _LintCode(String name, String message) => registry.putIfAbsent( |
| 426 name + message, () => new _LintCode._(name, message)); | 429 name + message, () => new _LintCode._(name, message)); |
| 427 | 430 |
| 428 _LintCode._(String name, String message) : super(name, message); | 431 _LintCode._(String name, String message) : super(name, message); |
| 429 } | 432 } |
| OLD | NEW |