Skip to content

Commit

Permalink
Fix #121, fix #186: remove --silent,-s flag: be silent by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jirfag committed Aug 8, 2018
1 parent 9ec959f commit b900926
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 35 deletions.
5 changes: 0 additions & 5 deletions .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion pkg/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"))
Expand Down
5 changes: 2 additions & 3 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 1 addition & 8 deletions pkg/printers/tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand All @@ -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 {
Expand Down
9 changes: 1 addition & 8 deletions pkg/printers/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions test/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b900926

Please sign in to comment.