Skip to content

Commit

Permalink
move lint directive parsing into toDispatchState
Browse files Browse the repository at this point in the history
Signed-off-by: Talon Bowler <talon.bowler@docker.com>
  • Loading branch information
daghack committed May 30, 2024
1 parent 12f0ce5 commit 80e988e
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 237 deletions.
34 changes: 9 additions & 25 deletions frontend/dockerfile/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,6 @@ func Build(ctx context.Context, c client.Client) (_ *client.Result, err error) {
}
}

var checkOptionStr string
var ruleChecker *linter.RuleChecker
if cmdline, ok := opts[keyDockerfileLintArg]; ok {
checkOptionStr = cmdline
}
if checkOptionStr != "" {
ruleChecker, err = linter.NewRuleCheckerFromStr(checkOptionStr)
ruleChecker.FromBuildArg = true
if err != nil {
return nil, errors.Wrapf(err, "failed to parse lint options")
}
} else {
ruleChecker = linter.NewRuleChecker()
}
ruleChecker.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))
}

if capsError != nil {
return nil, capsError
}
Expand All @@ -99,7 +76,14 @@ func Build(ctx context.Context, c client.Client) (_ *client.Result, err error) {
Client: bc,
SourceMap: src.SourceMap,
MetaResolver: c,
RuleChecker: ruleChecker,
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))
},
}

if res, ok, err := bc.HandleSubrequest(ctx, dockerui.RequestHandler{
Expand Down Expand Up @@ -146,7 +130,7 @@ func Build(ctx context.Context, c client.Client) (_ *client.Result, err error) {
opt := convertOpt
opt.TargetPlatform = platform
if idx != 0 {
opt.RuleChecker = nil
opt.Warn = nil
}

st, img, baseImg, scanTarget, err := dockerfile2llb.Dockerfile2LLB(ctx, src.Data, opt)
Expand Down
Loading

0 comments on commit 80e988e

Please sign in to comment.