@@ -233,6 +233,11 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
233
233
fs .BoolVar (& ic .WholeFiles , "whole-files" , false ,
234
234
wh ("Show issues in any part of update files (requires new-from-rev or new-from-patch)" ))
235
235
fs .BoolVar (& ic .NeedFix , "fix" , false , "Fix found issues (if it's supported by the linter)" )
236
+
237
+ // Severities config
238
+ sc := & cfg .Severity
239
+ fs .StringSliceVar (& sc .FailOnSeverities , "fail-on-severities" , nil ,
240
+ wh ("Fail only if issues matching these severities are found" ))
236
241
}
237
242
238
243
func (e * Executor ) initRunConfiguration (cmd * cobra.Command ) {
@@ -371,8 +376,26 @@ func (e *Executor) setOutputToDevNull() (savedStdout, savedStderr *os.File) {
371
376
}
372
377
373
378
func (e * Executor ) setExitCodeIfIssuesFound (issues []result.Issue ) {
374
- if len (issues ) != 0 {
375
- e .exitCode = e .cfg .Run .ExitCodeIfIssuesFound
379
+ if len (issues ) == 0 {
380
+ return
381
+ }
382
+ // treat empty set of failure severities as "fail on all issues"
383
+ if len (e .cfg .Severity .FailOnSeverities ) == 0 {
384
+ if len (issues ) > 0 {
385
+ e .exitCode = e .cfg .Run .ExitCodeIfIssuesFound
386
+ }
387
+ return
388
+ }
389
+
390
+ failSeveritySet := map [string ]struct {}{}
391
+ for _ , s := range e .cfg .Severity .FailOnSeverities {
392
+ failSeveritySet [s ] = struct {}{}
393
+ }
394
+ for i := range issues {
395
+ if _ , isFailure := failSeveritySet [issues [i ].Severity ]; isFailure {
396
+ e .exitCode = e .cfg .Run .ExitCodeIfIssuesFound
397
+ return
398
+ }
376
399
}
377
400
}
378
401
0 commit comments