@@ -16,6 +16,8 @@ import (
16
16
"github.com/pkg/errors"
17
17
)
18
18
19
+ type SourceInfoMap func (* pb.SourceInfo ) * pb.SourceInfo
20
+
19
21
const RequestLint = "frontend.lint"
20
22
21
23
var SubrequestLintDefinition = subrequests.Request {
@@ -39,7 +41,7 @@ type Warning struct {
39
41
Location pb.Location `json:"location,omitempty"`
40
42
}
41
43
42
- func (w * Warning ) PrintTo (wr io.Writer , sources []* pb.SourceInfo ) error {
44
+ func (w * Warning ) PrintTo (wr io.Writer , sources []* pb.SourceInfo , scb SourceInfoMap ) error {
43
45
fmt .Fprintf (wr , "\n WARNING: %s" , w .RuleName )
44
46
if w .URL != "" {
45
47
fmt .Fprintf (wr , " - %s" , w .URL )
@@ -50,6 +52,9 @@ func (w *Warning) PrintTo(wr io.Writer, sources []*pb.SourceInfo) error {
50
52
return nil
51
53
}
52
54
sourceInfo := sources [w .Location .SourceIndex ]
55
+ if scb != nil {
56
+ sourceInfo = scb (sourceInfo )
57
+ }
53
58
source := errdefs.Source {
54
59
Info : sourceInfo ,
55
60
Ranges : w .Location .Ranges ,
@@ -111,7 +116,7 @@ func (results *LintResults) AddWarning(rulename, description, url, fmtmsg string
111
116
})
112
117
}
113
118
114
- func (results * LintResults ) ToResult () (* client.Result , error ) {
119
+ func (results * LintResults ) ToResult (scb SourceInfoMap ) (* client.Result , error ) {
115
120
res := client .NewResult ()
116
121
dt , err := json .MarshalIndent (results , "" , " " )
117
122
if err != nil {
@@ -120,7 +125,7 @@ func (results *LintResults) ToResult() (*client.Result, error) {
120
125
res .AddMeta ("result.json" , dt )
121
126
122
127
b := bytes .NewBuffer (nil )
123
- if err := PrintLintViolations (dt , b ); err != nil {
128
+ if err := PrintLintViolations (dt , b , scb ); err != nil {
124
129
return nil , err
125
130
}
126
131
res .AddMeta ("result.txt" , b .Bytes ())
@@ -135,7 +140,7 @@ func (results *LintResults) ToResult() (*client.Result, error) {
135
140
return res , nil
136
141
}
137
142
138
- func (results * LintResults ) PrintTo (w io.Writer ) error {
143
+ func (results * LintResults ) PrintTo (w io.Writer , scb SourceInfoMap ) error {
139
144
if err := results .validateWarnings (); err != nil {
140
145
return err
141
146
}
@@ -166,7 +171,7 @@ func (results *LintResults) PrintTo(w io.Writer) error {
166
171
})
167
172
168
173
for _ , warning := range results .Warnings {
169
- err := warning .PrintTo (w , results .Sources )
174
+ err := warning .PrintTo (w , results .Sources , scb )
170
175
if err != nil {
171
176
return err
172
177
}
@@ -206,14 +211,14 @@ func (results *LintResults) validateWarnings() error {
206
211
return nil
207
212
}
208
213
209
- func PrintLintViolations (dt []byte , w io.Writer ) error {
214
+ func PrintLintViolations (dt []byte , w io.Writer , scb SourceInfoMap ) error {
210
215
var results LintResults
211
216
212
217
if err := json .Unmarshal (dt , & results ); err != nil {
213
218
return err
214
219
}
215
220
216
- return results .PrintTo (w )
221
+ return results .PrintTo (w , scb )
217
222
}
218
223
219
224
func sourceInfoEqual (a , b * pb.SourceInfo ) bool {
0 commit comments