Fix #121, fix #186: remove --silent,-s flag: be silent by default

This commit is contained in:
Denis Isaev 2018-08-08 23:47:19 +03:00 committed by Isaev Denis
parent 9ec959f08e
commit b900926bfc
7 changed files with 19 additions and 35 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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)"))

View File

@ -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:

View File

@ -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 {

View File

@ -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

View File

@ -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) {