lint/lintutil/format: include related information in output
@@ -51,7 +51,10 @@ type Text struct {
}
func (o Text) Format(p lint.Problem) {
- fmt.Fprintf(o.W, "%v: %s\n", relativePositionString(p.Pos), p.String())
+ fmt.Fprintf(o.W, "%s: %s\n", relativePositionString(p.Pos), p.String())
+ for _, r := range p.Related {
+ fmt.Fprintf(o.W, "\t%s: %s\n", relativePositionString(r.Pos), r.Message)
+ }
}
type JSON struct {
@@ -76,12 +79,18 @@ func (o JSON) Format(p lint.Problem) {
Line int `json:"line"`
Column int `json:"column"`
}
+ type related struct {
+ Location location `json:"location"`
+ End location `json:"end"`
+ Message string `json:"message"`
+ }
jp := struct {
Code string `json:"code"`
Severity string `json:"severity,omitempty"`
Location location `json:"location"`
End location `json:"end"`
Message string `json:"message"`
+ Related []related `json:"related,omitempty"`
}{
Code: p.Check,
Severity: severity(p.Severity),
@@ -97,6 +106,21 @@ func (o JSON) Format(p lint.Problem) {
},
Message: p.Message,
}
+ for _, r := range p.Related {
+ jp.Related = append(jp.Related, related{
+ Location: location{
+ File: r.Pos.Filename,
+ Line: r.Pos.Line,
+ Column: r.Pos.Column,
+ },
+ End: location{
+ File: r.End.Filename,
+ Line: r.End.Line,
+ Column: r.End.Column,
+ },
+ Message: r.Message,
+ })
+ }
_ = json.NewEncoder(o.W).Encode(jp)
}
@@ -123,6 +147,9 @@ func (o *Stylish) Format(p lint.Problem) {
o.tw = tabwriter.NewWriter(o.W, 0, 4, 2, ' ', 0)
}
fmt.Fprintf(o.tw, " (%d, %d)\t%s\t%s\n", pos.Line, pos.Column, p.Check, p.Message)
+ for _, r := range p.Related {
+ fmt.Fprintf(o.tw, " (%d, %d)\t\t %s\n", r.Pos.Line, r.Pos.Column, r.Message)
+ }
}
func (o *Stylish) Stats(total, errors, warnings, ignored int) {
