From d31230ea9641aade7a06f2fb81f76582e09f54c6 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 9 Sep 2025 14:00:36 +0200 Subject: [PATCH] lint: gopls fixes Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- api/services/control/control_bench_test.go | 12 ++++----- cache/contenthash/checksum_bench_test.go | 4 +-- cache/remotecache/v1/spec.go | 6 ++--- client/graph.go | 2 +- client/llb/resolver_test.go | 2 +- cmd/buildkitd/main_windows.go | 2 +- examples/kubernetes/consistenthash/main.go | 2 +- executor/resources/io.go | 4 +-- executor/resources/memory.go | 4 +-- executor/resources/monitor.go | 2 +- exporter/containerimage/export.go | 4 +-- exporter/containerimage/writer.go | 2 +- frontend/dockerfile/builder/caps.go | 4 +-- .../dockerfile/instructions/parse_test.go | 2 +- frontend/dockerui/attr.go | 2 +- frontend/dockerui/config.go | 4 +-- solver/llbsolver/provenance/types/types.go | 26 +++++++++---------- util/cachedigest/digest.go | 4 +-- util/resolvconf/resolvconf_test.go | 2 +- util/resolver/authorizer.go | 2 +- util/testutil/dockerd/config.go | 4 +-- util/testutil/workers/containerd.go | 4 +-- 22 files changed, 50 insertions(+), 50 deletions(-) diff --git a/api/services/control/control_bench_test.go b/api/services/control/control_bench_test.go index 65595af8b..4ce004d6f 100644 --- a/api/services/control/control_bench_test.go +++ b/api/services/control/control_bench_test.go @@ -15,7 +15,7 @@ var Buf []byte func BenchmarkMarshalVertex(b *testing.B) { v := sampleVertex() - for i := 0; i < b.N; i++ { + for b.Loop() { var err error Buf, err = v.MarshalVT() require.NoError(b, err) @@ -24,7 +24,7 @@ func BenchmarkMarshalVertex(b *testing.B) { func BenchmarkMarshalVertexStatus(b *testing.B) { v := sampleVertexStatus() - for i := 0; i < b.N; i++ { + for b.Loop() { var err error Buf, err = v.MarshalVT() require.NoError(b, err) @@ -33,7 +33,7 @@ func BenchmarkMarshalVertexStatus(b *testing.B) { func BenchmarkMarshalVertexLog(b *testing.B) { v := sampleVertexLog() - for i := 0; i < b.N; i++ { + for b.Loop() { var err error Buf, err = v.MarshalVT() require.NoError(b, err) @@ -47,7 +47,7 @@ func BenchmarkUnmarshalVertex(b *testing.B) { buf, err := proto.Marshal(v) require.NoError(b, err) - for i := 0; i < b.N; i++ { + for b.Loop() { err := VertexOutput.UnmarshalVT(buf) require.NoError(b, err) } @@ -60,7 +60,7 @@ func BenchmarkUnmarshalVertexStatus(b *testing.B) { buf, err := proto.Marshal(v) require.NoError(b, err) - for i := 0; i < b.N; i++ { + for b.Loop() { err := VertexStatusOutput.UnmarshalVT(buf) require.NoError(b, err) } @@ -73,7 +73,7 @@ func BenchmarkUnmarshalVertexLog(b *testing.B) { buf, err := proto.Marshal(v) require.NoError(b, err) - for i := 0; i < b.N; i++ { + for b.Loop() { err := VertexLogOutput.UnmarshalVT(buf) require.NoError(b, err) } diff --git a/cache/contenthash/checksum_bench_test.go b/cache/contenthash/checksum_bench_test.go index b1e5db350..211369a5e 100644 --- a/cache/contenthash/checksum_bench_test.go +++ b/cache/contenthash/checksum_bench_test.go @@ -13,7 +13,7 @@ var Buf []byte func BenchmarkMarshalCacheRecords(b *testing.B) { v := sampleCacheRecords() - for i := 0; i < b.N; i++ { + for b.Loop() { var err error Buf, err = v.MarshalVT() require.NoError(b, err) @@ -27,7 +27,7 @@ func BenchmarkUnmarshalCacheRecords(b *testing.B) { buf, err := proto.Marshal(v) require.NoError(b, err) - for i := 0; i < b.N; i++ { + for b.Loop() { err := CacheRecordsOutput.UnmarshalVT(buf) require.NoError(b, err) } diff --git a/cache/remotecache/v1/spec.go b/cache/remotecache/v1/spec.go index bb9501e4c..e3e94d790 100644 --- a/cache/remotecache/v1/spec.go +++ b/cache/remotecache/v1/spec.go @@ -23,7 +23,7 @@ type LayerAnnotations struct { MediaType string `json:"mediaType,omitempty"` DiffID digest.Digest `json:"diffID,omitempty"` Size int64 `json:"size,omitempty"` - CreatedAt time.Time `json:"createdAt,omitempty"` + CreatedAt time.Time `json:"createdAt"` } type CacheRecord struct { @@ -35,12 +35,12 @@ type CacheRecord struct { type CacheResult struct { LayerIndex int `json:"layer"` - CreatedAt time.Time `json:"createdAt,omitempty"` + CreatedAt time.Time `json:"createdAt"` } type ChainedResult struct { LayerIndexes []int `json:"layers"` - CreatedAt time.Time `json:"createdAt,omitempty"` + CreatedAt time.Time `json:"createdAt"` } type CacheInput struct { diff --git a/client/graph.go b/client/graph.go index c24e73d45..1000cd78f 100644 --- a/client/graph.go +++ b/client/graph.go @@ -24,7 +24,7 @@ type VertexStatus struct { Name string `json:"name,omitempty"` Total int64 `json:"total,omitempty"` Current int64 `json:"current"` - Timestamp time.Time `json:"timestamp,omitempty"` + Timestamp time.Time `json:"timestamp"` Started *time.Time `json:"started,omitempty"` Completed *time.Time `json:"completed,omitempty"` } diff --git a/client/llb/resolver_test.go b/client/llb/resolver_test.go index 560ea20f8..dba105bb1 100644 --- a/client/llb/resolver_test.go +++ b/client/llb/resolver_test.go @@ -81,7 +81,7 @@ func (r *testResolver) ResolveImageConfig(ctx context.Context, ref string, opt s Env []string `json:"Env,omitempty"` WorkingDir string `json:"WorkingDir,omitempty"` User string `json:"User,omitempty"` - } `json:"config,omitempty"` + } `json:"config"` } r.called = true diff --git a/cmd/buildkitd/main_windows.go b/cmd/buildkitd/main_windows.go index 35fc19de0..ee6273972 100644 --- a/cmd/buildkitd/main_windows.go +++ b/cmd/buildkitd/main_windows.go @@ -44,7 +44,7 @@ func getLocalListener(listenerPath, secDescriptor string) (net.Listener, error) func groupToSecurityDescriptor(group string) (string, error) { sddl := "D:P(A;;GA;;;BA)(A;;GA;;;SY)" if group != "" { - for _, g := range strings.Split(group, ",") { + for g := range strings.SplitSeq(group, ",") { sid, err := winio.LookupSidByName(g) if err != nil { return "", errors.Wrapf(err, "failed to lookup sid for group %s", g) diff --git a/examples/kubernetes/consistenthash/main.go b/examples/kubernetes/consistenthash/main.go index 4b100777c..c8855ef02 100644 --- a/examples/kubernetes/consistenthash/main.go +++ b/examples/kubernetes/consistenthash/main.go @@ -43,7 +43,7 @@ func xmain() error { return err } var nodes []string - for _, s := range strings.Split(string(stdin), "\n") { + for s := range strings.SplitSeq(string(stdin), "\n") { s = strings.TrimSpace(s) if s != "" { nodes = append(nodes, s) diff --git a/executor/resources/io.go b/executor/resources/io.go index 05a3a7ff6..88f6663b5 100644 --- a/executor/resources/io.go +++ b/executor/resources/io.go @@ -35,8 +35,8 @@ func getCgroupIOStat(cgroupPath string) (*resourcestypes.IOStat, error) { } ioStat := &resourcestypes.IOStat{} - lines := strings.Split(string(data), "\n") - for _, line := range lines { + lines := strings.SplitSeq(string(data), "\n") + for line := range lines { parts := strings.Fields(line) if len(parts) < 2 { continue diff --git a/executor/resources/memory.go b/executor/resources/memory.go index 07c43c292..fe68d25dd 100644 --- a/executor/resources/memory.go +++ b/executor/resources/memory.go @@ -138,8 +138,8 @@ func parseKeyValueFile(filePath string, callback func(key string, value uint64)) return errors.Wrapf(err, "failed to read %s", filePath) } - lines := strings.Split(string(content), "\n") - for _, line := range lines { + lines := strings.SplitSeq(string(content), "\n") + for line := range lines { if len(strings.TrimSpace(line)) == 0 { continue } diff --git a/executor/resources/monitor.go b/executor/resources/monitor.go index 5d6e0cdc7..fe2e57d43 100644 --- a/executor/resources/monitor.go +++ b/executor/resources/monitor.go @@ -273,7 +273,7 @@ func prepareCgroupControllers() error { if err != nil { return err } - for _, c := range strings.Split(string(dt), " ") { + for c := range strings.SplitSeq(string(dt), " ") { if c == "" { continue } diff --git a/exporter/containerimage/export.go b/exporter/containerimage/export.go index 7055db5ef..d604d0bf7 100644 --- a/exporter/containerimage/export.go +++ b/exporter/containerimage/export.go @@ -271,8 +271,8 @@ func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source } if e.opts.ImageName != "" { - targetNames := strings.Split(e.opts.ImageName, ",") - for _, targetName := range targetNames { + targetNames := strings.SplitSeq(e.opts.ImageName, ",") + for targetName := range targetNames { if e.opt.Images != nil && e.store { tagDone := progress.OneOff(ctx, "naming to "+targetName) diff --git a/exporter/containerimage/writer.go b/exporter/containerimage/writer.go index 02d3d9234..05e8b1e92 100644 --- a/exporter/containerimage/writer.go +++ b/exporter/containerimage/writer.go @@ -296,7 +296,7 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp *exporter.Source, session } var defaultSubjects []intoto.Subject - for _, name := range strings.Split(opts.ImageName, ",") { + for name := range strings.SplitSeq(opts.ImageName, ",") { if name == "" { continue } diff --git a/frontend/dockerfile/builder/caps.go b/frontend/dockerfile/builder/caps.go index bb8b100c0..19a7c8473 100644 --- a/frontend/dockerfile/builder/caps.go +++ b/frontend/dockerfile/builder/caps.go @@ -20,8 +20,8 @@ func validateCaps(req string) (forward bool, err error) { if req == "" { return } - caps := strings.Split(req, ",") - for _, c := range caps { + caps := strings.SplitSeq(req, ",") + for c := range caps { parts := strings.SplitN(c, "+", 2) if _, ok := enabledCaps[parts[0]]; !ok { err = stack.Enable(grpcerrors.WrapCode(errdefs.NewUnsupportedFrontendCapError(parts[0]), codes.Unimplemented)) diff --git a/frontend/dockerfile/instructions/parse_test.go b/frontend/dockerfile/instructions/parse_test.go index d3ae1e282..e31c957f2 100644 --- a/frontend/dockerfile/instructions/parse_test.go +++ b/frontend/dockerfile/instructions/parse_test.go @@ -275,7 +275,7 @@ func TestRunCmdFlagsUsed(t *testing.T) { func BenchmarkParseBuildStageName(b *testing.B) { b.ReportAllocs() stageNames := []string{"STAGE_NAME", "StageName", "St4g3N4m3"} - for i := 0; i < b.N; i++ { + for b.Loop() { for _, s := range stageNames { _, _ = parseBuildStageName([]string{"foo", "as", s}) } diff --git a/frontend/dockerui/attr.go b/frontend/dockerui/attr.go index e06d70e20..ffb618cb2 100644 --- a/frontend/dockerui/attr.go +++ b/frontend/dockerui/attr.go @@ -17,7 +17,7 @@ import ( func parsePlatforms(v string) ([]ocispecs.Platform, error) { var pp []ocispecs.Platform - for _, v := range strings.Split(v, ",") { + for v := range strings.SplitSeq(v, ",") { p, err := platforms.Parse(v) if err != nil { return nil, errors.Wrapf(err, "failed to parse target platform %s", v) diff --git a/frontend/dockerui/config.go b/frontend/dockerui/config.go index 6c3f9f5f3..619b83457 100644 --- a/frontend/dockerui/config.go +++ b/frontend/dockerui/config.go @@ -237,8 +237,8 @@ func (bc *Client) init() error { } // old API if cacheFromStr := opts[keyCacheFrom]; cacheFromStr != "" { - cacheFrom := strings.Split(cacheFromStr, ",") - for _, s := range cacheFrom { + cacheFrom := strings.SplitSeq(cacheFromStr, ",") + for s := range cacheFrom { im := client.CacheOptionsEntry{ Type: "registry", Attrs: map[string]string{ diff --git a/solver/llbsolver/provenance/types/types.go b/solver/llbsolver/provenance/types/types.go index 952c9720d..f2e38a52d 100644 --- a/solver/llbsolver/provenance/types/types.go +++ b/solver/llbsolver/provenance/types/types.go @@ -103,33 +103,33 @@ func (ps *ProvenanceSLSA) Validate() error { type ProvenancePredicateSLSA02 struct { slsa02.ProvenancePredicate - Invocation ProvenanceInvocationSLSA02 `json:"invocation,omitempty"` + Invocation ProvenanceInvocationSLSA02 `json:"invocation"` BuildConfig *BuildConfig `json:"buildConfig,omitempty"` Metadata *ProvenanceMetadataSLSA02 `json:"metadata,omitempty"` } type ProvenanceInvocationSLSA02 struct { - ConfigSource slsa02.ConfigSource `json:"configSource,omitempty"` - Parameters Parameters `json:"parameters,omitempty"` - Environment Environment `json:"environment,omitempty"` + ConfigSource slsa02.ConfigSource `json:"configSource"` + Parameters Parameters `json:"parameters"` + Environment Environment `json:"environment"` } type ProvenanceMetadataSLSA02 struct { slsa02.ProvenanceMetadata - BuildKitMetadata BuildKitMetadata `json:"https://mobyproject.org/buildkit@v1#metadata,omitempty"` + BuildKitMetadata BuildKitMetadata `json:"https://mobyproject.org/buildkit@v1#metadata"` Hermetic bool `json:"https://mobyproject.org/buildkit@v1#hermetic,omitempty"` } type ProvenancePredicateSLSA1 struct { slsa1.ProvenancePredicate - BuildDefinition ProvenanceBuildDefinitionSLSA1 `json:"buildDefinition,omitempty"` - RunDetails ProvenanceRunDetailsSLSA1 `json:"runDetails,omitempty"` + BuildDefinition ProvenanceBuildDefinitionSLSA1 `json:"buildDefinition"` + RunDetails ProvenanceRunDetailsSLSA1 `json:"runDetails"` } type ProvenanceBuildDefinitionSLSA1 struct { slsa1.ProvenanceBuildDefinition - ExternalParameters ProvenanceExternalParametersSLSA1 `json:"externalParameters,omitempty"` - InternalParameters ProvenanceInternalParametersSLSA1 `json:"internalParameters,omitempty"` + ExternalParameters ProvenanceExternalParametersSLSA1 `json:"externalParameters"` + InternalParameters ProvenanceInternalParametersSLSA1 `json:"internalParameters"` } type ProvenanceRunDetailsSLSA1 struct { @@ -138,8 +138,8 @@ type ProvenanceRunDetailsSLSA1 struct { } type ProvenanceExternalParametersSLSA1 struct { - ConfigSource ProvenanceConfigSourceSLSA1 `json:"configSource,omitempty"` - Request Parameters `json:"request,omitempty"` + ConfigSource ProvenanceConfigSourceSLSA1 `json:"configSource"` + Request Parameters `json:"request"` } type ProvenanceConfigSourceSLSA1 struct { @@ -155,9 +155,9 @@ type ProvenanceInternalParametersSLSA1 struct { type ProvenanceMetadataSLSA1 struct { slsa1.BuildMetadata - BuildKitMetadata BuildKitMetadata `json:"buildkit_metadata,omitempty"` + BuildKitMetadata BuildKitMetadata `json:"buildkit_metadata"` Hermetic bool `json:"buildkit_hermetic,omitempty"` - Completeness BuildKitComplete `json:"buildkit_completeness,omitempty"` + Completeness BuildKitComplete `json:"buildkit_completeness"` Reproducible bool `json:"buildkit_reproducible,omitempty"` } diff --git a/util/cachedigest/digest.go b/util/cachedigest/digest.go index 7407eddee..0637ddefe 100644 --- a/util/cachedigest/digest.go +++ b/util/cachedigest/digest.go @@ -121,11 +121,11 @@ func (r *Record) LoadSubRecords(loader func(d digest.Digest) (Type, []Frame, err } } case TypeDigestList: - for _, dgst := range bytes.Split(dt, []byte{0}) { + for dgst := range bytes.SplitSeq(dt, []byte{0}) { checksums = append(checksums, string(dgst)) } case TypeFileList: - for _, nameChecksumPair := range bytes.Split(dt, []byte{0}) { + for nameChecksumPair := range bytes.SplitSeq(dt, []byte{0}) { idx := bytes.LastIndex(nameChecksumPair, []byte("sha256:")) if idx < 0 { bklog.L.Warnf("invalid file list entry %q, missing sha256 prefix", nameChecksumPair) diff --git a/util/resolvconf/resolvconf_test.go b/util/resolvconf/resolvconf_test.go index 6b2cf35e1..2a2dcd1c9 100644 --- a/util/resolvconf/resolvconf_test.go +++ b/util/resolvconf/resolvconf_test.go @@ -697,7 +697,7 @@ func BenchmarkGenerate(b *testing.B) { } b.ReportAllocs() - for i := 0; i < b.N; i++ { + for b.Loop() { _, err := rc.Generate(true) if err != nil { b.Fatal(err) diff --git a/util/resolver/authorizer.go b/util/resolver/authorizer.go index 0f63a7247..aadb56676 100644 --- a/util/resolver/authorizer.go +++ b/util/resolver/authorizer.go @@ -453,7 +453,7 @@ func parseScopes(s []string) scopes { return nil } // The scopeStr may have strings that contain multiple scopes separated by a space. - for _, scope := range strings.Split(scopeStr, " ") { + for scope := range strings.SplitSeq(scopeStr, " ") { parts := strings.SplitN(scope, ":", 3) names := []string{parts[0]} if len(parts) > 1 { diff --git a/util/testutil/dockerd/config.go b/util/testutil/dockerd/config.go index abedf706f..de9ed4f3b 100644 --- a/util/testutil/dockerd/config.go +++ b/util/testutil/dockerd/config.go @@ -3,7 +3,7 @@ package dockerd type Config struct { Features map[string]bool `json:"features,omitempty"` Mirrors []string `json:"registry-mirrors,omitempty"` - Builder BuilderConfig `json:"builder,omitempty"` + Builder BuilderConfig `json:"builder"` } type BuilderEntitlements struct { @@ -13,5 +13,5 @@ type BuilderEntitlements struct { } type BuilderConfig struct { - Entitlements BuilderEntitlements `json:",omitempty"` + Entitlements BuilderEntitlements } diff --git a/util/testutil/workers/containerd.go b/util/testutil/workers/containerd.go index d73e5dd89..7ef31d12d 100644 --- a/util/testutil/workers/containerd.go +++ b/util/testutil/workers/containerd.go @@ -25,8 +25,8 @@ func InitContainerdWorker() { // defined in Dockerfile // e.g. `containerd-1.1=/opt/containerd-1.1/bin,containerd-42.0=/opt/containerd-42.0/bin` if s := os.Getenv("BUILDKIT_INTEGRATION_CONTAINERD_EXTRA"); s != "" { - entries := strings.Split(s, ",") - for _, entry := range entries { + entries := strings.SplitSeq(s, ",") + for entry := range entries { pair := strings.Split(strings.TrimSpace(entry), "=") if len(pair) != 2 { panic(errors.Errorf("unexpected BUILDKIT_INTEGRATION_CONTAINERD_EXTRA: %q", s))