Skip to content

Commit 86d8ff6

Browse files
committed
disable the congrats message
There is now an extra switch '-s' to disable the congrats message when there are no issues detected Fixes: golangci#110
1 parent 7f1779d commit 86d8ff6

File tree

9 files changed

+51
-18
lines changed

9 files changed

+51
-18
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, --no-congrats disable congrats output
297298
-v, --verbose verbose output
298299
299300
```

pkg/commands/root.go

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

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

pkg/commands/run.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,16 @@ func (e *Executor) runAndPrint(ctx context.Context, args []string) error {
255255
format := e.cfg.Output.Format
256256
switch format {
257257
case config.OutFormatJSON:
258-
p = printers.NewJSON()
258+
p = printers.NewJSON(e.cfg.Run.DisableCongrats)
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.DisableCongrats,
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.DisableCongrats,
265265
e.log.Child("tab_printer"))
266266
case config.OutFormatCheckstyle:
267-
p = printers.NewCheckstyle()
267+
p = printers.NewCheckstyle(e.cfg.Run.DisableCongrats)
268268
default:
269269
return fmt.Errorf("unknown output format %s", format)
270270
}

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+
DisableCongrats bool
9596
CPUProfilePath string
9697
MemProfilePath string
9798
Concurrency int

pkg/printers/checkstyle.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ type checkstyleError struct {
2929

3030
const defaultSeverity = "error"
3131

32-
type Checkstyle struct{}
32+
type Checkstyle struct {
33+
disableCongrats bool
34+
}
3335

34-
func NewCheckstyle() *Checkstyle {
35-
return &Checkstyle{}
36+
func NewCheckstyle(disableCongrats bool) *Checkstyle {
37+
return &Checkstyle{
38+
disableCongrats: disableCongrats,
39+
}
3640
}
3741

38-
func (Checkstyle) Print(ctx context.Context, issues <-chan result.Issue) (bool, error) {
42+
func (c Checkstyle) Print(ctx context.Context, issues <-chan result.Issue) (bool, error) {
3943
out := checkstyleOutput{
4044
Version: "5.0",
4145
}
@@ -63,6 +67,10 @@ func (Checkstyle) Print(ctx context.Context, issues <-chan result.Issue) (bool,
6367
file.Errors = append(file.Errors, newError)
6468
}
6569

70+
if len(files) == 0 && c.disableCongrats {
71+
return true, nil
72+
}
73+
6674
out.Files = make([]*checkstyleFile, 0, len(files))
6775
for _, file := range files {
6876
out.Files = append(out.Files, file)

pkg/printers/json.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,30 @@ import (
88
"github.com/golangci/golangci-lint/pkg/result"
99
)
1010

11-
type JSON struct{}
11+
type JSON struct {
12+
disableCongrats bool
13+
}
1214

13-
func NewJSON() *JSON {
14-
return &JSON{}
15+
func NewJSON(disableCongrats bool) *JSON {
16+
return &JSON{
17+
disableCongrats: disableCongrats,
18+
}
1519
}
1620

1721
type JSONResult struct {
1822
Issues []result.Issue
1923
}
2024

21-
func (JSON) Print(ctx context.Context, issues <-chan result.Issue) (bool, error) {
25+
func (j JSON) Print(ctx context.Context, issues <-chan result.Issue) (bool, error) {
2226
allIssues := []result.Issue{}
2327
for i := range issues {
2428
allIssues = append(allIssues, i)
2529
}
2630

31+
if len(allIssues) == 0 && j.disableCongrats {
32+
return true, nil
33+
}
34+
2735
res := JSONResult{
2836
Issues: allIssues,
2937
}

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+
disableCongrats bool
1617
log logutils.Log
1718
}
1819

19-
func NewTab(printLinterName bool, log logutils.Log) *Tab {
20+
func NewTab(printLinterName bool, disableCongrats bool, log logutils.Log) *Tab {
2021
return &Tab{
2122
printLinterName: printLinterName,
23+
disableCongrats: disableCongrats,
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(StdOut, outStr)
45+
if !p.disableCongrats {
46+
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
47+
fmt.Fprintln(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+
disableCongrats 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, disableCongrats bool, log logutils.Log) *Text {
2930
return &Text{
3031
printIssuedLine: printIssuedLine,
3132
useColors: useColors,
3233
printLinterName: printLinterName,
34+
disableCongrats: disableCongrats,
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(StdOut, outStr)
97+
if !p.disableCongrats {
98+
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
99+
fmt.Fprintln(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 TestCongratsMessageGoneIfNoIssuesAndDisableCongrats(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)