
1. Log all warnings, don't hide none of them 2. Write fatal messages (stop analysis) with error log level 3. Remove ugly timestamp counter from logrus output 4. Print nested module prefix in log 5. Make logger abstraction: no global logging anymore 6. Refactor config reading to config.FileReader struct to avoid passing logger into every function 7. Replace exit codes hardcoding with constants in exitcodes package 8. Fail test if any warning was logged 9. Fix calculation of relative path if we analyze parent dir ../ 10. Move Runner initialization from Executor to NewRunner func 11. Log every AST parsing error 12. Properly print used config file path in verbose mode 13. Print package files if only 1 package is analyzedin verbose mode, print not compiling packages in verbose mode 14. Forbid usage of github.com/sirupsen/logrus by DepGuard linter 15. Add default ignore pattern to folint: "comment on exported const"
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
package printers
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"text/tabwriter"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/golangci/golangci-lint/pkg/logutils"
|
|
"github.com/golangci/golangci-lint/pkg/result"
|
|
)
|
|
|
|
type Tab struct {
|
|
printLinterName bool
|
|
log logutils.Log
|
|
}
|
|
|
|
func NewTab(printLinterName bool, log logutils.Log) *Tab {
|
|
return &Tab{
|
|
printLinterName: printLinterName,
|
|
log: log,
|
|
}
|
|
}
|
|
|
|
func (p Tab) SprintfColored(ca color.Attribute, format string, args ...interface{}) string {
|
|
c := color.New(ca)
|
|
return c.Sprintf(format, args...)
|
|
}
|
|
|
|
func (p *Tab) Print(ctx context.Context, issues <-chan result.Issue) (bool, error) {
|
|
w := tabwriter.NewWriter(StdOut, 0, 0, 2, ' ', 0)
|
|
|
|
issuesN := 0
|
|
for i := range issues {
|
|
issuesN++
|
|
p.printIssue(&i, w)
|
|
}
|
|
|
|
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(StdOut, outStr)
|
|
}
|
|
|
|
if err := w.Flush(); err != nil {
|
|
p.log.Warnf("Can't flush tab writer: %s", err)
|
|
}
|
|
|
|
return issuesN != 0, nil
|
|
}
|
|
|
|
func (p Tab) printIssue(i *result.Issue, w io.Writer) {
|
|
text := p.SprintfColored(color.FgRed, "%s", i.Text)
|
|
if p.printLinterName {
|
|
text = fmt.Sprintf("%s\t%s", i.FromLinter, text)
|
|
}
|
|
|
|
pos := p.SprintfColored(color.Bold, "%s:%d", i.FilePath(), i.Line())
|
|
if i.Pos.Column != 0 {
|
|
pos += fmt.Sprintf(":%d", i.Pos.Column)
|
|
}
|
|
|
|
fmt.Fprintf(w, "%s\t%s\n", pos, text)
|
|
}
|