Skip to content

Commit 894bcb3

Browse files
authored
Merge pull request moby#5277 from daghack/warn-print-dockerfile-path
frontend: rule check print to include path to dockerfile
2 parents 6fdac94 + 6e838fe commit 894bcb3

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

frontend/dockerui/requests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (bc *Client) HandleSubrequest(ctx context.Context, h RequestHandler) (*clie
6666
if warnings == nil {
6767
return nil, true, nil
6868
}
69-
res, err := warnings.ToResult()
69+
res, err := warnings.ToResult(nil)
7070
return res, true, err
7171
}
7272
}

frontend/subrequests/lint/lint.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/pkg/errors"
1717
)
1818

19+
type SourceInfoMap func(*pb.SourceInfo) *pb.SourceInfo
20+
1921
const RequestLint = "frontend.lint"
2022

2123
var SubrequestLintDefinition = subrequests.Request{
@@ -39,7 +41,7 @@ type Warning struct {
3941
Location pb.Location `json:"location,omitempty"`
4042
}
4143

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 {
4345
fmt.Fprintf(wr, "\nWARNING: %s", w.RuleName)
4446
if w.URL != "" {
4547
fmt.Fprintf(wr, " - %s", w.URL)
@@ -50,6 +52,9 @@ func (w *Warning) PrintTo(wr io.Writer, sources []*pb.SourceInfo) error {
5052
return nil
5153
}
5254
sourceInfo := sources[w.Location.SourceIndex]
55+
if scb != nil {
56+
sourceInfo = scb(sourceInfo)
57+
}
5358
source := errdefs.Source{
5459
Info: sourceInfo,
5560
Ranges: w.Location.Ranges,
@@ -111,7 +116,7 @@ func (results *LintResults) AddWarning(rulename, description, url, fmtmsg string
111116
})
112117
}
113118

114-
func (results *LintResults) ToResult() (*client.Result, error) {
119+
func (results *LintResults) ToResult(scb SourceInfoMap) (*client.Result, error) {
115120
res := client.NewResult()
116121
dt, err := json.MarshalIndent(results, "", " ")
117122
if err != nil {
@@ -120,7 +125,7 @@ func (results *LintResults) ToResult() (*client.Result, error) {
120125
res.AddMeta("result.json", dt)
121126

122127
b := bytes.NewBuffer(nil)
123-
if err := PrintLintViolations(dt, b); err != nil {
128+
if err := PrintLintViolations(dt, b, scb); err != nil {
124129
return nil, err
125130
}
126131
res.AddMeta("result.txt", b.Bytes())
@@ -135,7 +140,7 @@ func (results *LintResults) ToResult() (*client.Result, error) {
135140
return res, nil
136141
}
137142

138-
func (results *LintResults) PrintTo(w io.Writer) error {
143+
func (results *LintResults) PrintTo(w io.Writer, scb SourceInfoMap) error {
139144
if err := results.validateWarnings(); err != nil {
140145
return err
141146
}
@@ -166,7 +171,7 @@ func (results *LintResults) PrintTo(w io.Writer) error {
166171
})
167172

168173
for _, warning := range results.Warnings {
169-
err := warning.PrintTo(w, results.Sources)
174+
err := warning.PrintTo(w, results.Sources, scb)
170175
if err != nil {
171176
return err
172177
}
@@ -206,14 +211,14 @@ func (results *LintResults) validateWarnings() error {
206211
return nil
207212
}
208213

209-
func PrintLintViolations(dt []byte, w io.Writer) error {
214+
func PrintLintViolations(dt []byte, w io.Writer, scb SourceInfoMap) error {
210215
var results LintResults
211216

212217
if err := json.Unmarshal(dt, &results); err != nil {
213218
return err
214219
}
215220

216-
return results.PrintTo(w)
221+
return results.PrintTo(w, scb)
217222
}
218223

219224
func sourceInfoEqual(a, b *pb.SourceInfo) bool {

0 commit comments

Comments
 (0)