chore(ci): upgrade to golangci-lint 2.6.1 (#4973)

- upgrade to golangci-lint 2.6.1
- updates for gosec
- updates for govet
- updates for perfsprint
- updates modernize

Leaves out modernize:omitempty due to conflicts with tests
This commit is contained in:
Nathan Baulch
2025-11-12 16:27:10 +11:00
committed by GitHub
parent 19af93f2b1
commit 657fda216a
112 changed files with 73 additions and 191 deletions

View File

@@ -80,6 +80,9 @@ linters:
- (*go.uber.org/zap.SugaredLogger).With
misspell:
locale: US
modernize:
disable:
- omitzero
wsl_v5:
allow-whole-block: true
disable:

View File

@@ -236,8 +236,8 @@ func (c *commandBlobShardsModify) renameBlobs(ctx context.Context, dir, prefix s
if err := c.renameBlobs(ctx, path.Join(dir, ent.Name()), prefix+ent.Name(), params, numMoved, numUnchanged); err != nil {
return err
}
} else if strings.HasSuffix(ent.Name(), sharded.CompleteBlobSuffix) {
blobID := prefix + strings.TrimSuffix(ent.Name(), sharded.CompleteBlobSuffix)
} else if name, ok := strings.CutSuffix(ent.Name(), sharded.CompleteBlobSuffix); ok {
blobID := prefix + name
destDir, destBlobID := params.GetShardDirectoryAndBlob(c.rootPath, blob.ID(blobID))
srcFile := path.Join(dir, ent.Name())

View File

@@ -2,6 +2,7 @@
import (
"context"
"slices"
"sync"
"github.com/pkg/errors"
@@ -134,13 +135,7 @@ func (c *commandIndexInspect) shouldInclude(ci content.Info) bool {
contentID := ci.ContentID.String()
for _, cid := range c.contentIDs {
if cid == contentID {
return true
}
}
return false
return slices.Contains(c.contentIDs, contentID)
}
type indexBlobPlusContentInfo struct {

View File

@@ -2,6 +2,7 @@
import (
"context"
"slices"
"github.com/pkg/errors"
@@ -38,13 +39,7 @@ func (c *commandLogsShow) run(ctx context.Context, rep repo.DirectRepository) er
if len(c.logSessionIDs) > 0 {
sessions = filterLogSessions(sessions, func(l *logSessionInfo) bool {
for _, sid := range c.logSessionIDs {
if l.id == sid {
return true
}
}
return false
return slices.Contains(c.logSessionIDs, l.id)
})
}

View File

@@ -2,6 +2,7 @@
import (
"context"
"strings"
"time"
"github.com/pkg/errors"
@@ -123,16 +124,16 @@ func getMessageFromRun(extra []maintenancestats.Extra) string {
return succeed
}
extraStr := ""
var extraStr strings.Builder
for _, e := range extra {
if msg, err := maintenancestats.BuildFromExtra(e); err == nil {
extraStr += msg.Summary()
extraStr.WriteString(msg.Summary())
}
}
if extraStr != "" {
succeed = ": " + extraStr
if extraStr.Len() > 0 {
succeed = ": " + extraStr.String()
}
return succeed

View File

@@ -3,6 +3,7 @@
import (
"context"
"os"
"slices"
"strings"
"testing"
@@ -124,10 +125,8 @@ func verifyTemplateContents(t *testing.T, e *testenv.CLITest, templateName strin
func verifyHasLine(t *testing.T, lines []string, ok func(s string) bool) {
t.Helper()
for _, l := range lines {
if ok(l) {
return
}
if slices.ContainsFunc(lines, ok) {
return
}
t.Errorf("output line meeting given condition was not found: %v", lines)

View File

@@ -2,6 +2,7 @@
import (
"runtime"
"slices"
"testing"
"time"
@@ -221,11 +222,5 @@ func TestServerControlUDS(t *testing.T) {
}
func hasLine(lines []string, lookFor string) bool {
for _, l := range lines {
if l == lookFor {
return true
}
}
return false
return slices.Contains(lines, lookFor)
}

View File

@@ -3,6 +3,7 @@
import (
"context"
"path"
"slices"
"github.com/pkg/errors"
@@ -28,12 +29,10 @@ func (c *commandSnapshotFixRemoveFiles) setup(svc appServices, parent commandPar
}
func (c *commandSnapshotFixRemoveFiles) rewriteEntry(ctx context.Context, pathFromRoot string, ent *snapshot.DirEntry) (*snapshot.DirEntry, error) {
for _, id := range c.removeObjectIDs {
if ent.ObjectID.String() == id {
log(ctx).Infof("will remove file %v", pathFromRoot)
if slices.Contains(c.removeObjectIDs, ent.ObjectID.String()) {
log(ctx).Infof("will remove file %v", pathFromRoot)
return nil, nil
}
return nil, nil
}
for _, n := range c.removeFilesByName {

View File

@@ -1,5 +1,4 @@
//go:build !windows && !linux && !darwin
// +build !windows,!linux,!darwin
package cli

View File

@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows
package cli

View File

@@ -1,6 +1,4 @@
//go:build !windows && ((!amd64 && !arm64 && !arm && !ppc64 && !ppc64le && !s390x && !386 && !riscv64) || darwin || openbsd)
// +build !windows
// +build !amd64,!arm64,!arm,!ppc64,!ppc64le,!s390x,!386,!riscv64 darwin openbsd
package localfs

View File

@@ -1,8 +1,4 @@
//go:build !windows && !openbsd && !darwin && (amd64 || arm64 || arm || ppc64 || ppc64le || s390x || 386 || riscv64)
// +build !windows
// +build !openbsd
// +build !darwin
// +build amd64 arm64 arm ppc64 ppc64le s390x 386 riscv64
package localfs

View File

@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows
package localfs

View File

@@ -2,6 +2,7 @@
import (
"fmt"
"slices"
"sort"
"strings"
@@ -81,10 +82,8 @@ func nonEmptyString(v string) error {
func oneOf(allowed ...string) valueValidatorFunc {
return func(v string) error {
for _, a := range allowed {
if v == a {
return nil
}
if slices.Contains(allowed, v) {
return nil
}
return errors.Errorf("must be one of: %v", strings.Join(allowed, ", "))

View File

@@ -1,5 +1,4 @@
//go:build !testing
// +build !testing
package clock

View File

@@ -1,5 +1,4 @@
//go:build testing
// +build testing
package clock

View File

@@ -1,5 +1,4 @@
//go:build testing
// +build testing
package crypto

View File

@@ -4,6 +4,7 @@
import (
"fmt"
"slices"
)
// IfNotUnderstood describes the behavior of Kopia when a required feature is not understood.
@@ -58,11 +59,5 @@ func GetUnsupportedFeatures(required []Required, supported []Feature) []Required
}
func isSupported(req Required, supported []Feature) bool {
for _, s := range supported {
if req.Feature == s {
return true
}
}
return false
return slices.Contains(supported, req.Feature)
}

View File

@@ -1,5 +1,4 @@
//go:build !windows && !openbsd && !freebsd
// +build !windows,!openbsd,!freebsd
// Package fusemount implements FUSE filesystem nodes for mounting contents of filesystem stored in repository.
//

View File

@@ -61,7 +61,7 @@ func InfoDiff(i1, i2 index.Info, ignore ...string) []string {
// dear future reader, if this fails because the number of methods has changed,
// you need to add additional verification above.
if cnt := reflect.TypeOf(index.Info{}).NumMethod(); cnt != 1 {
if cnt := reflect.TypeFor[index.Info]().NumMethod(); cnt != 1 {
diffs = append(diffs, fmt.Sprintf("unexpected number of methods on content.Info: %v, must update the test", cnt))
}

View File

@@ -5,6 +5,7 @@
import (
"context"
"encoding/json"
"slices"
"strings"
"time"
@@ -140,13 +141,7 @@ func (s *listCacheStorage) DeleteBlob(ctx context.Context, blobID blob.ID) error
}
func (s *listCacheStorage) isCachedPrefix(prefix blob.ID) bool {
for _, p := range s.prefixes {
if prefix == p {
return true
}
}
return false
return slices.Contains(s.prefixes, prefix)
}
func (s *listCacheStorage) invalidateAfterUpdate(ctx context.Context, blobID blob.ID) {

View File

@@ -1,5 +1,4 @@
//go:build !windows && !freebsd && !openbsd
// +build !windows,!freebsd,!openbsd
package mount

View File

@@ -1,5 +1,4 @@
//go:build windows
// +build windows
package mount

View File

@@ -1,5 +1,4 @@
//go:build !windows && !freebsd && !openbsd
// +build !windows,!freebsd,!openbsd
package mount

View File

@@ -1,5 +1,4 @@
//go:build freebsd || openbsd
// +build freebsd openbsd
package mount

View File

@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows
package osexec

View File

@@ -1,5 +1,4 @@
//go:build !windows && !darwin && !openbsd
// +build !windows,!darwin,!openbsd
package ospath

View File

@@ -1,5 +1,4 @@
//go:build !nohtmlui
// +build !nohtmlui
package server

View File

@@ -1,5 +1,4 @@
//go:build nohtmlui
// +build nohtmlui
package server

View File

@@ -1,5 +1,4 @@
//go:build openbsd
// +build openbsd
// Package stat provides a cross-platform abstraction for
// common stat commands.

View File

@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows
package stat

View File

@@ -1,5 +1,4 @@
//go:build linux || freebsd || darwin
// +build linux freebsd darwin
// Package stat provides a cross-platform abstraction for common stat commands.
package stat

View File

@@ -1,5 +1,4 @@
//go:build windows
// +build windows
// Package stat provides a cross-platform abstraction for
// common stat commands.

View File

@@ -1,5 +1,4 @@
//go:build linux
// +build linux
package tempfile

View File

@@ -1,5 +1,4 @@
//go:build linux || freebsd || darwin || openbsd
// +build linux freebsd darwin openbsd
package tempfile

View File

@@ -1,5 +1,4 @@
//go:build freebsd || darwin || openbsd
// +build freebsd darwin openbsd
package tempfile

View File

@@ -1,5 +1,4 @@
//go:build !race
// +build !race
package testutil

View File

@@ -1,5 +1,4 @@
//go:build race
// +build race
package testutil

View File

@@ -106,13 +106,7 @@ func (m *Manager) WaitForTask(ctx context.Context, taskID string, maxWaitTime ti
deadline := clock.Now().Add(maxWaitTime)
sleepInterval := min(
//nolint:mnd
maxWaitTime/10, maxWaitInterval)
if sleepInterval < minWaitInterval {
sleepInterval = minWaitInterval
}
sleepInterval := max(min(maxWaitTime/10, maxWaitInterval), minWaitInterval) //nolint:mnd
for maxWaitTime < 0 || clock.Now().Before(deadline) {
if !clock.SleepInterruptibly(ctx, sleepInterval) {

View File

@@ -1,5 +1,4 @@
//go:build openbsd
// +build openbsd
package filesystem

View File

@@ -1,5 +1,4 @@
//go:build linux || freebsd || darwin
// +build linux freebsd darwin
package filesystem

View File

@@ -1,5 +1,4 @@
//go:build windows
// +build windows
package filesystem

View File

@@ -1,5 +1,4 @@
//go:build linux || freebsd || darwin
// +build linux freebsd darwin
package filesystem

View File

@@ -1,5 +1,4 @@
//go:build !linux && !freebsd && !darwin
// +build !linux,!freebsd,!darwin
package filesystem

View File

@@ -1,5 +1,4 @@
//go:build linux || freebsd || darwin
// +build linux freebsd darwin
package filesystem

View File

@@ -1,5 +1,4 @@
//go:build !linux && !freebsd && !darwin
// +build !linux,!freebsd,!darwin
package filesystem

View File

@@ -1,5 +1,4 @@
//go:build linux || freebsd || darwin
// +build linux freebsd darwin
package filesystem

View File

@@ -143,8 +143,7 @@ func (c *diskCommittedContentIndexCache) expireUnused(ctx context.Context, used
return errors.Wrap(err, "failed to read file info")
}
if strings.HasSuffix(ent.Name(), simpleIndexSuffix) {
n := strings.TrimSuffix(ent.Name(), simpleIndexSuffix)
if n, ok := strings.CutSuffix(ent.Name(), simpleIndexSuffix); ok {
remaining[blob.ID(n)] = fi
}
}

View File

@@ -97,7 +97,7 @@ func (b Builder) sortedContents() []*Info {
// Phase 3 - merge results from all buckets.
result := make([]*Info, 0, len(b))
for i := range len(buckets) { //nolint:intrange
for i := range buckets {
result = append(result, buckets[i]...)
}

View File

@@ -351,7 +351,7 @@ func readLength(shards [][]byte, sizes *sizesInfo) (originalSize, startShard, st
startShard = 4
startByte = 0
for i := range 4 {
for i := range lengthBuffer {
lengthBuffer[i] = shards[i][0]
}

View File

@@ -1,5 +1,4 @@
//go:build !testing
// +build !testing
package format

View File

@@ -1,5 +1,4 @@
//go:build testing
// +build testing
package format

View File

@@ -5,6 +5,7 @@
"encoding/json"
"fmt"
"reflect"
"slices"
"strings"
"testing"
"time"
@@ -37,10 +38,8 @@ func checkPopulated(
)
}
for _, typ := range ignoreTypeSubfields {
if typ == v.Type() {
return
}
if slices.Contains(ignoreTypeSubfields, v.Type()) {
return
}
switch v.Kind() {

View File

@@ -11,6 +11,7 @@
"math/rand"
"runtime"
"runtime/debug"
"slices"
"sync"
"testing"
@@ -393,10 +394,8 @@ func TestObjectWriterRaceBetweenCheckpointAndResult(t *testing.T) {
return errors.Wrapf(err, "Checkpoint() returned invalid object %v", cpID)
}
for _, id := range ids {
if id == content.EmptyID {
return errors.New("checkpoint returned empty id")
}
if slices.Contains(ids, content.EmptyID) {
return errors.New("checkpoint returned empty id")
}
}

View File

@@ -25,13 +25,13 @@
func TestPolicyDefinition(t *testing.T) {
// verify that each field in the policy struct recursively matches a corresponding field
// from the policy.Definition() struct.
ensureTypesMatch(t, reflect.TypeOf(policy.Policy{}), reflect.TypeOf(policy.Definition{}))
ensureTypesMatch(t, reflect.TypeFor[policy.Policy](), reflect.TypeFor[policy.Definition]())
}
func ensureTypesMatch(t *testing.T, policyType, definitionType reflect.Type) {
t.Helper()
sourceInfoType := reflect.TypeOf(snapshot.SourceInfo{})
sourceInfoType := reflect.TypeFor[snapshot.SourceInfo]()
for i := range policyType.NumField() {
f := policyType.Field(i)
@@ -57,7 +57,7 @@ func ensureTypesMatch(t *testing.T, policyType, definitionType reflect.Type) {
}
func TestPolicyMerge(t *testing.T) {
testPolicyMerge(t, reflect.TypeOf(policy.Policy{}), reflect.TypeOf(policy.Definition{}), "")
testPolicyMerge(t, reflect.TypeFor[policy.Policy](), reflect.TypeFor[policy.Definition](), "")
}
//nolint:thelper

View File

@@ -1,5 +1,4 @@
//go:build linux || freebsd || openbsd
// +build linux freebsd openbsd
package restore

View File

@@ -1,5 +1,4 @@
//go:build !windows && !plan9
// +build !windows,!plan9
package restore

View File

@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows
package upload

View File

@@ -1,5 +1,4 @@
//go:build !race
// +build !race
package endtoend_test

View File

@@ -1,6 +1,7 @@
package endtoend_test
import (
"slices"
"strings"
"testing"
@@ -75,10 +76,8 @@ func (s *formatSpecificTestSuite) TestRepositorySetClient(t *testing.T) {
func verifyHasLine(t *testing.T, lines []string, ok func(s string) bool) {
t.Helper()
for _, l := range lines {
if ok(l) {
return
}
if slices.ContainsFunc(lines, ok) {
return
}
t.Errorf("output line meeting given condition was not found")

View File

@@ -6,6 +6,7 @@
"path/filepath"
"reflect"
"runtime"
"slices"
"sort"
"strings"
"testing"
@@ -643,10 +644,8 @@ func TestSnapshotCreateWithStdinStream(t *testing.T) {
}
func appendIfMissing(slice []string, i string) []string {
for _, ele := range slice {
if ele == i {
return slice
}
if slices.Contains(slice, i) {
return slice
}
return append(slice, i)

View File

@@ -1,4 +1,3 @@
//go:build !windows
// +build !windows
package os_snapshot_test

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
// Package blobmanipulator provides the framework for snapshot fix testing.
package blobmanipulator

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package recovery

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package recovery

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
// Package checker defines the framework for creating and restoring snapshots
// with a data integrity check

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package engine

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
// Package engine provides the framework for a snapshot repository testing engine
package engine

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package engine

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package engine

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package engine

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package engine

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package robustness

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package robustness

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
// Package fiofilewriter provides a FileWriter based on FIO.
package fiofilewriter

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package framework

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package framework

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
// Package framework contains tools to enable multiple clients to connect to a
// central repository server and run robustness tests concurrently.

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package framework

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package framework

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package multiclienttest

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package multiclienttest

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
// Package storagestats contains logging mechanism
// log disk space consumed by directories created by

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package robustness

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package robustness

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package robustness

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package robustness

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package snapmeta

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package snapmeta

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package snapmeta

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package snapmeta

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
// Package snapmeta provides Kopia implementations of Persister and Snapshotter.
package snapmeta

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package snapmeta

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package snapmeta

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package snapmeta

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package snapmeta

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package snapmeta

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
package snapmeta

View File

@@ -1,5 +1,4 @@
//go:build darwin || (linux && amd64)
// +build darwin linux,amd64
// Package robustness contains tests that validate data stability over time.
// The package, while designed for Kopia, is written with abstractions that

View File

@@ -1,5 +1,4 @@
//go:build linux
// +build linux
package socketactivation_test

Some files were not shown because too many files have changed in this diff Show More