Skip to content

Commit 1383aa3

Browse files
committed
lint: modernize fix
Signed-off-by: CrazyMax <[email protected]>
1 parent 09b824b commit 1383aa3

File tree

27 files changed

+14
-49
lines changed

27 files changed

+14
-49
lines changed

bake/bake.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,7 @@ func (c Config) expandTargets(pattern string) ([]string, error) {
483483
func (c Config) loadLinks(name string, t *Target, m map[string]*Target, o map[string]map[string]Override, visited []string, ent *EntitlementConf) error {
484484
visited = append(visited, name)
485485
for _, v := range t.Contexts {
486-
if strings.HasPrefix(v, "target:") {
487-
target := strings.TrimPrefix(v, "target:")
486+
if target, ok := strings.CutPrefix(v, "target:"); ok {
488487
if target == name {
489488
return errors.Errorf("target %s cannot link to itself", target)
490489
}
@@ -1275,8 +1274,8 @@ func collectLocalPaths(t build.Inputs) []string {
12751274
if v, ok := isLocalPath(t.DockerfilePath); ok {
12761275
out = append(out, v)
12771276
}
1278-
} else if strings.HasPrefix(t.ContextPath, "cwd://") {
1279-
out = append(out, strings.TrimPrefix(t.ContextPath, "cwd://"))
1277+
} else if v, ok := strings.CutPrefix(t.ContextPath, "cwd://"); ok {
1278+
out = append(out, v)
12801279
}
12811280
for _, v := range t.NamedContexts {
12821281
if v.State != nil {
@@ -1328,11 +1327,11 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
13281327
bi.DockerfileInline = *t.DockerfileInline
13291328
}
13301329
updateContext(&bi, inp)
1331-
if strings.HasPrefix(bi.DockerfilePath, "cwd://") {
1330+
if v, ok := strings.CutPrefix(bi.DockerfilePath, "cwd://"); ok {
13321331
// If Dockerfile is local for a remote invocation, we first check if
13331332
// it's not outside the working directory and then resolve it to an
13341333
// absolute path.
1335-
bi.DockerfilePath = path.Clean(strings.TrimPrefix(bi.DockerfilePath, "cwd://"))
1334+
bi.DockerfilePath = path.Clean(v)
13361335
var err error
13371336
bi.DockerfilePath, err = filepath.Abs(bi.DockerfilePath)
13381337
if err != nil {
@@ -1357,15 +1356,15 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
13571356
return nil, errors.Errorf("reading a dockerfile for a remote build invocation is currently not supported")
13581357
}
13591358
}
1360-
if strings.HasPrefix(bi.ContextPath, "cwd://") {
1361-
bi.ContextPath = path.Clean(strings.TrimPrefix(bi.ContextPath, "cwd://"))
1359+
if v, ok := strings.CutPrefix(bi.ContextPath, "cwd://"); ok {
1360+
bi.ContextPath = path.Clean(v)
13621361
}
13631362
if !build.IsRemoteURL(bi.ContextPath) && bi.ContextState == nil && !filepath.IsAbs(bi.DockerfilePath) {
13641363
bi.DockerfilePath = filepath.Join(bi.ContextPath, bi.DockerfilePath)
13651364
}
13661365
for k, v := range bi.NamedContexts {
1367-
if strings.HasPrefix(v.Path, "cwd://") {
1368-
bi.NamedContexts[k] = build.NamedContext{Path: path.Clean(strings.TrimPrefix(v.Path, "cwd://"))}
1366+
if v, ok := strings.CutPrefix(v.Path, "cwd://"); ok {
1367+
bi.NamedContexts[k] = build.NamedContext{Path: path.Clean(v)}
13691368
}
13701369
}
13711370

bake/bake_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,6 @@ target "d" {
13811381
},
13821382
}
13831383
for _, tt := range cases {
1384-
tt := tt
13851384
t.Run(tt.name, func(t *testing.T) {
13861385
m, g, err := ReadTargets(ctx, []File{f}, []string{"d"}, tt.overrides, nil, &EntitlementConf{})
13871386
require.NoError(t, err)
@@ -1454,7 +1453,6 @@ group "default" {
14541453
},
14551454
}
14561455
for _, tt := range cases {
1457-
tt := tt
14581456
t.Run(tt.name, func(t *testing.T) {
14591457
m, g, err := ReadTargets(ctx, []File{f}, []string{"default"}, tt.overrides, nil, &EntitlementConf{})
14601458
require.NoError(t, err)
@@ -1509,7 +1507,6 @@ func TestTargetName(t *testing.T) {
15091507
},
15101508
}
15111509
for _, tt := range cases {
1512-
tt := tt
15131510
t.Run(tt.target, func(t *testing.T) {
15141511
_, _, err := ReadTargets(ctx, []File{{
15151512
Name: "docker-bake.hcl",
@@ -1600,7 +1597,6 @@ target "f" {
16001597
},
16011598
}
16021599
for _, tt := range cases {
1603-
tt := tt
16041600
t.Run(strings.Join(tt.names, "+"), func(t *testing.T) {
16051601
m, g, err := ReadTargets(ctx, []File{f}, tt.names, nil, nil, &EntitlementConf{})
16061602
require.NoError(t, err)

bake/compose.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ func ParseCompose(cfgs []composetypes.ConfigFile, envs map[string]string) (*Conf
6262
g := &Group{Name: "default"}
6363

6464
for _, s := range cfg.Services {
65-
s := s
6665
if s.Build == nil {
6766
continue
6867
}
@@ -144,7 +143,6 @@ func ParseCompose(cfgs []composetypes.ConfigFile, envs map[string]string) (*Conf
144143
// compose does not support nil values for labels
145144
labels := map[string]*string{}
146145
for k, v := range s.Build.Labels {
147-
v := v
148146
labels[k] = &v
149147
}
150148

bake/compose_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ func TestServiceName(t *testing.T) {
518518
},
519519
}
520520
for _, tt := range cases {
521-
tt := tt
522521
t.Run(tt.svc, func(t *testing.T) {
523522
_, err := ParseCompose([]composetypes.ConfigFile{{Content: []byte(`
524523
services:
@@ -589,7 +588,6 @@ services:
589588
},
590589
}
591590
for _, tt := range cases {
592-
tt := tt
593591
t.Run(tt.name, func(t *testing.T) {
594592
_, err := ParseCompose([]composetypes.ConfigFile{{Content: tt.dt}}, nil)
595593
if tt.wantErr {
@@ -665,7 +663,6 @@ target "default" {
665663
},
666664
}
667665
for _, tt := range cases {
668-
tt := tt
669666
t.Run(tt.name, func(t *testing.T) {
670667
isCompose, err := validateComposeFile(tt.dt, tt.fn)
671668
assert.Equal(t, tt.isCompose, isCompose)

bake/hclparser/hclparser.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,6 @@ func Parse(b hcl.Body, opt Opt, val any) (*ParseMeta, hcl.Diagnostics) {
781781
}
782782

783783
for _, a := range content.Attributes {
784-
a := a
785784
return nil, hcl.Diagnostics{
786785
&hcl.Diagnostic{
787786
Severity: hcl.DiagError,
@@ -834,7 +833,6 @@ func Parse(b hcl.Body, opt Opt, val any) (*ParseMeta, hcl.Diagnostics) {
834833
context = subject
835834
} else {
836835
for _, block := range blocks.Blocks {
837-
block := block
838836
if block.Type == "function" && len(block.Labels) == 1 && block.Labels[0] == k {
839837
subject = block.LabelRanges[0].Ptr()
840838
context = block.DefRange.Ptr()
@@ -903,7 +901,6 @@ func Parse(b hcl.Body, opt Opt, val any) (*ParseMeta, hcl.Diagnostics) {
903901

904902
diags = hcl.Diagnostics{}
905903
for _, b := range content.Blocks {
906-
b := b
907904
v := reflect.ValueOf(val)
908905

909906
err := p.resolveBlock(b, nil)

build/build.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opts map[
383383
wg.Add(1)
384384
sharedSessionsWG[node.Name] = wg
385385
for _, s := range sessions {
386-
s := s
387386
eg.Go(func() error {
388387
return s.Run(baseCtx, c.Dialer())
389388
})

build/git_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ func TestGetGitAttributes(t *testing.T) {
109109
},
110110
}
111111
for _, tt := range cases {
112-
tt := tt
113112
t.Run(tt.name, func(t *testing.T) {
114113
setupTest(t)
115114
if tt.envGitLabels != "" {

build/opt.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,7 @@ func loadInputs(ctx context.Context, d *driver.DriverHandle, inp *Inputs, pw pro
503503
}
504504

505505
// handle OCI layout
506-
if strings.HasPrefix(v.Path, "oci-layout://") {
507-
localPath := strings.TrimPrefix(v.Path, "oci-layout://")
506+
if localPath, ok := strings.CutPrefix(v.Path, "oci-layout://"); ok {
508507
localPath, dig, hasDigest := strings.Cut(localPath, "@")
509508
localPath, tag, hasTag := strings.Cut(localPath, ":")
510509
if !hasTag {

build/provenance.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ func fetchProvenance(ctx context.Context, c *client.Client, ref string, mode con
9292
})
9393
} else if ev.Record.Results != nil {
9494
for platform, res := range ev.Record.Results {
95-
platform := platform
9695
desc := lookupProvenance(res)
9796
if desc == nil {
9897
continue

build/utils_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ func TestToBuildkitExtraHosts(t *testing.T) {
130130
}
131131

132132
for _, tc := range tests {
133-
tc := tc
134133
if tc.expectedOut == "" {
135134
tc.expectedOut = strings.Join(tc.input, ",")
136135
}

0 commit comments

Comments
 (0)