Skip to content

Commit

Permalink
fix: Missing column in simple output when violation is at column 0
Browse files Browse the repository at this point in the history
  • Loading branch information
caitlinelfring committed Aug 28, 2020
1 parent bb08acf commit 26f6f57
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/printer/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package printer

import (
"fmt"
"go/token"

"github.com/caitlinelfring/woke/pkg/result"
)
Expand All @@ -19,9 +20,23 @@ func NewSimple() *Simple {
func (p *Simple) Print(fs *result.FileResults) error {
for _, r := range fs.Results {
fmt.Printf("%v: [%s] %s\n",
r.StartPosition,
positionString(r.StartPosition),
r.Rule.Severity,
r.Reason())
}
return nil
}

// positionString is similar to Position.String, but includes the Column
// even if the column is 0
func positionString(pos *token.Position) string {
s := pos.Filename
if pos.IsValid() {
if s != "" {
s += ":"
}
s += fmt.Sprintf("%d", pos.Line)
s += fmt.Sprintf(":%d", pos.Column)
}
return s
}

0 comments on commit 26f6f57

Please sign in to comment.