@@ -265,7 +265,7 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
265
265
266
266
// Validate that base images continue to be valid even
267
267
// when no build arguments are used.
268
- validateBaseImagesWithDefaultArgs (stages , shlex , argCmds , globalArgs , lint )
268
+ validateBaseImagesWithDefaultArgs (stages , shlex , globalArgs , argCmds , lint )
269
269
270
270
// Rebuild the arguments using the provided build arguments
271
271
// for the remainder of the build.
@@ -284,7 +284,8 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
284
284
// set base state for every image
285
285
for i , st := range stages {
286
286
nameMatch , err := shlex .ProcessWordWithMatches (st .BaseName , globalArgs )
287
- reportUnusedFromArgs (globalArgs , nameMatch .Unmatched , st .Location , lint )
287
+ argKeys := unusedFromArgsCheckKeys (globalArgs , outline .allArgs )
288
+ reportUnusedFromArgs (argKeys , nameMatch .Unmatched , st .Location , lint )
288
289
used := nameMatch .Matched
289
290
if used == nil {
290
291
used = map [string ]struct {}{}
@@ -311,7 +312,8 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
311
312
312
313
if v := st .Platform ; v != "" {
313
314
platMatch , err := shlex .ProcessWordWithMatches (v , globalArgs )
314
- reportUnusedFromArgs (globalArgs , platMatch .Unmatched , st .Location , lint )
315
+ argKeys := unusedFromArgsCheckKeys (globalArgs , outline .allArgs )
316
+ reportUnusedFromArgs (argKeys , platMatch .Unmatched , st .Location , lint )
315
317
reportRedundantTargetPlatform (st .Platform , platMatch , st .Location , globalArgs , lint )
316
318
reportConstPlatformDisallowed (st .Name , platMatch , st .Location , lint )
317
319
@@ -2332,9 +2334,27 @@ func toPBLocation(sourceIndex int, location []parser.Range) pb.Location {
2332
2334
}
2333
2335
}
2334
2336
2335
- func reportUnusedFromArgs (args shell.EnvGetter , unmatched map [string ]struct {}, location []parser.Range , lint * linter.Linter ) {
2337
+ func unusedFromArgsCheckKeys (env shell.EnvGetter , args map [string ]argInfo ) map [string ]struct {} {
2338
+ matched := make (map [string ]struct {})
2339
+ for _ , arg := range args {
2340
+ matched [arg .definition .Key ] = struct {}{}
2341
+ }
2342
+ for _ , k := range env .Keys () {
2343
+ matched [k ] = struct {}{}
2344
+ }
2345
+ return matched
2346
+ }
2347
+
2348
+ func reportUnusedFromArgs (testArgKeys map [string ]struct {}, unmatched map [string ]struct {}, location []parser.Range , lint * linter.Linter ) {
2349
+ var argKeys []string
2350
+ for arg := range testArgKeys {
2351
+ argKeys = append (argKeys , arg )
2352
+ }
2336
2353
for arg := range unmatched {
2337
- suggest , _ := suggest .Search (arg , args .Keys (), true )
2354
+ if _ , ok := testArgKeys [arg ]; ok {
2355
+ continue
2356
+ }
2357
+ suggest , _ := suggest .Search (arg , argKeys , true )
2338
2358
msg := linter .RuleUndefinedArgInFrom .Format (arg , suggest )
2339
2359
lint .Run (& linter .RuleUndefinedArgInFrom , location , msg )
2340
2360
}
@@ -2456,10 +2476,10 @@ func validateNoSecretKey(instruction, key string, location []parser.Range, lint
2456
2476
}
2457
2477
}
2458
2478
2459
- func validateBaseImagesWithDefaultArgs (stages []instructions.Stage , shlex * shell.Lex , argsCmds []instructions. ArgCommand , args * llb. EnvList , lint * linter.Linter ) {
2479
+ func validateBaseImagesWithDefaultArgs (stages []instructions.Stage , shlex * shell.Lex , env * llb. EnvList , argCmds []instructions. ArgCommand , lint * linter.Linter ) {
2460
2480
// Build the arguments as if no build options were given
2461
2481
// and using only defaults.
2462
- args , _ , err := buildMetaArgs (args , shlex , argsCmds , nil )
2482
+ args , _ , err := buildMetaArgs (env , shlex , argCmds , nil )
2463
2483
if err != nil {
2464
2484
// Abandon running the linter. We'll likely fail after this point
2465
2485
// with the same error but we shouldn't error here inside
0 commit comments