@@ -266,7 +266,7 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
266
266
267
267
// Validate that base images continue to be valid even
268
268
// when no build arguments are used.
269
- validateBaseImagesWithDefaultArgs (stages , shlex , argCmds , globalArgs , lint )
269
+ validateBaseImagesWithDefaultArgs (stages , shlex , globalArgs , argCmds , lint )
270
270
271
271
// Rebuild the arguments using the provided build arguments
272
272
// for the remainder of the build.
@@ -285,7 +285,8 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
285
285
// set base state for every image
286
286
for i , st := range stages {
287
287
nameMatch , err := shlex .ProcessWordWithMatches (st .BaseName , globalArgs )
288
- reportUnusedFromArgs (globalArgs , nameMatch .Unmatched , st .Location , lint )
288
+ argKeys := unusedFromArgsCheckKeys (globalArgs , outline .allArgs )
289
+ reportUnusedFromArgs (argKeys , nameMatch .Unmatched , st .Location , lint )
289
290
used := nameMatch .Matched
290
291
if used == nil {
291
292
used = map [string ]struct {}{}
@@ -312,7 +313,8 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
312
313
313
314
if v := st .Platform ; v != "" {
314
315
platMatch , err := shlex .ProcessWordWithMatches (v , globalArgs )
315
- reportUnusedFromArgs (globalArgs , platMatch .Unmatched , st .Location , lint )
316
+ argKeys := unusedFromArgsCheckKeys (globalArgs , outline .allArgs )
317
+ reportUnusedFromArgs (argKeys , platMatch .Unmatched , st .Location , lint )
316
318
reportRedundantTargetPlatform (st .Platform , platMatch , st .Location , globalArgs , lint )
317
319
reportConstPlatformDisallowed (st .Name , platMatch , st .Location , lint )
318
320
@@ -2353,9 +2355,27 @@ func toPBLocation(sourceIndex int, location []parser.Range) pb.Location {
2353
2355
}
2354
2356
}
2355
2357
2356
- func reportUnusedFromArgs (args shell.EnvGetter , unmatched map [string ]struct {}, location []parser.Range , lint * linter.Linter ) {
2358
+ func unusedFromArgsCheckKeys (env shell.EnvGetter , args map [string ]argInfo ) map [string ]struct {} {
2359
+ matched := make (map [string ]struct {})
2360
+ for _ , arg := range args {
2361
+ matched [arg .definition .Key ] = struct {}{}
2362
+ }
2363
+ for _ , k := range env .Keys () {
2364
+ matched [k ] = struct {}{}
2365
+ }
2366
+ return matched
2367
+ }
2368
+
2369
+ func reportUnusedFromArgs (testArgKeys map [string ]struct {}, unmatched map [string ]struct {}, location []parser.Range , lint * linter.Linter ) {
2370
+ var argKeys []string
2371
+ for arg := range testArgKeys {
2372
+ argKeys = append (argKeys , arg )
2373
+ }
2357
2374
for arg := range unmatched {
2358
- suggest , _ := suggest .Search (arg , args .Keys (), true )
2375
+ if _ , ok := testArgKeys [arg ]; ok {
2376
+ continue
2377
+ }
2378
+ suggest , _ := suggest .Search (arg , argKeys , true )
2359
2379
msg := linter .RuleUndefinedArgInFrom .Format (arg , suggest )
2360
2380
lint .Run (& linter .RuleUndefinedArgInFrom , location , msg )
2361
2381
}
@@ -2483,10 +2503,10 @@ func validateNoSecretKey(instruction, key string, location []parser.Range, lint
2483
2503
}
2484
2504
}
2485
2505
2486
- func validateBaseImagesWithDefaultArgs (stages []instructions.Stage , shlex * shell.Lex , argsCmds []instructions. ArgCommand , args * llb. EnvList , lint * linter.Linter ) {
2506
+ func validateBaseImagesWithDefaultArgs (stages []instructions.Stage , shlex * shell.Lex , env * llb. EnvList , argCmds []instructions. ArgCommand , lint * linter.Linter ) {
2487
2507
// Build the arguments as if no build options were given
2488
2508
// and using only defaults.
2489
- args , _ , err := buildMetaArgs (args , shlex , argsCmds , nil )
2509
+ args , _ , err := buildMetaArgs (env , shlex , argCmds , nil )
2490
2510
if err != nil {
2491
2511
// Abandon running the linter. We'll likely fail after this point
2492
2512
// with the same error but we shouldn't error here inside
0 commit comments