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

Unified Diff: pkg/analyzer_cli/lib/src/analyzer_impl.dart

Issue 1529243002: Fix `analyzer_cli` error overrides (#24452). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/error_formatter.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer_cli/lib/src/analyzer_impl.dart
diff --git a/pkg/analyzer_cli/lib/src/analyzer_impl.dart b/pkg/analyzer_cli/lib/src/analyzer_impl.dart
index 84b28c50bd123501b512cfd3659fd0727fc6b4df..d54178e5663d67b90adea189c38ee3f4a371b00d 100644
--- a/pkg/analyzer_cli/lib/src/analyzer_impl.dart
+++ b/pkg/analyzer_cli/lib/src/analyzer_impl.dart
@@ -8,6 +8,7 @@ import 'dart:collection';
import 'dart:io';
import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/source/error_processor.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/error.dart';
import 'package:analyzer/src/generated/java_engine.dart';
@@ -59,7 +60,7 @@ class AnalyzerImpl {
var status = ErrorSeverity.NONE;
for (AnalysisErrorInfo errorInfo in errorInfos) {
for (AnalysisError error in errorInfo.errors) {
- if (!_isDesiredError(error)) {
+ if (_processError(error) == null) {
continue;
}
var severity = computeSeverity(error, options);
@@ -175,17 +176,6 @@ class AnalyzerImpl {
return status;
}
- bool _isDesiredError(AnalysisError error) {
- if (error.errorCode.type == ErrorType.TODO) {
- return false;
- }
- if (computeSeverity(error, options) == ErrorSeverity.INFO &&
- options.disableHints) {
- return false;
- }
- return true;
- }
-
/// Determine whether the given URI refers to a package other than the package
/// being analyzed.
bool _isOtherPackage(Uri uri) {
@@ -225,24 +215,64 @@ class AnalyzerImpl {
StringSink sink = options.machineFormat ? errorSink : outSink;
// Print errors.
- ErrorFormatter formatter =
- new ErrorFormatter(sink, options, _isDesiredError);
+ ErrorFormatter formatter = new ErrorFormatter(sink, options, _processError);
formatter.formatErrors(errorInfos);
}
+ /// Check various configuration options to get a desired severity for this
+ /// [error] (or `null` if it's to be suppressed).
+ ProcessedSeverity _processError(AnalysisError error) {
+ ErrorSeverity severity = computeSeverity(error, options, context);
+ bool isOverridden = false;
+
+ // First check for a filter.
+ if (severity == null) {
+ // Null severity means the error has been explicitly ignored.
+ return null;
+ } else {
+ isOverridden = true;
+ }
+
+ // If not overridden, some "natural" severities get globally filtered.
+ if (!isOverridden) {
+ // Check for global hint filtering.
+ if (severity == ErrorSeverity.INFO && options.disableHints) {
+ return null;
+ }
+
+ // Skip TODOs.
+ if (severity == ErrorType.TODO) {
+ return null;
+ }
+ }
+
+ return new ProcessedSeverity(severity, isOverridden);
+ }
+
/// Compute the severity of the error; however:
/// * if [options.enableTypeChecks] is false, then de-escalate checked-mode
/// compile time errors to a severity of [ErrorSeverity.INFO].
/// * if [options.hintsAreFatal] is true, escalate hints to errors.
static ErrorSeverity computeSeverity(
- AnalysisError error, CommandLineOptions options) {
+ AnalysisError error, CommandLineOptions options,
+ [AnalysisContext context]) {
+ if (context != null) {
+ ErrorProcessor processor = ErrorProcessor.getProcessor(context, error);
+ // If there is a processor for this error, defer to it.
+ if (processor != null) {
+ return processor.severity;
+ }
+ }
+
if (!options.enableTypeChecks &&
error.errorCode.type == ErrorType.CHECKED_MODE_COMPILE_TIME_ERROR) {
return ErrorSeverity.INFO;
}
+
if (options.hintsAreFatal && error.errorCode is HintCode) {
return ErrorSeverity.ERROR;
}
+
return error.errorCode.errorSeverity;
}
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/error_formatter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698