Skip to content

Commit

Permalink
justify incrementing better
Browse files Browse the repository at this point in the history
  • Loading branch information
dexhorthy committed Jan 18, 2020
1 parent 33285c6 commit d32e80d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions cli/print/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ var lintTmplSrc = `RULE TYPE LINE MESSAGE
var lintTmpl = template.Must(template.New("lint").Parse(lintTmplSrc))

func LintErrors(w *tabwriter.Writer, lintErrors []types.LintMessage) error {
lintErrors = incrementLineNumbersToOneIndexed(lintErrors)
if err := lintTmpl.Execute(w, lintErrors); err != nil {
return err
}
return w.Flush()
}

// line numbers come back zero-indexed from the API
// Since we now attach messages from the yaml parser,
// lets make this 1-indexed so they match if the message includes a line number
// this is here because its primarily client logic, its about how we're displaying the data
func incrementLineNumbersToOneIndexed(lintErrors []types.LintMessage) []types.LintMessage {
for _, lintError := range lintErrors {
if len(lintError.Positions) > 0 {
lintError.Positions[0].Start.Line += 1
}
}
if err := lintTmpl.Execute(w, lintErrors); err != nil {
return err
}
return w.Flush()
return lintErrors
}
4 changes: 2 additions & 2 deletions pkg/types/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type LintMessage struct {

type LintPosition struct {
Path string `json:"path"`
Start *LintLinePosition `json:"start"`
End *LintLinePosition `json:"end"`
Start LintLinePosition `json:"start"`
End LintLinePosition `json:"end"`
}

type LintLinePosition struct {
Expand Down

0 comments on commit d32e80d

Please sign in to comment.