@@ -13,6 +13,7 @@ type Arguments =
13
13
| Project of string list
14
14
| Analyzers_ Path of string
15
15
| Fail_ On_ Warnings of string list
16
+ | Fail_ On_ All_ Warnings of except : string list
16
17
| Ignore_ Files of string list
17
18
| Exclude_ Analyzer of string list
18
19
| Report of string
@@ -25,11 +26,17 @@ type Arguments =
25
26
| Analyzers_ Path _ -> " Path to a folder where your analyzers are located."
26
27
| Fail_ On_ Warnings _ ->
27
28
" List of analyzer codes that should trigger tool failures in the presence of warnings."
29
+ | Fail_ On_ All_ Warnings _ ->
30
+ " All analyzer codes will trigger tool failure in the presence of warnings, except for the ones listed here."
28
31
| Ignore_ Files _ -> " Source files that shouldn't be processed."
29
32
| Exclude_ Analyzer _ -> " The names of analyzers that should not be executed."
30
33
| Report _ -> " Write the result messages to a (sarif) report file."
31
34
| Verbose -> " Verbose logging."
32
35
36
+ type WarningConfig =
37
+ | FailOnWarnings of string list
38
+ | FailOnAllWarnings of except : string list
39
+
33
40
let mutable verbose = false
34
41
35
42
let fcs = Utils.createFCS None
@@ -111,7 +118,7 @@ let runProject (client: Client<CliAnalyzerAttribute, CliContext>) toolsPath proj
111
118
]
112
119
}
113
120
114
- let printMessages failOnWarnings ( msgs : AnalyzerMessage list ) =
121
+ let printMessages warningConfig ( msgs : AnalyzerMessage list ) =
115
122
if verbose then
116
123
printfn " "
117
124
@@ -123,12 +130,13 @@ let printMessages failOnWarnings (msgs: AnalyzerMessage list) =
123
130
let m = analyzerMessage.Message
124
131
125
132
let color =
126
- match m.Severity with
127
- | Error -> ConsoleColor.Red
128
- | Warning when failOnWarnings |> List.contains m.Code -> ConsoleColor.Red
129
- | Warning -> ConsoleColor.DarkYellow
130
- | Info -> ConsoleColor.Blue
131
- | Hint -> ConsoleColor.Cyan
133
+ match m.Severity, warningConfig with
134
+ | Error, _ -> ConsoleColor.Red
135
+ | Warning, FailOnWarnings inclusions when inclusions |> List.contains m.Code -> ConsoleColor.Red
136
+ | Warning, FailOnAllWarnings exclusions when exclusions |> List.contains m.Code |> not -> ConsoleColor.Red
137
+ | Warning, _ -> ConsoleColor.DarkYellow
138
+ | Info, _ -> ConsoleColor.Blue
139
+ | Hint, _ -> ConsoleColor.Cyan
132
140
133
141
Console.ForegroundColor <- color
134
142
@@ -226,7 +234,7 @@ let writeReport (results: AnalyzerMessage list option) (report: string) =
226
234
let details = if not verbose then " " else $" %s {ex.Message}"
227
235
printfn $" Could not write sarif to %s {report}%s {details}"
228
236
229
- let calculateExitCode failOnWarnings ( msgs : AnalyzerMessage list option ) : int =
237
+ let calculateExitCode warningConfig ( msgs : AnalyzerMessage list option ) : int =
230
238
match msgs with
231
239
| None -> - 1
232
240
| Some msgs ->
@@ -235,8 +243,13 @@ let calculateExitCode failOnWarnings (msgs: AnalyzerMessage list option) : int =
235
243
|> List.exists ( fun analyzerMessage ->
236
244
let message = analyzerMessage.Message
237
245
238
- message.Severity = Error
239
- || ( message.Severity = Warning && failOnWarnings |> List.contains message.Code)
246
+ match warningConfig with
247
+ | FailOnWarnings inclusions ->
248
+ message.Severity = Error
249
+ || ( message.Severity = Warning && inclusions |> List.contains message.Code)
250
+ | FailOnAllWarnings exclusions ->
251
+ message.Severity = Error
252
+ || ( message.Severity = Warning && not ( exclusions |> List.contains message.Code))
240
253
)
241
254
242
255
if check then - 2 else 0
@@ -249,8 +262,22 @@ let main argv =
249
262
verbose <- results.Contains <@ Verbose @>
250
263
printInfo " Running in verbose mode"
251
264
252
- let failOnWarnings = results.GetResult(<@ Fail_ On_ Warnings @>, [])
253
- printInfo " Fail On Warnings: [%s ]" ( failOnWarnings |> String.concat " , " )
265
+ let warningConfig =
266
+ match results.TryGetResult(<@ Fail_ On_ All_ Warnings @>) with
267
+ | Some exceptions ->
268
+ match exceptions with
269
+ | [] ->
270
+ printInfo " Fail On All Warnings"
271
+ FailOnAllWarnings []
272
+ | _ ->
273
+ printInfo " Fail On All Warnings Except: [%s ]" ( exceptions |> String.concat " , " )
274
+ FailOnAllWarnings exceptions
275
+ | None ->
276
+ match results.TryGetResult(<@ Fail_ On_ Warnings @>) with
277
+ | Some inclusions ->
278
+ printInfo " Fail On Warnings: [%s ]" ( inclusions |> String.concat " , " )
279
+ FailOnWarnings inclusions
280
+ | None -> FailOnWarnings []
254
281
255
282
let ignoreFiles = results.GetResult(<@ Ignore_ Files @>, [])
256
283
printInfo " Ignore Files: [%s ]" ( ignoreFiles |> String.concat " , " )
@@ -309,7 +336,7 @@ let main argv =
309
336
Path.GetFullPath( Path.Combine( Environment.CurrentDirectory, proj))
310
337
311
338
let! results = runProject client toolsPath project ignoreFiles
312
- return results |> Option.map ( printMessages failOnWarnings )
339
+ return results |> Option.map ( printMessages warningConfig )
313
340
}
314
341
315
342
projects
@@ -322,4 +349,4 @@ let main argv =
322
349
323
350
report |> Option.iter ( writeReport results)
324
351
325
- calculateExitCode failOnWarnings results
352
+ calculateExitCode warningConfig results
0 commit comments