Skip to content

Commit

Permalink
avoid appending line info in lint detail
Browse files Browse the repository at this point in the history
Signed-off-by: Talon Bowler <[email protected]>
  • Loading branch information
daghack committed Apr 17, 2024
1 parent b6bd514 commit 8b40582
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 6 additions & 0 deletions frontend/dockerfile/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/moby/buildkit/frontend"
"github.com/moby/buildkit/frontend/attestations/sbom"
"github.com/moby/buildkit/frontend/dockerfile/dockerfile2llb"
"github.com/moby/buildkit/frontend/dockerfile/linter"
"github.com/moby/buildkit/frontend/dockerfile/parser"
"github.com/moby/buildkit/frontend/dockerui"
"github.com/moby/buildkit/frontend/gateway/client"
Expand Down Expand Up @@ -75,6 +76,11 @@ func Build(ctx context.Context, c client.Client) (_ *client.Result, err error) {
SourceMap: src.SourceMap,
MetaResolver: c,
Warn: func(rulename, description, url, msg string, location []parser.Range) {
startLine := 0
if len(location) > 0 {
startLine = location[0].Start.Line
}
msg = linter.LintFormatShort(rulename, msg, startLine)
src.Warn(ctx, msg, warnOpts(location, [][]byte{[]byte(description)}, url))
},
}
Expand Down
3 changes: 1 addition & 2 deletions frontend/dockerfile/dockerfile_lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,10 @@ func checkVertexWarning(t *testing.T, warning *client.VertexWarning, expected ex
}

func checkLintWarning(t *testing.T, warning lint.Warning, expected expectedLintWarning) {
short := linter.LintFormatShort(expected.RuleName, expected.Detail, expected.Line)
require.Equal(t, expected.RuleName, warning.RuleName)
require.Equal(t, expected.Description, warning.Description)
require.Equal(t, expected.URL, warning.URL)
require.Equal(t, short, warning.Detail)
require.Equal(t, expected.Detail, warning.Detail)
}

func unmarshalLintResults(res *gateway.Result) (*lint.LintResults, error) {
Expand Down
6 changes: 1 addition & 5 deletions frontend/dockerfile/linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ type LinterRule[F any] struct {
}

func (rule LinterRule[F]) Run(warn LintWarnFunc, location []parser.Range, txt ...string) {
startLine := 0
if len(location) > 0 {
startLine = location[0].Start.Line
}
if len(txt) == 0 {
txt = []string{rule.Description}
}
short := LintFormatShort(rule.Name, strings.Join(txt, " "), startLine)
short := strings.Join(txt, " ")
warn(rule.Name, rule.Description, rule.URL, short, location)
}

Expand Down

0 comments on commit 8b40582

Please sign in to comment.