Skip to content

Commit 0856761

Browse files
authored
feat: support --max-warnings (#118)
1 parent d95aecc commit 0856761

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

cmd/rslint/cmd.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,15 @@ Usage:
315315
rslint [OPTIONS]
316316
317317
Options:
318-
--config PATH Which rslint config file to use. Defaults to rslint.json.
319-
--list-files List matched files
320-
--format FORMAT Output format: default | jsonline
321-
--fix Automatically fix problems
322-
--no-color Disable colored output
323-
--force-color Force colored output
324-
--quiet Report errors only
325-
-h, --help Show help
318+
--config PATH Which rslint config file to use. Defaults to rslint.json.
319+
--list-files List matched files
320+
--format FORMAT Output format: default | jsonline
321+
--fix Automatically fix problems
322+
--no-color Disable colored output
323+
--force-color Force colored output
324+
--quiet Report errors only
325+
--max-warnings Int Number of warnings to trigger nonzero exit code
326+
-h, --help Show help
326327
`
327328

328329
func runCMD() int {
@@ -341,6 +342,7 @@ func runCMD() int {
341342
noColor bool
342343
forceColor bool
343344
quiet bool
345+
maxWarnings int
344346
)
345347
flag.StringVar(&format, "format", "default", "output format")
346348
flag.StringVar(&config, "config", "", "which rslint config to use")
@@ -351,6 +353,7 @@ func runCMD() int {
351353
flag.BoolVar(&noColor, "no-color", false, "disable colored output")
352354
flag.BoolVar(&forceColor, "force-color", false, "force colored output")
353355
flag.BoolVar(&quiet, "quiet", false, "report errors only")
356+
flag.IntVar(&maxWarnings, "max-warnings", -1, "Number of warnings to trigger nonzero exit code")
354357

355358
flag.StringVar(&traceOut, "trace", "", "file to put trace to")
356359
flag.StringVar(&cpuprofOut, "cpuprof", "", "file to put cpu profiling to")
@@ -628,8 +631,17 @@ func runCMD() int {
628631
}
629632
}
630633

634+
tooManyWarnings := false
635+
if maxWarnings >= 0 && warningsCount > maxWarnings {
636+
tooManyWarnings = true
637+
}
638+
639+
if errorsCount == 0 && tooManyWarnings {
640+
fmt.Fprintf(os.Stderr, "Rslint found too many warnings (maximum: %d).\n", maxWarnings)
641+
}
642+
631643
// Exit with non-zero status code if errors were found
632-
if errorsCount > 0 {
644+
if errorsCount > 0 || tooManyWarnings {
633645
return 1
634646
}
635647
return 0

0 commit comments

Comments
 (0)