Skip to content

Commit

Permalink
chore: bump golangci-lint to 1.57.0
Browse files Browse the repository at this point in the history
Fix all discovered issues.

Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
  • Loading branch information
DmitriyMV committed Mar 20, 2024
1 parent 6840119 commit 19f15a8
Show file tree
Hide file tree
Showing 158 changed files with 141 additions and 380 deletions.
26 changes: 12 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ run:
# include test files or not, default is true
tests: true

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files:
- .*\\.pb\\.go$

# list of build tags, all linters use it. Default is empty list.
build-tags:
- integration
Expand All @@ -33,7 +26,12 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
format: line-number
formats:
- format: line-number
path: stdout
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
sort-results: true

# all available settings of specific linters
Expand All @@ -46,12 +44,7 @@ linters-settings:
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: true
govet:
# report about shadowed variables
check-shadowing: true
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
govet: { }
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 10
Expand Down Expand Up @@ -79,6 +72,8 @@ linters-settings:
allow-no-explanation: []
require-explanation: false
require-specific: true
unused:
local-variables-are-used: false
prealloc:
# XXX: we don't recommend using this linter before doing performance profiling.
# For most programs usage of prealloc will be a premature optimization.
Expand Down Expand Up @@ -166,6 +161,9 @@ issues:
- ^ST1000 # ST1000: at least one file in a package should have a package comment (stylecheck)
- parameter '\w+' seems to be unused, consider removing or renaming it as _ # noisy check, especially when the usage is an interface implementation

exclude-files:
- .*\\.pb\\.go$

exclude-rules:
- path: cmd/talosctl/cmd
linters:
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ FROM base AS lint-go
COPY .golangci.yml .
ENV GOGC 50
ENV GOLANGCI_LINT_CACHE /.cache/lint
RUN golangci-lint config verify --config .golangci.yml
RUN --mount=type=cache,target=/.cache golangci-lint run --config .golangci.yml
WORKDIR /src/pkg/machinery
RUN --mount=type=cache,target=/.cache golangci-lint run --config ../../.golangci.yml
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ GOIMPORTS_VERSION ?= v0.19.0
# renovate: datasource=go depName=mvdan.cc/gofumpt
GOFUMPT_VERSION ?= v0.6.0
# renovate: datasource=go depName=github.com/golangci/golangci-lint
GOLANGCILINT_VERSION ?= v1.56.2
GOLANGCILINT_VERSION ?= v1.57.0
# renovate: datasource=go depName=golang.org/x/tools
STRINGER_VERSION ?= v0.19.0
# renovate: datasource=go depName=github.com/dmarkham/enumer
Expand Down
4 changes: 0 additions & 4 deletions cmd/installer/pkg/install/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ func (m *Manifest) checkMounts(device Device) error {
}

