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

Side by Side Diff: pkg/analyzer_cli/lib/src/analyzer_impl.dart

Issue 1888583002: Disable computing errors for .pub-cache sources. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 months 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 | « no previous file | 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_cli.src.analyzer_impl; 5 library analyzer_cli.src.analyzer_impl;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
11 import 'package:analyzer/source/error_processor.dart'; 11 import 'package:analyzer/source/error_processor.dart';
12 import 'package:analyzer/src/generated/engine.dart'; 12 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/error.dart'; 13 import 'package:analyzer/src/generated/error.dart';
14 import 'package:analyzer/src/generated/java_engine.dart'; 14 import 'package:analyzer/src/generated/java_engine.dart';
15 import 'package:analyzer/src/generated/java_io.dart'; 15 import 'package:analyzer/src/generated/java_io.dart';
16 import 'package:analyzer/src/generated/sdk_io.dart'; 16 import 'package:analyzer/src/generated/sdk_io.dart';
17 import 'package:analyzer/src/generated/source.dart'; 17 import 'package:analyzer/src/generated/source.dart';
18 import 'package:analyzer/src/generated/source_io.dart'; 18 import 'package:analyzer/src/generated/source_io.dart';
19 import 'package:analyzer/src/generated/utilities_general.dart'; 19 import 'package:analyzer/src/generated/utilities_general.dart';
20 import 'package:analyzer_cli/src/driver.dart'; 20 import 'package:analyzer_cli/src/driver.dart';
21 import 'package:analyzer_cli/src/error_formatter.dart'; 21 import 'package:analyzer_cli/src/error_formatter.dart';
22 import 'package:analyzer_cli/src/options.dart'; 22 import 'package:analyzer_cli/src/options.dart';
23 import 'package:path/path.dart' as pathos;
23 24
24 /// The maximum number of sources for which AST structures should be kept in the cache. 25 /// The maximum number of sources for which AST structures should be kept in the cache.
25 const int _maxCacheSize = 512; 26 const int _maxCacheSize = 512;
26 27
27 DirectoryBasedDartSdk sdk; 28 DirectoryBasedDartSdk sdk;
28 29
29 int currentTimeMillis() => new DateTime.now().millisecondsSinceEpoch; 30 int currentTimeMillis() => new DateTime.now().millisecondsSinceEpoch;
30 31
31 /// Analyzes single library [File]. 32 /// Analyzes single library [File].
32 class AnalyzerImpl { 33 class AnalyzerImpl {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // Compute max severity and set exitCode. 173 // Compute max severity and set exitCode.
173 ErrorSeverity status = maxErrorSeverity; 174 ErrorSeverity status = maxErrorSeverity;
174 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { 175 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) {
175 status = ErrorSeverity.ERROR; 176 status = ErrorSeverity.ERROR;
176 } 177 }
177 return status; 178 return status;
178 } 179 }
179 180
180 /// Returns true if we want to report diagnostics for this library. 181 /// Returns true if we want to report diagnostics for this library.
181 bool _isAnalyzedLibrary(LibraryElement library) { 182 bool _isAnalyzedLibrary(LibraryElement library) {
182 switch (library.source.uriKind) { 183 Source source = library.source;
184 switch (source.uriKind) {
183 case UriKind.DART_URI: 185 case UriKind.DART_URI:
184 return options.showSdkWarnings; 186 return options.showSdkWarnings;
185 case UriKind.PACKAGE_URI: 187 case UriKind.PACKAGE_URI:
186 return _isAnalyzedPackage(library.source.uri); 188 if (_isPathInPubCache(source.fullName)) {
189 return false;
190 }
191 return _isAnalyzedPackage(source.uri);
187 default: 192 default:
188 return true; 193 return true;
189 } 194 }
190 } 195 }
191 196
192 /// Determine whether the given URI refers to a package being analyzed. 197 /// Determine whether the given URI refers to a package being analyzed.
193 bool _isAnalyzedPackage(Uri uri) { 198 bool _isAnalyzedPackage(Uri uri) {
194 if (uri.scheme != 'package' || uri.pathSegments.isEmpty) { 199 if (uri.scheme != 'package' || uri.pathSegments.isEmpty) {
195 return false; 200 return false;
196 } 201 }
197
198 String packageName = uri.pathSegments.first; 202 String packageName = uri.pathSegments.first;
199 if (packageName == _selfPackageName) { 203 if (packageName == _selfPackageName) {
200 return true; 204 return true;
201 } else if (!options.showPackageWarnings) { 205 } else if (!options.showPackageWarnings) {
202 return false; 206 return false;
203 } else if (options.showPackageWarningsPrefix == null) { 207 } else if (options.showPackageWarningsPrefix == null) {
204 return true; 208 return true;
205 } else { 209 } else {
206 return packageName.startsWith(options.showPackageWarningsPrefix); 210 return packageName.startsWith(options.showPackageWarningsPrefix);
207 } 211 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // If not overridden, some "natural" severities get globally filtered. 325 // If not overridden, some "natural" severities get globally filtered.
322 if (!isOverridden) { 326 if (!isOverridden) {
323 // Check for global hint filtering. 327 // Check for global hint filtering.
324 if (severity == ErrorSeverity.INFO && options.disableHints) { 328 if (severity == ErrorSeverity.INFO && options.disableHints) {
325 return null; 329 return null;
326 } 330 }
327 } 331 }
328 332
329 return new ProcessedSeverity(severity, isOverridden); 333 return new ProcessedSeverity(severity, isOverridden);
330 } 334 }
335
336 /// Return `true` if the given [path] is in the Pub cache.
337 static bool _isPathInPubCache(String path) {
338 List<String> parts = pathos.split(path);
339 if (parts.contains('.pub-cache')) {
340 return true;
341 }
342 for (int i = 0; i < parts.length - 2; i++) {
343 if (parts[i] == 'Pub' && parts[i + 1] == 'Cache') {
344 return true;
345 }
346 }
347 return false;
348 }
331 } 349 }
332 350
333 /// This [Logger] prints out information comments to [outSink] and error message s 351 /// This [Logger] prints out information comments to [outSink] and error message s
334 /// to [errorSink]. 352 /// to [errorSink].
335 class StdLogger extends Logger { 353 class StdLogger extends Logger {
336 StdLogger(); 354 StdLogger();
337 355
338 @override 356 @override
339 void logError(String message, [CaughtException exception]) { 357 void logError(String message, [CaughtException exception]) {
340 errorSink.writeln(message); 358 errorSink.writeln(message);
341 if (exception != null) { 359 if (exception != null) {
342 errorSink.writeln(exception); 360 errorSink.writeln(exception);
343 } 361 }
344 } 362 }
345 363
346 @override 364 @override
347 void logInformation(String message, [CaughtException exception]) { 365 void logInformation(String message, [CaughtException exception]) {
348 outSink.writeln(message); 366 outSink.writeln(message);
349 if (exception != null) { 367 if (exception != null) {
350 outSink.writeln(exception); 368 outSink.writeln(exception);
351 } 369 }
352 } 370 }
353 } 371 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698