Skip to content

Commit

Permalink
output: add colored-tab
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Mar 25, 2023
1 parent 1f4fed7 commit 8cad751
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ run:

# output configuration options
output:
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity
# Format: colored-line-number|line-number|json|colored-tab|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity
#
# Multiple can be specified by separating them by comma, output can be provided
# for each of them by separating format name and path by colon symbol.
Expand Down
6 changes: 4 additions & 2 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,10 @@ func (e *Executor) createPrinter(format string, w io.Writer) (printers.Printer,
p = printers.NewText(e.cfg.Output.PrintIssuedLine,
format == config.OutFormatColoredLineNumber, e.cfg.Output.PrintLinterName,
e.log.Child(logutils.DebugKeyTextPrinter), w)
case config.OutFormatTab:
p = printers.NewTab(e.cfg.Output.PrintLinterName, e.log.Child(logutils.DebugKeyTabPrinter), w)
case config.OutFormatTab, config.OutFormatColoredTab:
p = printers.NewTab(e.cfg.Output.PrintLinterName,
format == config.OutFormatColoredTab,
e.log.Child(logutils.DebugKeyTabPrinter), w)
case config.OutFormatCheckstyle:
p = printers.NewCheckstyle(w)
case config.OutFormatCodeClimate:
Expand Down
1 change: 1 addition & 0 deletions pkg/config/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
OutFormatLineNumber = "line-number"
OutFormatColoredLineNumber = "colored-line-number"
OutFormatTab = "tab"
OutFormatColoredTab = "colored-tab"
OutFormatCheckstyle = "checkstyle"
OutFormatCodeClimate = "code-climate"
OutFormatHTML = "html"
Expand Down
14 changes: 11 additions & 3 deletions pkg/printers/tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,28 @@ import (

type Tab struct {
printLinterName bool
log logutils.Log
w io.Writer
useColors bool

log logutils.Log
w io.Writer
}

func NewTab(printLinterName bool, log logutils.Log, w io.Writer) *Tab {
func NewTab(printLinterName, useColors bool, log logutils.Log, w io.Writer) *Tab {
return &Tab{
printLinterName: printLinterName,
useColors: useColors,
log: log,
w: w,
}
}

func (p *Tab) SprintfColored(ca color.Attribute, format string, args ...interface{}) string {
c := color.New(ca)

if !p.useColors {
c.DisableColor()
}

return c.Sprintf(format, args...)
}

Expand Down
11 changes: 6 additions & 5 deletions pkg/printers/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

type Text struct {
printIssuedLine bool
useColors bool
printLinterName bool
useColors bool

log logutils.Log
w io.Writer
Expand All @@ -24,19 +24,20 @@ type Text struct {
func NewText(printIssuedLine, useColors, printLinterName bool, log logutils.Log, w io.Writer) *Text {
return &Text{
printIssuedLine: printIssuedLine,
useColors: useColors,
printLinterName: printLinterName,
useColors: useColors,
log: log,
w: w,
}
}

func (p *Text) SprintfColored(ca color.Attribute, format string, args ...interface{}) string {
c := color.New(ca)

if !p.useColors {
return fmt.Sprintf(format, args...)
c.DisableColor()
}

c := color.New(ca)
return c.Sprintf(format, args...)
}

Expand Down Expand Up @@ -73,7 +74,7 @@ func (p *Text) printSourceCode(i *result.Issue) {
}
}

func (p Text) printUnderLinePointer(i *result.Issue) {
func (p *Text) printUnderLinePointer(i *result.Issue) {
// if column == 0 it means column is unknown (e.g. for gosec)
if len(i.SourceLines) != 1 || i.Pos.Column == 0 {
return
Expand Down

0 comments on commit 8cad751

Please sign in to comment.