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.analysis; | 5 library linter.src.analysis; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
9 | 9 |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
11 import 'package:analyzer/file_system/file_system.dart' | 11 import 'package:analyzer/file_system/file_system.dart' |
12 show File, ResourceUriResolver; | 12 show File, ResourceUriResolver; |
13 import 'package:analyzer/file_system/physical_file_system.dart'; | 13 import 'package:analyzer/file_system/physical_file_system.dart'; |
14 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 14 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
15 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
16 import 'package:analyzer/src/generated/java_io.dart'; | 16 import 'package:analyzer/src/generated/java_io.dart'; |
17 import 'package:analyzer/src/generated/sdk.dart'; | 17 import 'package:analyzer/src/generated/sdk.dart'; |
18 import 'package:analyzer/src/generated/source.dart'; | 18 import 'package:analyzer/src/generated/source.dart'; |
19 import 'package:analyzer/src/generated/source_io.dart'; | 19 import 'package:analyzer/src/generated/source_io.dart'; |
20 import 'package:analyzer/src/services/lint.dart'; | 20 import 'package:analyzer/src/services/lint.dart'; |
21 import 'package:cli_util/cli_util.dart' as cli_util; | 21 import 'package:cli_util/cli_util.dart' as cli_util; |
22 import 'package:linter/src/io.dart'; | 22 import 'package:linter/src/io.dart'; |
23 import 'package:linter/src/linter.dart'; | 23 import 'package:linter/src/linter.dart'; |
24 import 'package:linter/src/project.dart'; | 24 import 'package:linter/src/project.dart'; |
25 import 'package:linter/src/rules.dart'; | 25 import 'package:linter/src/rules.dart'; |
26 import 'package:linter/src/sdk.dart'; | |
27 import 'package:package_config/packages.dart' show Packages; | 26 import 'package:package_config/packages.dart' show Packages; |
28 import 'package:package_config/packages_file.dart' as pkgfile show parse; | 27 import 'package:package_config/packages_file.dart' as pkgfile show parse; |
29 import 'package:package_config/src/packages_impl.dart' show MapPackages; | 28 import 'package:package_config/src/packages_impl.dart' show MapPackages; |
30 import 'package:path/path.dart' as p; | 29 import 'package:path/path.dart' as p; |
31 import 'package:plugin/manager.dart'; | 30 import 'package:plugin/manager.dart'; |
32 import 'package:plugin/plugin.dart'; | 31 import 'package:plugin/plugin.dart'; |
33 | 32 |
34 Source createSource(Uri sourceUri) { | 33 Source createSource(Uri sourceUri) { |
35 return PhysicalResourceProvider.INSTANCE | 34 return PhysicalResourceProvider.INSTANCE |
36 .getFile(sourceUri.toFilePath()) | 35 .getFile(sourceUri.toFilePath()) |
(...skipping 26 matching lines...) Expand all Loading... |
63 final LinterOptions options; | 62 final LinterOptions options; |
64 | 63 |
65 AnalysisDriver(this.options) { | 64 AnalysisDriver(this.options) { |
66 _processPlugins(); | 65 _processPlugins(); |
67 } | 66 } |
68 | 67 |
69 /// Return the number of sources that have been analyzed so far. | 68 /// Return the number of sources that have been analyzed so far. |
70 int get numSourcesAnalyzed => _sourcesAnalyzed.length; | 69 int get numSourcesAnalyzed => _sourcesAnalyzed.length; |
71 | 70 |
72 List<UriResolver> get resolvers { | 71 List<UriResolver> get resolvers { |
73 DartSdk sdk = options.useMockSdk | 72 DartSdk sdk = options.mockSdk ?? |
74 ? new MockSdk() | 73 new FolderBasedDartSdk(PhysicalResourceProvider.INSTANCE, |
75 : new FolderBasedDartSdk(PhysicalResourceProvider.INSTANCE, | |
76 PhysicalResourceProvider.INSTANCE.getFolder(sdkDir)); | 74 PhysicalResourceProvider.INSTANCE.getFolder(sdkDir)); |
77 | 75 |
78 List<UriResolver> resolvers = [new DartUriResolver(sdk)]; | 76 List<UriResolver> resolvers = [new DartUriResolver(sdk)]; |
79 | 77 |
80 if (options.packageRootPath != null) { | 78 if (options.packageRootPath != null) { |
81 JavaFile packageDirectory = new JavaFile(options.packageRootPath); | 79 JavaFile packageDirectory = new JavaFile(options.packageRootPath); |
82 resolvers.add(new PackageUriResolver([packageDirectory])); | 80 resolvers.add(new PackageUriResolver([packageDirectory])); |
83 } | 81 } |
84 | 82 |
85 // File URI resolver must come last so that files inside "/lib" are | 83 // File URI resolver must come last so that files inside "/lib" are |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 225 |
228 /// The path to the package root. | 226 /// The path to the package root. |
229 String packageRootPath; | 227 String packageRootPath; |
230 | 228 |
231 /// Whether to show SDK warnings. | 229 /// Whether to show SDK warnings. |
232 bool showSdkWarnings = false; | 230 bool showSdkWarnings = false; |
233 | 231 |
234 /// Whether to use Dart's Strong Mode analyzer. | 232 /// Whether to use Dart's Strong Mode analyzer. |
235 bool strongMode = true; | 233 bool strongMode = true; |
236 | 234 |
237 /// Whether to use a mock SDK (to speed up testing). | 235 /// The mock SDK (to speed up testing) or `null` to use the actual SDK. |
238 bool useMockSdk = false; | 236 DartSdk mockSdk; |
239 | 237 |
240 /// Whether to show lints for the transitive closure of imported and exported | 238 /// Whether to show lints for the transitive closure of imported and exported |
241 /// libraries. | 239 /// libraries. |
242 bool visitTransitiveClosure = false; | 240 bool visitTransitiveClosure = false; |
243 } | 241 } |
244 | 242 |
245 /// Prints logging information comments to the [outSink] and error messages to | 243 /// Prints logging information comments to the [outSink] and error messages to |
246 /// [errorSink]. | 244 /// [errorSink]. |
247 class StdLogger extends Logger { | 245 class StdLogger extends Logger { |
248 @override | 246 @override |
249 void logError(String message, [exception]) => errorSink.writeln(message); | 247 void logError(String message, [exception]) => errorSink.writeln(message); |
250 @override | 248 @override |
251 void logInformation(String message, [exception]) => outSink.writeln(message); | 249 void logInformation(String message, [exception]) => outSink.writeln(message); |
252 } | 250 } |
OLD | NEW |