Skip to content

disable the congrats message #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ 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
1 change: 1 addition & 0 deletions pkg/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ 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"))
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
4 changes: 2 additions & 2 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ func (e *Executor) runAndPrint(ctx context.Context, args []string) error {
p = printers.NewJSON()
case config.OutFormatColoredLineNumber, config.OutFormatLineNumber:
p = printers.NewText(e.cfg.Output.PrintIssuedLine,
format == config.OutFormatColoredLineNumber, e.cfg.Output.PrintLinterName,
format == config.OutFormatColoredLineNumber, e.cfg.Output.PrintLinterName, e.cfg.Run.Silent,
e.log.Child("text_printer"))
case config.OutFormatTab:
p = printers.NewTab(e.cfg.Output.PrintLinterName,
p = printers.NewTab(e.cfg.Output.PrintLinterName, e.cfg.Run.Silent,
e.log.Child("tab_printer"))
case config.OutFormatCheckstyle:
p = printers.NewCheckstyle()
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func GetDefaultExcludePatternsStrings() []string {

type Run struct {
IsVerbose bool `mapstructure:"verbose"`
Silent bool
CPUProfilePath string
MemProfilePath string
Concurrency int
Expand Down
10 changes: 7 additions & 3 deletions pkg/printers/tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import (

type Tab struct {
printLinterName bool
silent bool
log logutils.Log
}

func NewTab(printLinterName bool, log logutils.Log) *Tab {
func NewTab(printLinterName bool, silent bool, log logutils.Log) *Tab {
return &Tab{
printLinterName: printLinterName,
silent: silent,
log: log,
}
}
Expand All @@ -40,8 +42,10 @@ 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
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
fmt.Fprintln(logutils.StdOut, outStr)
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
10 changes: 7 additions & 3 deletions pkg/printers/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ type Text struct {
printIssuedLine bool
useColors bool
printLinterName bool
silent bool

cache filesCache
log logutils.Log
}

func NewText(printIssuedLine, useColors, printLinterName bool, log logutils.Log) *Text {
func NewText(printIssuedLine, useColors, printLinterName bool, silent bool, log logutils.Log) *Text {
return &Text{
printIssuedLine: printIssuedLine,
useColors: useColors,
printLinterName: printLinterName,
silent: silent,
cache: filesCache{},
log: log,
}
Expand Down Expand Up @@ -92,8 +94,10 @@ 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
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
fmt.Fprintln(logutils.StdOut, outStr)
if !p.silent {
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
fmt.Fprintln(logutils.StdOut, outStr)
}
}

return issuesN != 0, nil
Expand Down
6 changes: 6 additions & 0 deletions test/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ func checkNoIssuesRun(t *testing.T, out string, exitCode int) {
assert.Equal(t, "Congrats! No issues were found.\n", out)
}

func TestCongratsMessageGoneIfSilent(t *testing.T) {
out, exitCode := runGolangciLint(t, "../...", "-s")
assert.Equal(t, exitcodes.Success, exitCode)
assert.Equal(t, "", out)
}

func TestCongratsMessageIfNoIssues(t *testing.T) {
out, exitCode := runGolangciLint(t, "../...")
checkNoIssuesRun(t, out, exitCode)
Expand Down