Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 import 'package:analyzer/error/error.dart'; | |
| 6 import 'package:analyzer/source/error_processor.dart'; | |
| 7 import 'package:analyzer/src/error/codes.dart'; | |
| 8 import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult; | |
| 9 | |
| 10 import 'error_formatter.dart'; | |
| 11 import 'options.dart'; | |
| 12 | |
| 13 /// Check various configuration options to get a desired severity for this | |
| 14 /// [error] (or `null` if it's to be suppressed). | |
| 15 ProcessedSeverity processError(AnalysisError error, | |
| 16 CommandLineOptions commandLineOptions, AnalysisOptions analysisOptions) { | |
| 17 ErrorSeverity severity = computeSeverity(error, commandLineOptions, | |
| 18 analysisOptions: analysisOptions); | |
| 19 bool isOverridden = false; | |
| 20 | |
| 21 // Skip TODOs categorically (unless escalated to ERROR or HINT.) | |
| 22 // https://github.com/dart-lang/sdk/issues/26215 | |
|
Brian Wilkerson
2017/02/19 22:52:17
nit: please indent internal comments so that they
devoncarew
2017/02/21 04:30:47
updated. This happened via copy and paste; strange
| |
| 23 if (error.errorCode.type == ErrorType.TODO && | |
| 24 severity == ErrorSeverity.INFO) { | |
| 25 return null; | |
| 26 } | |
| 27 | |
| 28 // First check for a filter. | |
| 29 if (severity == null) { | |
| 30 // Null severity means the error has been explicitly ignored. | |
| 31 return null; | |
| 32 } else { | |
| 33 isOverridden = true; | |
| 34 } | |
| 35 | |
| 36 // If not overridden, some "natural" severities get globally filtered. | |
| 37 if (!isOverridden) { | |
| 38 // Check for global hint filtering. | |
| 39 if (severity == ErrorSeverity.INFO && commandLineOptions.disableHints) { | |
| 40 return null; | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 return new ProcessedSeverity(severity, isOverridden); | |
| 45 } | |
| 46 | |
| 47 /// Compute the severity of the error; however: | |
| 48 /// - if [options.enableTypeChecks] is false, then de-escalate checked-mode | |
| 49 /// compile time errors to a severity of [ErrorSeverity.INFO]. | |
| 50 /// - if [options.hintsAreFatal] is true, escalate hints to errors. | |
| 51 /// - if [options.lintsAreFatal] is true, escalate lints to errors. | |
| 52 ErrorSeverity computeSeverity( | |
| 53 AnalysisError error, CommandLineOptions commandLineOptions, | |
| 54 {AnalysisOptions analysisOptions}) { | |
| 55 if (analysisOptions != null) { | |
| 56 ErrorProcessor processor = | |
| 57 ErrorProcessor.getProcessor(analysisOptions, error); | |
| 58 // If there is a processor for this error, defer to it. | |
| 59 if (processor != null) { | |
| 60 return processor.severity; | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 if (!commandLineOptions.enableTypeChecks && | |
| 65 error.errorCode.type == ErrorType.CHECKED_MODE_COMPILE_TIME_ERROR) { | |
| 66 return ErrorSeverity.INFO; | |
| 67 } else if (commandLineOptions.hintsAreFatal && error.errorCode is HintCode) { | |
| 68 return ErrorSeverity.ERROR; | |
| 69 } else if (commandLineOptions.lintsAreFatal && error.errorCode is LintCode) { | |
| 70 return ErrorSeverity.ERROR; | |
| 71 } | |
| 72 return error.errorCode.errorSeverity; | |
| 73 } | |
| OLD | NEW |