Skip to content

Commit f239b80

Browse files
dahankzterjirfag
authored andcommitted
disable the congrats message
There is now an extra switch '-s' to disable the congrats message when there are no issues detected Fixes: #110
1 parent 2de1f87 commit f239b80

File tree

7 files changed

+25
-8
lines changed

7 files changed

+25
-8
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ Global Flags:
294294
-j, --concurrency int Concurrency (default NumCPU) (default 8)
295295
--cpu-profile-path string Path to CPU profile output file
296296
--mem-profile-path string Path to memory profile output file
297+
-s, --silent disables congrats outputs
297298
-v, --verbose verbose output
298299
299300
```

pkg/commands/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (e *Executor) needVersionOption() bool {
8383

8484
func initRootFlagSet(fs *pflag.FlagSet, cfg *config.Config, needVersionOption bool) {
8585
fs.BoolVarP(&cfg.Run.IsVerbose, "verbose", "v", false, wh("verbose output"))
86+
fs.BoolVarP(&cfg.Run.Silent, "silent", "s", false, wh("disables congrats outputs"))
8687
fs.StringVar(&cfg.Run.CPUProfilePath, "cpu-profile-path", "", wh("Path to CPU profile output file"))
8788
fs.StringVar(&cfg.Run.MemProfilePath, "mem-profile-path", "", wh("Path to memory profile output file"))
8889
fs.IntVarP(&cfg.Run.Concurrency, "concurrency", "j", getDefaultConcurrency(), wh("Concurrency (default NumCPU)"))

pkg/commands/run.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ func (e *Executor) runAndPrint(ctx context.Context, args []string) error {
258258
p = printers.NewJSON()
259259
case config.OutFormatColoredLineNumber, config.OutFormatLineNumber:
260260
p = printers.NewText(e.cfg.Output.PrintIssuedLine,
261-
format == config.OutFormatColoredLineNumber, e.cfg.Output.PrintLinterName,
261+
format == config.OutFormatColoredLineNumber, e.cfg.Output.PrintLinterName, e.cfg.Run.Silent,
262262
e.log.Child("text_printer"))
263263
case config.OutFormatTab:
264-
p = printers.NewTab(e.cfg.Output.PrintLinterName,
264+
p = printers.NewTab(e.cfg.Output.PrintLinterName, e.cfg.Run.Silent,
265265
e.log.Child("tab_printer"))
266266
case config.OutFormatCheckstyle:
267267
p = printers.NewCheckstyle()

pkg/config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func GetDefaultExcludePatternsStrings() []string {
9292

9393
type Run struct {
9494
IsVerbose bool `mapstructure:"verbose"`
95+
Silent bool
9596
CPUProfilePath string
9697
MemProfilePath string
9798
Concurrency int

pkg/printers/tab.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ import (
1313

1414
type Tab struct {
1515
printLinterName bool
16+
silent bool
1617
log logutils.Log
1718
}
1819

19-
func NewTab(printLinterName bool, log logutils.Log) *Tab {
20+
func NewTab(printLinterName bool, silent bool, log logutils.Log) *Tab {
2021
return &Tab{
2122
printLinterName: printLinterName,
23+
silent: silent,
2224
log: log,
2325
}
2426
}
@@ -40,8 +42,10 @@ func (p *Tab) Print(ctx context.Context, issues <-chan result.Issue) (bool, erro
4042
if issuesN != 0 {
4143
p.log.Infof("Found %d issues", issuesN)
4244
} else if ctx.Err() == nil { // don't print "congrats" if timeouted
43-
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
44-
fmt.Fprintln(logutils.StdOut, outStr)
45+
if !p.silent {
46+
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
47+
fmt.Fprintln(logutils.StdOut, outStr)
48+
}
4549
}
4650

4751
if err := w.Flush(); err != nil {

pkg/printers/text.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ type Text struct {
2020
printIssuedLine bool
2121
useColors bool
2222
printLinterName bool
23+
silent bool
2324

2425
cache filesCache
2526
log logutils.Log
2627
}
2728

28-
func NewText(printIssuedLine, useColors, printLinterName bool, log logutils.Log) *Text {
29+
func NewText(printIssuedLine, useColors, printLinterName bool, silent bool, log logutils.Log) *Text {
2930
return &Text{
3031
printIssuedLine: printIssuedLine,
3132
useColors: useColors,
3233
printLinterName: printLinterName,
34+
silent: silent,
3335
cache: filesCache{},
3436
log: log,
3537
}
@@ -92,8 +94,10 @@ func (p *Text) Print(ctx context.Context, issues <-chan result.Issue) (bool, err
9294
if issuesN != 0 {
9395
p.log.Infof("Found %d issues", issuesN)
9496
} else if ctx.Err() == nil { // don't print "congrats" if timeouted
95-
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
96-
fmt.Fprintln(logutils.StdOut, outStr)
97+
if !p.silent {
98+
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
99+
fmt.Fprintln(logutils.StdOut, outStr)
100+
}
97101
}
98102

99103
return issuesN != 0, nil

test/run_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ func checkNoIssuesRun(t *testing.T, out string, exitCode int) {
3333
assert.Equal(t, "Congrats! No issues were found.\n", out)
3434
}
3535

36+
func TestCongratsMessageGoneIfSilent(t *testing.T) {
37+
out, exitCode := runGolangciLint(t, "../...", "-s")
38+
assert.Equal(t, exitcodes.Success, exitCode)
39+
assert.Equal(t, "", out)
40+
}
41+
3642
func TestCongratsMessageIfNoIssues(t *testing.T) {
3743
out, exitCode := runGolangciLint(t, "../...")
3844
checkNoIssuesRun(t, out, exitCode)

0 commit comments

Comments
 (0)