package printers
import (
"context"
"fmt"
"html/template"
"io"
"strings"
"github.com/golangci/golangci-lint/pkg/result"
)
const templateContent = `
golangci-lint
`
type htmlIssue struct {
Title string
Pos string
Linter string
Code string
}
type HTML struct {
w io.Writer
}
func NewHTML(w io.Writer) *HTML {
return &HTML{w: w}
}
func (p HTML) Print(_ context.Context, issues []result.Issue) error {
var htmlIssues []htmlIssue
for i := range issues {
pos := fmt.Sprintf("%s:%d", issues[i].FilePath(), issues[i].Line())
if issues[i].Pos.Column != 0 {
pos += fmt.Sprintf(":%d", issues[i].Pos.Column)
}
htmlIssues = append(htmlIssues, htmlIssue{
Title: strings.TrimSpace(issues[i].Text),
Pos: pos,
Linter: issues[i].FromLinter,
Code: strings.Join(issues[i].SourceLines, "\n"),
})
}
t, err := template.New("golangci-lint").Parse(templateContent)
if err != nil {
return err
}
return t.Execute(p.w, struct{ Issues []htmlIssue }{Issues: htmlIssues})
}