Skip to content

Commit 8cad751

Browse files
committed
output: add colored-tab
1 parent 1f4fed7 commit 8cad751

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

.golangci.reference.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ run:
7676

7777
# output configuration options
7878
output:
79-
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity
79+
# Format: colored-line-number|line-number|json|colored-tab|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity
8080
#
8181
# Multiple can be specified by separating them by comma, output can be provided
8282
# for each of them by separating format name and path by colon symbol.

pkg/commands/run.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,10 @@ func (e *Executor) createPrinter(format string, w io.Writer) (printers.Printer,
475475
p = printers.NewText(e.cfg.Output.PrintIssuedLine,
476476
format == config.OutFormatColoredLineNumber, e.cfg.Output.PrintLinterName,
477477
e.log.Child(logutils.DebugKeyTextPrinter), w)
478-
case config.OutFormatTab:
479-
p = printers.NewTab(e.cfg.Output.PrintLinterName, e.log.Child(logutils.DebugKeyTabPrinter), w)
478+
case config.OutFormatTab, config.OutFormatColoredTab:
479+
p = printers.NewTab(e.cfg.Output.PrintLinterName,
480+
format == config.OutFormatColoredTab,
481+
e.log.Child(logutils.DebugKeyTabPrinter), w)
480482
case config.OutFormatCheckstyle:
481483
p = printers.NewCheckstyle(w)
482484
case config.OutFormatCodeClimate:

pkg/config/output.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const (
55
OutFormatLineNumber = "line-number"
66
OutFormatColoredLineNumber = "colored-line-number"
77
OutFormatTab = "tab"
8+
OutFormatColoredTab = "colored-tab"
89
OutFormatCheckstyle = "checkstyle"
910
OutFormatCodeClimate = "code-climate"
1011
OutFormatHTML = "html"

pkg/printers/tab.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,28 @@ import (
1414

1515
type Tab struct {
1616
printLinterName bool
17-
log logutils.Log
18-
w io.Writer
17+
useColors bool
18+
19+
log logutils.Log
20+
w io.Writer
1921
}
2022

21-
func NewTab(printLinterName bool, log logutils.Log, w io.Writer) *Tab {
23+
func NewTab(printLinterName, useColors bool, log logutils.Log, w io.Writer) *Tab {
2224
return &Tab{
2325
printLinterName: printLinterName,
26+
useColors: useColors,
2427
log: log,
2528
w: w,
2629
}
2730
}
2831

2932
func (p *Tab) SprintfColored(ca color.Attribute, format string, args ...interface{}) string {
3033
c := color.New(ca)
34+
35+
if !p.useColors {
36+
c.DisableColor()
37+
}
38+
3139
return c.Sprintf(format, args...)
3240
}
3341

pkg/printers/text.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414

1515
type Text struct {
1616
printIssuedLine bool
17-
useColors bool
1817
printLinterName bool
18+
useColors bool
1919

2020
log logutils.Log
2121
w io.Writer
@@ -24,19 +24,20 @@ type Text struct {
2424
func NewText(printIssuedLine, useColors, printLinterName bool, log logutils.Log, w io.Writer) *Text {
2525
return &Text{
2626
printIssuedLine: printIssuedLine,
27-
useColors: useColors,
2827
printLinterName: printLinterName,
28+
useColors: useColors,
2929
log: log,
3030
w: w,
3131
}
3232
}
3333

3434
func (p *Text) SprintfColored(ca color.Attribute, format string, args ...interface{}) string {
35+
c := color.New(ca)
36+
3537
if !p.useColors {
36-
return fmt.Sprintf(format, args...)
38+
c.DisableColor()
3739
}
3840

39-
c := color.New(ca)
4041
return c.Sprintf(format, args...)
4142
}
4243

@@ -73,7 +74,7 @@ func (p *Text) printSourceCode(i *result.Issue) {
7374
}
7475
}
7576

76-
func (p Text) printUnderLinePointer(i *result.Issue) {
77+
func (p *Text) printUnderLinePointer(i *result.Issue) {
7778
// if column == 0 it means column is unknown (e.g. for gosec)
7879
if len(i.SourceLines) != 1 || i.Pos.Column == 0 {
7980
return

0 commit comments

Comments
 (0)