for _, path := range matches {
path := path

if err = func() error {
var f *os.File

Expand Down Expand Up @@ -390,8 +388,6 @@ func (m *Manifest) executeOnDevice(device Device, targets []*Target) (err error)
}

for _, target := range targets {
target := target

err = retry.Constant(time.Minute, retry.WithUnits(100*time.Millisecond)).Retry(func() error {
e := target.Format(m.Printf)
if e != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/talosctl/cmd/mgmt/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ func create(ctx context.Context, flags *pflag.FlagSet) error {
endpointList = []string{ips[0][0].String()}
default:
// use control plane nodes as endpoints, client-side load-balancing
for i := 0; i < controlplanes; i++ {
for i := range controlplanes {
endpointList = append(endpointList, ips[0][i].String())
}
}
Expand Down Expand Up @@ -750,7 +750,7 @@ func create(ctx context.Context, flags *pflag.FlagSet) error {
provisionOptions = append(provisionOptions, provision.WithTalosConfig(configBundle.TalosConfig()))

// Create the controlplane nodes.
for i := 0; i < controlplanes; i++ {
for i := range controlplanes {
var cfg config.Provider

nodeIPs := make([]netip.Addr, len(cidrs))
Expand Down Expand Up @@ -796,7 +796,7 @@ func create(ctx context.Context, flags *pflag.FlagSet) error {
}

// append extra disks
for i := 0; i < extraDisks; i++ {
for range extraDisks {
disks = append(disks, &provision.Disk{
Size: uint64(extraDiskSize) * 1024 * 1024,
SkipPreallocate: !clusterDiskPreallocate,
Expand Down
1 change: 0 additions & 1 deletion cmd/talosctl/cmd/talos/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ Certificate expires: 10 years from now (2031-07-03)
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down
11 changes: 5 additions & 6 deletions cmd/talosctl/cmd/talos/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ func containerRender(remotePeer *peer.Peer, resp *machineapi.ContainersResponse)
defaultNode := client.AddrFromPeer(remotePeer)

for _, msg := range resp.Messages {
resp := msg
sort.Slice(resp.Containers,
sort.Slice(msg.Containers,
func(i, j int) bool {
return strings.Compare(resp.Containers[i].Id, resp.Containers[j].Id) < 0
return strings.Compare(msg.Containers[i].Id, msg.Containers[j].Id) < 0
})

for _, p := range resp.Containers {
for _, p := range msg.Containers {
display := p.Id
if p.Id != p.PodId {
// container in a sandbox
Expand All @@ -84,8 +83,8 @@ func containerRender(remotePeer *peer.Peer, resp *machineapi.ContainersResponse)

node := defaultNode

if resp.Metadata != nil {
node = resp.Metadata.Hostname
if msg.Metadata != nil {
node = msg.Metadata.Hostname
}

fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\t%s\n", node, p.Namespace, display, p.Image, p.Pid, p.Status)
Expand Down
2 changes: 1 addition & 1 deletion cmd/talosctl/cmd/talos/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var logsCmd = &cobra.Command{
continue
}

node := defaultNode
node := defaultNode //nolint:copyloopvar
if data.Metadata != nil && data.Metadata.Hostname != "" {
node = data.Metadata.Hostname
}
Expand Down
11 changes: 5 additions & 6 deletions cmd/talosctl/cmd/talos/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ func statsRender(remotePeer *peer.Peer, resp *machineapi.StatsResponse) error {
defaultNode := client.AddrFromPeer(remotePeer)

for _, msg := range resp.Messages {
resp := msg
sort.Slice(resp.Stats,
sort.Slice(msg.Stats,
func(i, j int) bool {
return strings.Compare(resp.Stats[i].Id, resp.Stats[j].Id) < 0
return strings.Compare(msg.Stats[i].Id, msg.Stats[j].Id) < 0
})

for _, s := range resp.Stats {
for _, s := range msg.Stats {
display := s.Id
if s.Id != s.PodId {
// container in a sandbox
Expand All @@ -84,8 +83,8 @@ func statsRender(remotePeer *peer.Peer, resp *machineapi.StatsResponse) error {

node := defaultNode

if resp.Metadata != nil {
node = resp.Metadata.Hostname
if msg.Metadata != nil {
node = msg.Metadata.Hostname
}

fmt.Fprintf(w, "%s\t%s\t%s\t%.2f\t%d\n", node, s.Namespace, display, float64(s.MemoryUsage)*1e-6, s.CpuUsage)
Expand Down
2 changes: 0 additions & 2 deletions cmd/talosctl/pkg/talos/action/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ func (a *Tracker) Run() error {
var trackEg errgroup.Group

for _, node := range a.cliContext.Nodes {
node := node

var (
dmesg *circular.Buffer
err error
Expand Down
2 changes: 0 additions & 2 deletions cmd/talosctl/pkg/talos/yamlstrip/yamlstrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ func TestComments(t *testing.T) {
require.NoError(t, err)

for _, path := range testCases {
path := path

t.Run(filepath.Base(path), func(t *testing.T) {
in, err := os.ReadFile(path)
require.NoError(t, err)
Expand Down
5 changes: 0 additions & 5 deletions hack/cloud-image-uploader/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ func (au *AWSUploader) RegisterAMIs(ctx context.Context) error {
g, ctx = errgroup.WithContext(ctx)

for region, svc := range au.ec2svcs {
region := region
svc := svc

g.Go(func() error {
err := au.registerAMI(ctx, region, svc)
if err != nil {
Expand Down Expand Up @@ -147,8 +144,6 @@ func (au *AWSUploader) registerAMI(ctx context.Context, region string, svc *ec2.
var g errgroup.Group

for _, arch := range au.Options.Architectures {
arch := arch

g.Go(func() error {
err = au.registerAMIArch(ctx, region, svc, arch, bucketName, uploader)
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions hack/cloud-image-uploader/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ func (azu *AzureUploader) AzureGalleryUpload(ctx context.Context) error {
log.Printf("azure: uploading blobs for architectures: %+v\n", azu.Options.Architectures)

for _, arch := range azu.Options.Architectures {
arch := arch

g.Go(func() error {
log.Printf("azure: starting upload blob for %s\n", arch)

Expand Down Expand Up @@ -190,7 +188,7 @@ func (azu *AzureUploader) uploadAzureBlob(ctx context.Context, arch string) erro
var g *errgroup.Group
g, ctx = errgroup.WithContext(ctx)

for i := 0; i < concurrency; i++ {
for range concurrency {
g.Go(func() error {
for w := range workCh {
_, err = pageBlobClient.UploadPages(
Expand Down
2 changes: 0 additions & 2 deletions hack/gotagsrewrite/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ func TestRun(t *testing.T) {
}

for name, test := range tests {
test := test

t.Run(name, func(t *testing.T) {
tempDir := t.TempDir()

Expand Down
2 changes: 1 addition & 1 deletion internal/app/apid/pkg/backend/apid_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (suite *APIDFactorySuite) TestGetConcurrent() {

backendCh := make(chan proxy.Backend, 10)

for i := 0; i < 10; i++ {
for range 10 {
wg.Add(1)

go func() {
Expand Down
22 changes: 11 additions & 11 deletions internal/app/apid/pkg/backend/apid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ func TestAPIIdiosyncrasies(t *testing.T) {
storage.File_storage_storage_proto.Services(),
time.File_time_time_proto.Services(),
} {
for i := 0; i < services.Len(); i++ {
for i := range services.Len() {
service := services.Get(i)
methods := service.Methods()

for j := 0; j < methods.Len(); j++ {
for j := range methods.Len() {
method := methods.Get(j)

t.Run(
Expand Down Expand Up @@ -320,7 +320,7 @@ func testEnum(t *testing.T, enum protoreflect.EnumDescriptor, currentVersion *co
testDeprecated(t, enum, currentVersion)

values := enum.Values()
for i := 0; i < values.Len(); i++ {
for i := range values.Len() {
testDeprecated(t, values.Get(i), currentVersion)
}
}
Expand All @@ -329,23 +329,23 @@ func testMessage(t *testing.T, message protoreflect.MessageDescriptor, currentVe
testDeprecated(t, message, currentVersion)

fields := message.Fields()
for i := 0; i < fields.Len(); i++ {
for i := range fields.Len() {
testDeprecated(t, fields.Get(i), currentVersion)
}

oneofs := message.Oneofs()
for i := 0; i < oneofs.Len(); i++ {
for i := range oneofs.Len() {
testDeprecated(t, oneofs.Get(i), currentVersion)
}

enums := message.Enums()
for i := 0; i < enums.Len(); i++ {
for i := range enums.Len() {
testEnum(t, enums.Get(i), currentVersion)
}

// test nested messages
messages := message.Messages()
for i := 0; i < messages.Len(); i++ {
for i := range messages.Len() {
testMessage(t, messages.Get(i), currentVersion)
}
}
Expand All @@ -364,22 +364,22 @@ func TestDeprecatedAPIs(t *testing.T) {
time.File_time_time_proto,
} {
enums := file.Enums()
for i := 0; i < enums.Len(); i++ {
for i := range enums.Len() {
testEnum(t, enums.Get(i), currentVersion)
}

messages := file.Messages()
for i := 0; i < messages.Len(); i++ {
for i := range messages.Len() {
testMessage(t, messages.Get(i), currentVersion)
}

services := file.Services()
for i := 0; i < services.Len(); i++ {
for i := range services.Len() {
service := services.Get(i)
testDeprecated(t, service, currentVersion)

methods := service.Methods()
for j := 0; j < methods.Len(); j++ {
for j := range methods.Len() {
method := methods.Get(j)
testDeprecated(t, method, currentVersion)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ func TestPeerStatus_CalculateState(t *testing.T) {
expectedState: kubespan.PeerStateUp,
},
} {
tt := tt

t.Run(tt.name, func(t *testing.T) {
peerStatus := kubespan.PeerStatusSpec{
LastHandshakeTime: time.Now().Add(-tt.sinceLastHandshake),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ func (ctrl *AffiliateMergeController) Run(ctx context.Context, r controller.Runt
touchedIDs := make(map[resource.ID]struct{}, len(mergedAffiliates))

for id, affiliateSpec := range mergedAffiliates {
affiliateSpec := affiliateSpec

if err = safe.WriterModify(ctx, r, cluster.NewAffiliate(cluster.NamespaceName, id), func(res *cluster.Affiliate) error {
*res.TypedSpec() = *affiliateSpec

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ func (ctrl *DiscoveryServiceController) Run(ctx context.Context, r controller.Ru
for _, discoveredAffiliate := range client.GetAffiliates() {
id := fmt.Sprintf("service/%s", discoveredAffiliate.Affiliate.NodeId)

discoveredAffiliate := discoveredAffiliate

if err = safe.WriterModify(ctx, r, cluster.NewAffiliate(cluster.RawNamespaceName, id), func(res *cluster.Affiliate) error {
*res.TypedSpec() = specAffiliate(discoveredAffiliate.Affiliate, discoveredAffiliate.Endpoints)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ func (ctrl *KubernetesPullController) Run(ctx context.Context, r controller.Runt
for _, affilateSpec := range affiliateSpecs {
id := fmt.Sprintf("k8s/%s", affilateSpec.NodeID)

affilateSpec := affilateSpec

if err = safe.WriterModify(ctx, r, cluster.NewAffiliate(cluster.RawNamespaceName, id), func(res *cluster.Affiliate) error {
*res.TypedSpec() = *affilateSpec

Expand Down
Loading

0 comments on commit 19f15a8

Please sign in to comment.