| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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 'package:analyzer/error/error.dart'; | 5 import 'package:analyzer/error/error.dart'; |
| 6 import 'package:analyzer/source/error_processor.dart'; | 6 import 'package:analyzer/source/error_processor.dart'; |
| 7 import 'package:analyzer/src/error/codes.dart'; | 7 import 'package:analyzer/src/error/codes.dart'; |
| 8 import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult; | 8 import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult; |
| 9 import 'package:analyzer_cli/src/options.dart'; | 9 import 'package:analyzer_cli/src/options.dart'; |
| 10 | 10 |
| 11 /// Check various configuration options to get a desired severity for this | |
| 12 /// [error] (or `null` if it's to be suppressed). | |
| 13 ErrorSeverity determineProcessedSeverity(AnalysisError error, | |
| 14 CommandLineOptions commandLineOptions, AnalysisOptions analysisOptions) { | |
| 15 ErrorSeverity severity = | |
| 16 computeSeverity(error, commandLineOptions, analysisOptions); | |
| 17 // Skip TODOs categorically unless escalated to ERROR or HINT (#26215). | |
| 18 if (error.errorCode.type == ErrorType.TODO && | |
| 19 severity == ErrorSeverity.INFO) { | |
| 20 return null; | |
| 21 } | |
| 22 | |
| 23 // TODO(devoncarew): We should not filter hints here. | |
| 24 // If not overridden, some "natural" severities get globally filtered. | |
| 25 // Check for global hint filtering. | |
| 26 if (severity == ErrorSeverity.INFO && commandLineOptions.disableHints) { | |
| 27 return null; | |
| 28 } | |
| 29 | |
| 30 return severity; | |
| 31 } | |
| 32 | |
| 33 /// Compute the severity of the error; however: | 11 /// Compute the severity of the error; however: |
| 34 /// - if [options.enableTypeChecks] is false, then de-escalate checked-mode | 12 /// - if [options.enableTypeChecks] is false, then de-escalate checked-mode |
| 35 /// compile time errors to a severity of [ErrorSeverity.INFO]. | 13 /// compile time errors to a severity of [ErrorSeverity.INFO]. |
| 36 /// - if [options.lintsAreFatal] is true, escalate lints to errors. | 14 /// - if [options.lintsAreFatal] is true, escalate lints to errors. |
| 37 ErrorSeverity computeSeverity( | 15 ErrorSeverity computeSeverity( |
| 38 AnalysisError error, | 16 AnalysisError error, |
| 39 CommandLineOptions commandLineOptions, | 17 CommandLineOptions commandLineOptions, |
| 40 AnalysisOptions analysisOptions, | 18 AnalysisOptions analysisOptions, |
| 41 ) { | 19 ) { |
| 42 if (analysisOptions != null) { | 20 if (analysisOptions != null) { |
| 43 ErrorProcessor processor = | 21 ErrorProcessor processor = |
| 44 ErrorProcessor.getProcessor(analysisOptions, error); | 22 ErrorProcessor.getProcessor(analysisOptions, error); |
| 45 // If there is a processor for this error, defer to it. | 23 // If there is a processor for this error, defer to it. |
| 46 if (processor != null) { | 24 if (processor != null) { |
| 47 return processor.severity; | 25 return processor.severity; |
| 48 } | 26 } |
| 49 } | 27 } |
| 50 | 28 |
| 51 if (!commandLineOptions.enableTypeChecks && | 29 if (!commandLineOptions.enableTypeChecks && |
| 52 error.errorCode.type == ErrorType.CHECKED_MODE_COMPILE_TIME_ERROR) { | 30 error.errorCode.type == ErrorType.CHECKED_MODE_COMPILE_TIME_ERROR) { |
| 53 return ErrorSeverity.INFO; | 31 return ErrorSeverity.INFO; |
| 54 } else if (commandLineOptions.lintsAreFatal && error.errorCode is LintCode) { | 32 } else if (commandLineOptions.lintsAreFatal && error.errorCode is LintCode) { |
| 55 return ErrorSeverity.ERROR; | 33 return ErrorSeverity.ERROR; |
| 56 } | 34 } |
| 57 | 35 |
| 58 return error.errorCode.errorSeverity; | 36 return error.errorCode.errorSeverity; |
| 59 } | 37 } |
| 38 |
| 39 /// Check various configuration options to get a desired severity for this |
| 40 /// [error] (or `null` if it's to be suppressed). |
| 41 ErrorSeverity determineProcessedSeverity(AnalysisError error, |
| 42 CommandLineOptions commandLineOptions, AnalysisOptions analysisOptions) { |
| 43 ErrorSeverity severity = |
| 44 computeSeverity(error, commandLineOptions, analysisOptions); |
| 45 // Skip TODOs categorically unless escalated to ERROR or HINT (#26215). |
| 46 if (error.errorCode.type == ErrorType.TODO && |
| 47 severity == ErrorSeverity.INFO) { |
| 48 return null; |
| 49 } |
| 50 |
| 51 // TODO(devoncarew): We should not filter hints here. |
| 52 // If not overridden, some "natural" severities get globally filtered. |
| 53 // Check for global hint filtering. |
| 54 if (severity == ErrorSeverity.INFO && commandLineOptions.disableHints) { |
| 55 return null; |
| 56 } |
| 57 |
| 58 return severity; |
| 59 } |
| OLD | NEW |