@@ -26,20 +26,28 @@ final class DiagnosticsEngine {
26
26
/// A Boolean value indicating whether any warnings were emitted by the diagnostics engine.
27
27
private( set) var hasWarnings : Bool
28
28
29
+ /// Whether to upgrade all warnings to errors.
30
+ private let treatWarningsAsErrors : Bool
31
+
29
32
/// Creates a new diagnostics engine with the given diagnostic handlers.
30
33
///
31
34
/// - Parameter diagnosticsHandlers: An array of functions, each of which takes a `Diagnostic` as
32
35
/// its sole argument and returns `Void`. The functions are called whenever a diagnostic is
33
36
/// received by the engine.
34
- init ( diagnosticsHandlers: [ ( Diagnostic ) -> Void ] ) {
37
+ init ( diagnosticsHandlers: [ ( Diagnostic ) -> Void ] , treatWarningsAsErrors : Bool = false ) {
35
38
self . handlers = diagnosticsHandlers
36
39
self . hasErrors = false
37
40
self . hasWarnings = false
41
+ self . treatWarningsAsErrors = treatWarningsAsErrors
38
42
}
39
43
40
44
/// Emits the diagnostic by passing it to the registered handlers, and tracks whether it was an
41
45
/// error or warning diagnostic.
42
46
private func emit( _ diagnostic: Diagnostic ) {
47
+ var diagnostic = diagnostic
48
+ if treatWarningsAsErrors, diagnostic. severity == . warning {
49
+ diagnostic. severity = . error
50
+ }
43
51
switch diagnostic. severity {
44
52
case . error: self . hasErrors = true
45
53
case . warning: self . hasWarnings = true
@@ -135,7 +143,7 @@ final class DiagnosticsEngine {
135
143
/// diagnostics engine and returns it.
136
144
private func diagnosticMessage( for finding: Finding ) -> Diagnostic {
137
145
return Diagnostic (
138
- severity: . error ,
146
+ severity: . warning ,
139
147
location: finding. location. map ( Diagnostic . Location. init) ,
140
148
category: " \( finding. category) " ,
141
149
message: " \( finding. message. text) "
0 commit comments