Skip to content

Commit

Permalink
Merge pull request #5277 from daghack/warn-print-dockerfile-path
Browse files Browse the repository at this point in the history
frontend: rule check print to include path to dockerfile
  • Loading branch information
tonistiigi authored Aug 30, 2024
2 parents 6fdac94 + 6e838fe commit 894bcb3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion frontend/dockerui/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (bc *Client) HandleSubrequest(ctx context.Context, h RequestHandler) (*clie
if warnings == nil {
return nil, true, nil
}
res, err := warnings.ToResult()
res, err := warnings.ToResult(nil)
return res, true, err
}
}
Expand Down
19 changes: 12 additions & 7 deletions frontend/subrequests/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/pkg/errors"
)

type SourceInfoMap func(*pb.SourceInfo) *pb.SourceInfo

const RequestLint = "frontend.lint"

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

func (w *Warning) PrintTo(wr io.Writer, sources []*pb.SourceInfo) error {
func (w *Warning) PrintTo(wr io.Writer, sources []*pb.SourceInfo, scb SourceInfoMap) error {
fmt.Fprintf(wr, "\nWARNING: %s", w.RuleName)
if w.URL != "" {
fmt.Fprintf(wr, " - %s", w.URL)
Expand All @@ -50,6 +52,9 @@ func (w *Warning) PrintTo(wr io.Writer, sources []*pb.SourceInfo) error {
return nil
}
sourceInfo := sources[w.Location.SourceIndex]
if scb != nil {
sourceInfo = scb(sourceInfo)
}
source := errdefs.Source{
Info: sourceInfo,
Ranges: w.Location.Ranges,
Expand Down Expand Up @@ -111,7 +116,7 @@ func (results *LintResults) AddWarning(rulename, description, url, fmtmsg string
})
}

func (results *LintResults) ToResult() (*client.Result, error) {
func (results *LintResults) ToResult(scb SourceInfoMap) (*client.Result, error) {
res := client.NewResult()
dt, err := json.MarshalIndent(results, "", " ")
if err != nil {
Expand All @@ -120,7 +125,7 @@ func (results *LintResults) ToResult() (*client.Result, error) {
res.AddMeta("result.json", dt)

b := bytes.NewBuffer(nil)
if err := PrintLintViolations(dt, b); err != nil {
if err := PrintLintViolations(dt, b, scb); err != nil {
return nil, err
}
res.AddMeta("result.txt", b.Bytes())
Expand All @@ -135,7 +140,7 @@ func (results *LintResults) ToResult() (*client.Result, error) {
return res, nil
}

func (results *LintResults) PrintTo(w io.Writer) error {
func (results *LintResults) PrintTo(w io.Writer, scb SourceInfoMap) error {
if err := results.validateWarnings(); err != nil {
return err
}
Expand Down Expand Up @@ -166,7 +171,7 @@ func (results *LintResults) PrintTo(w io.Writer) error {
})

for _, warning := range results.Warnings {
err := warning.PrintTo(w, results.Sources)
err := warning.PrintTo(w, results.Sources, scb)
if err != nil {
return err
}
Expand Down Expand Up @@ -206,14 +211,14 @@ func (results *LintResults) validateWarnings() error {
return nil
}

func PrintLintViolations(dt []byte, w io.Writer) error {
func PrintLintViolations(dt []byte, w io.Writer, scb SourceInfoMap) error {
var results LintResults

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

return results.PrintTo(w)
return results.PrintTo(w, scb)
}

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

0 comments on commit 894bcb3

Please sign in to comment.