Skip to content

Commit 72e7e43

Browse files
committed
Fix #121, fix #186: remove --silent,-s flag: be silent by default
1 parent 9ec959f commit 72e7e43

File tree

7 files changed

+19
-35
lines changed

7 files changed

+19
-35
lines changed

.golangci.example.yml

-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ run:
3636
- ".*\\.my\\.go$"
3737
- lib/bad.go
3838

39-
# whether to hide "congrats" message if no issues were found,
40-
# default is false (show "congrats" message by default).
41-
# set this option to true to print nothing if no issues were found.
42-
silent: true
43-
4439

4540
# output configuration options
4641
output:

README.md

-6
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ Global Flags:
397397
-j, --concurrency int Concurrency (default NumCPU) (default 8)
398398
--cpu-profile-path string Path to CPU profile output file
399399
--mem-profile-path string Path to memory profile output file
400-
-s, --silent disables congrats outputs
401400
-v, --verbose verbose output
402401
403402
```
@@ -455,11 +454,6 @@ run:
455454
- ".*\\.my\\.go$"
456455
- lib/bad.go
457456

458-
# whether to hide "congrats" message if no issues were found,
459-
# default is false (show "congrats" message by default).
460-
# set this option to true to print nothing if no issues were found.
461-
silent: true
462-
463457

464458
# output configuration options
465459
output:

pkg/commands/root.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,18 @@ 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"))
86+
87+
var silent bool
88+
fs.BoolVarP(&silent, "silent", "s", false, wh("disables congrats outputs"))
89+
if err := fs.MarkHidden("silent"); err != nil {
90+
panic(err)
91+
}
92+
err := fs.MarkDeprecated("silent",
93+
"now golangci-lint by default is silent: it doesn't print Congrats message")
94+
if err != nil {
95+
panic(err)
96+
}
97+
8798
fs.StringVar(&cfg.Run.CPUProfilePath, "cpu-profile-path", "", wh("Path to CPU profile output file"))
8899
fs.StringVar(&cfg.Run.MemProfilePath, "mem-profile-path", "", wh("Path to memory profile output file"))
89100
fs.IntVarP(&cfg.Run.Concurrency, "concurrency", "j", getDefaultConcurrency(), wh("Concurrency (default NumCPU)"))

pkg/commands/run.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,10 @@ func (e *Executor) createPrinter() (printers.Printer, error) {
313313
p = printers.NewJSON(&e.reportData)
314314
case config.OutFormatColoredLineNumber, config.OutFormatLineNumber:
315315
p = printers.NewText(e.cfg.Output.PrintIssuedLine,
316-
format == config.OutFormatColoredLineNumber, e.cfg.Output.PrintLinterName, e.cfg.Run.Silent,
316+
format == config.OutFormatColoredLineNumber, e.cfg.Output.PrintLinterName,
317317
e.log.Child("text_printer"))
318318
case config.OutFormatTab:
319-
p = printers.NewTab(e.cfg.Output.PrintLinterName, e.cfg.Run.Silent,
320-
e.log.Child("tab_printer"))
319+
p = printers.NewTab(e.cfg.Output.PrintLinterName, e.log.Child("tab_printer"))
321320
case config.OutFormatCheckstyle:
322321
p = printers.NewCheckstyle()
323322
default:

pkg/printers/tab.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ import (
1313

1414
type Tab struct {
1515
printLinterName bool
16-
silent bool
1716
log logutils.Log
1817
}
1918

20-
func NewTab(printLinterName bool, silent bool, log logutils.Log) *Tab {
19+
func NewTab(printLinterName bool, log logutils.Log) *Tab {
2120
return &Tab{
2221
printLinterName: printLinterName,
23-
silent: silent,
2422
log: log,
2523
}
2624
}
@@ -41,11 +39,6 @@ func (p *Tab) Print(ctx context.Context, issues <-chan result.Issue) (bool, erro
4139

4240
if issuesN != 0 {
4341
p.log.Infof("Found %d issues", issuesN)
44-
} else if ctx.Err() == nil { // don't print "congrats" if timeouted
45-
if !p.silent {
46-
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
47-
fmt.Fprintln(logutils.StdOut, outStr)
48-
}
4942
}
5043

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

pkg/printers/text.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,16 @@ type Text struct {
1919
printIssuedLine bool
2020
useColors bool
2121
printLinterName bool
22-
silent bool
2322

2423
cache filesCache
2524
log logutils.Log
2625
}
2726

28-
func NewText(printIssuedLine, useColors, printLinterName bool, silent bool, log logutils.Log) *Text {
27+
func NewText(printIssuedLine, useColors, printLinterName bool, log logutils.Log) *Text {
2928
return &Text{
3029
printIssuedLine: printIssuedLine,
3130
useColors: useColors,
3231
printLinterName: printLinterName,
33-
silent: silent,
3432
cache: filesCache{},
3533
log: log,
3634
}
@@ -92,11 +90,6 @@ func (p *Text) Print(ctx context.Context, issues <-chan result.Issue) (bool, err
9290

9391
if issuesN != 0 {
9492
p.log.Infof("Found %d issues", issuesN)
95-
} else if ctx.Err() == nil { // don't print "congrats" if timeouted
96-
if !p.silent {
97-
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
98-
fmt.Fprintln(logutils.StdOut, outStr)
99-
}
10093
}
10194

10295
return issuesN != 0, nil

test/run_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
var root = filepath.Join("..", "...")
2323
var installOnce sync.Once
2424

25-
const noIssuesOut = "Congrats! No issues were found.\n"
25+
const noIssuesOut = ""
2626

2727
func installBinary(t assert.TestingT) {
2828
installOnce.Do(func() {
@@ -36,8 +36,8 @@ func checkNoIssuesRun(t *testing.T, out string, exitCode int) {
3636
assert.Equal(t, noIssuesOut, out)
3737
}
3838

39-
func TestCongratsMessageGoneIfSilent(t *testing.T) {
40-
out, exitCode := runGolangciLint(t, "../...", "-s")
39+
func TestNoCongratsMessage(t *testing.T) {
40+
out, exitCode := runGolangciLint(t, "../...")
4141
assert.Equal(t, exitcodes.Success, exitCode)
4242
assert.Equal(t, "", out)
4343
}
@@ -72,7 +72,6 @@ func TestDeadline(t *testing.T) {
7272
out, exitCode := runGolangciLint(t, "--deadline=1ms", root)
7373
assert.Equal(t, exitcodes.Timeout, exitCode)
7474
assert.Contains(t, out, "deadline exceeded: try increase it by passing --deadline option")
75-
assert.NotContains(t, out, "Congrats! No issues were found.")
7675
}
7776

7877
func runGolangciLint(t *testing.T, args ...string) (string, int) {

0 commit comments

Comments
 (0)