@@ -26,20 +26,28 @@ final class DiagnosticsEngine {
2626 /// A Boolean value indicating whether any warnings were emitted by the diagnostics engine.
2727 private( set) var hasWarnings : Bool
2828
29+ /// Whether to upgrade all warnings to errors.
30+ private let treatWarningsAsErrors : Bool
31+
2932 /// Creates a new diagnostics engine with the given diagnostic handlers.
3033 ///
3134 /// - Parameter diagnosticsHandlers: An array of functions, each of which takes a `Diagnostic` as
3235 /// its sole argument and returns `Void`. The functions are called whenever a diagnostic is
3336 /// received by the engine.
34- init ( diagnosticsHandlers: [ ( Diagnostic ) -> Void ] ) {
37+ init ( diagnosticsHandlers: [ ( Diagnostic ) -> Void ] , treatWarningsAsErrors : Bool = false ) {
3538 self . handlers = diagnosticsHandlers
3639 self . hasErrors = false
3740 self . hasWarnings = false
41+ self . treatWarningsAsErrors = treatWarningsAsErrors
3842 }
3943
4044 /// Emits the diagnostic by passing it to the registered handlers, and tracks whether it was an
4145 /// error or warning diagnostic.
4246 private func emit( _ diagnostic: Diagnostic ) {
47+ var diagnostic = diagnostic
48+ if treatWarningsAsErrors, diagnostic. severity == . warning {
49+ diagnostic. severity = . error
50+ }
4351 switch diagnostic. severity {
4452 case . error: self . hasErrors = true
4553 case . warning: self . hasWarnings = true
@@ -135,7 +143,7 @@ final class DiagnosticsEngine {
135143 /// diagnostics engine and returns it.
136144 private func diagnosticMessage( for finding: Finding ) -> Diagnostic {
137145 return Diagnostic (
138- severity: . error ,
146+ severity: . warning ,
139147 location: finding. location. map ( Diagnostic . Location. init) ,
140148 category: " \( finding. category) " ,
141149 message: " \( finding. message. text) "
0 commit comments