From b900926bfc404297e92b72db879894e894a97be9 Mon Sep 17 00:00:00 2001 From: Denis Isaev Date: Wed, 8 Aug 2018 23:47:19 +0300 Subject: [PATCH] Fix #121, fix #186: remove --silent,-s flag: be silent by default --- .golangci.example.yml | 5 ----- README.md | 6 ------ pkg/commands/root.go | 13 ++++++++++++- pkg/commands/run.go | 5 ++--- pkg/printers/tab.go | 9 +-------- pkg/printers/text.go | 9 +-------- test/run_test.go | 7 +++---- 7 files changed, 19 insertions(+), 35 deletions(-) diff --git a/.golangci.example.yml b/.golangci.example.yml index 49800b62..5f7d5d88 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -36,11 +36,6 @@ run: - ".*\\.my\\.go$" - lib/bad.go - # whether to hide "congrats" message if no issues were found, - # default is false (show "congrats" message by default). - # set this option to true to print nothing if no issues were found. - silent: true - # output configuration options output: diff --git a/README.md b/README.md index 4578fa12..abec081c 100644 --- a/README.md +++ b/README.md @@ -397,7 +397,6 @@ Global Flags: -j, --concurrency int Concurrency (default NumCPU) (default 8) --cpu-profile-path string Path to CPU profile output file --mem-profile-path string Path to memory profile output file - -s, --silent disables congrats outputs -v, --verbose verbose output ``` @@ -455,11 +454,6 @@ run: - ".*\\.my\\.go$" - lib/bad.go - # whether to hide "congrats" message if no issues were found, - # default is false (show "congrats" message by default). - # set this option to true to print nothing if no issues were found. - silent: true - # output configuration options output: diff --git a/pkg/commands/root.go b/pkg/commands/root.go index 2f0543a9..1ddf2302 100644 --- a/pkg/commands/root.go +++ b/pkg/commands/root.go @@ -83,7 +83,18 @@ func (e *Executor) needVersionOption() bool { func initRootFlagSet(fs *pflag.FlagSet, cfg *config.Config, needVersionOption bool) { fs.BoolVarP(&cfg.Run.IsVerbose, "verbose", "v", false, wh("verbose output")) - fs.BoolVarP(&cfg.Run.Silent, "silent", "s", false, wh("disables congrats outputs")) + + var silent bool + fs.BoolVarP(&silent, "silent", "s", false, wh("disables congrats outputs")) + if err := fs.MarkHidden("silent"); err != nil { + panic(err) + } + err := fs.MarkDeprecated("silent", + "now golangci-lint by default is silent: it doesn't print Congrats message") + if err != nil { + panic(err) + } + fs.StringVar(&cfg.Run.CPUProfilePath, "cpu-profile-path", "", wh("Path to CPU profile output file")) fs.StringVar(&cfg.Run.MemProfilePath, "mem-profile-path", "", wh("Path to memory profile output file")) fs.IntVarP(&cfg.Run.Concurrency, "concurrency", "j", getDefaultConcurrency(), wh("Concurrency (default NumCPU)")) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 64421be0..94be156d 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -313,11 +313,10 @@ func (e *Executor) createPrinter() (printers.Printer, error) { p = printers.NewJSON(&e.reportData) case config.OutFormatColoredLineNumber, config.OutFormatLineNumber: p = printers.NewText(e.cfg.Output.PrintIssuedLine, - format == config.OutFormatColoredLineNumber, e.cfg.Output.PrintLinterName, e.cfg.Run.Silent, + format == config.OutFormatColoredLineNumber, e.cfg.Output.PrintLinterName, e.log.Child("text_printer")) case config.OutFormatTab: - p = printers.NewTab(e.cfg.Output.PrintLinterName, e.cfg.Run.Silent, - e.log.Child("tab_printer")) + p = printers.NewTab(e.cfg.Output.PrintLinterName, e.log.Child("tab_printer")) case config.OutFormatCheckstyle: p = printers.NewCheckstyle() default: diff --git a/pkg/printers/tab.go b/pkg/printers/tab.go index 0dfba125..fe0373c9 100644 --- a/pkg/printers/tab.go +++ b/pkg/printers/tab.go @@ -13,14 +13,12 @@ import ( type Tab struct { printLinterName bool - silent bool log logutils.Log } -func NewTab(printLinterName bool, silent bool, log logutils.Log) *Tab { +func NewTab(printLinterName bool, log logutils.Log) *Tab { return &Tab{ printLinterName: printLinterName, - silent: silent, log: log, } } @@ -41,11 +39,6 @@ func (p *Tab) Print(ctx context.Context, issues <-chan result.Issue) (bool, erro if issuesN != 0 { p.log.Infof("Found %d issues", issuesN) - } else if ctx.Err() == nil { // don't print "congrats" if timeouted - if !p.silent { - outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.") - fmt.Fprintln(logutils.StdOut, outStr) - } } if err := w.Flush(); err != nil { diff --git a/pkg/printers/text.go b/pkg/printers/text.go index c2d7e205..2133f085 100644 --- a/pkg/printers/text.go +++ b/pkg/printers/text.go @@ -19,18 +19,16 @@ type Text struct { printIssuedLine bool useColors bool printLinterName bool - silent bool cache filesCache log logutils.Log } -func NewText(printIssuedLine, useColors, printLinterName bool, silent bool, log logutils.Log) *Text { +func NewText(printIssuedLine, useColors, printLinterName bool, log logutils.Log) *Text { return &Text{ printIssuedLine: printIssuedLine, useColors: useColors, printLinterName: printLinterName, - silent: silent, cache: filesCache{}, log: log, } @@ -92,11 +90,6 @@ func (p *Text) Print(ctx context.Context, issues <-chan result.Issue) (bool, err if issuesN != 0 { p.log.Infof("Found %d issues", issuesN) - } else if ctx.Err() == nil { // don't print "congrats" if timeouted - if !p.silent { - outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.") - fmt.Fprintln(logutils.StdOut, outStr) - } } return issuesN != 0, nil diff --git a/test/run_test.go b/test/run_test.go index 2c4216b4..ae370be2 100644 --- a/test/run_test.go +++ b/test/run_test.go @@ -22,7 +22,7 @@ import ( var root = filepath.Join("..", "...") var installOnce sync.Once -const noIssuesOut = "Congrats! No issues were found.\n" +const noIssuesOut = "" func installBinary(t assert.TestingT) { installOnce.Do(func() { @@ -36,8 +36,8 @@ func checkNoIssuesRun(t *testing.T, out string, exitCode int) { assert.Equal(t, noIssuesOut, out) } -func TestCongratsMessageGoneIfSilent(t *testing.T) { - out, exitCode := runGolangciLint(t, "../...", "-s") +func TestNoCongratsMessage(t *testing.T) { + out, exitCode := runGolangciLint(t, "../...") assert.Equal(t, exitcodes.Success, exitCode) assert.Equal(t, "", out) } @@ -72,7 +72,6 @@ func TestDeadline(t *testing.T) { out, exitCode := runGolangciLint(t, "--deadline=1ms", root) assert.Equal(t, exitcodes.Timeout, exitCode) assert.Contains(t, out, "deadline exceeded: try increase it by passing --deadline option") - assert.NotContains(t, out, "Congrats! No issues were found.") } func runGolangciLint(t *testing.T, args ...string) (string, int) {