Skip to content

Commit fc8fff2

Browse files
committed
rpk: bump golangci-lint to v2 and fix issues
This bump increased the accuracy and the report showed up to 100 issues. One of the major changes that were not fixed by the `--fix` flag were: - Package naming: common -> better names - net, os, utils -> netutil, osutil, rpkutil to avoid collision with standard naming packages - Context handling in the container package. We were using a context.Background with a timeout instead of the command context. There are further improvements to be made as moving away from some of the code in rpkutil and eliminating the containerutil package but these will be handled in separate commits to not hinder the review of this one. In addition we are also bumping the golangci-lint version in our Github Actions.
1 parent 7e0f30d commit fc8fff2

File tree

182 files changed

+778
-785
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+778
-785
lines changed

.github/workflows/lint-golang.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- name: Checkout code
23-
uses: actions/checkout@v4
23+
uses: actions/checkout@v5
2424
- name: Setup go
25-
uses: actions/setup-go@v5
25+
uses: actions/setup-go@v6
2626
with:
2727
go-version: stable
2828
cache-dependency-path: src/go/rpk/go.mod
2929
- name: Run golangci-lint
30-
uses: golangci/golangci-lint-action@v6
30+
uses: golangci/golangci-lint-action@v9
3131
with:
3232
version: latest
3333
args: --timeout 10m --verbose

src/go/.goreleaser.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ builds:
99
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.version={{.Tag}}
1010
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.rev={{.ShortCommit}}
1111
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.buildTime={{.Date}}
12-
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common.tag={{.Tag}}
12+
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil.tag={{.Tag}}
1313
env:
1414
- CGO_ENABLED=0
1515
goos:
@@ -26,7 +26,7 @@ builds:
2626
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.version={{.Tag}}
2727
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.rev={{.ShortCommit}}
2828
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.buildTime={{.Date}}
29-
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common.tag={{.Tag}}
29+
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil.tag={{.Tag}}
3030
env:
3131
- 'CGO_ENABLED={{ if index .Env "CGO_ENABLED" }}{{ .Env.CGO_ENABLED }}{{ else }}0{{ end }}'
3232
tags:
@@ -44,7 +44,7 @@ builds:
4444
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.version={{.Tag}}
4545
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.rev={{.ShortCommit}}
4646
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.buildTime={{.Date}}
47-
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common.tag={{.Tag}}
47+
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil.tag={{.Tag}}
4848
env:
4949
- CGO_ENABLED=0
5050
goos:
@@ -60,7 +60,7 @@ builds:
6060
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.version={{.Tag}}
6161
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.rev={{.ShortCommit}}
6262
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.buildTime={{.Date}}
63-
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common.tag={{.Tag}}
63+
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil.tag={{.Tag}}
6464
env:
6565
- CGO_ENABLED=0
6666
goos:
@@ -76,7 +76,7 @@ builds:
7676
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.version={{.Tag}}
7777
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.rev={{.ShortCommit}}
7878
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.buildTime={{.Date}}
79-
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common.tag={{.Tag}}
79+
- -X github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil.tag={{.Tag}}
8080
env:
8181
- CGO_ENABLED=0
8282
goos:

src/go/rpk/.golangci.yml

Lines changed: 90 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
1+
version: "2"
12
run:
2-
allow-parallel-runners: true
33
tests: false
4-
5-
# golangci-lint by default ignores some staticcheck and vet raised issues that
6-
# are actually important to catch. The following ensures that we do not ignore
7-
# those tools ever.
8-
issues:
9-
exclude-use-default: false
10-
11-
# We opt out of all suggested linters and manually pick what we want.
12-
# Please do not use enable-all.
4+
allow-parallel-runners: true
135
linters:
14-
disable-all: true
6+
# golangci-lint by default ignores some staticcheck and vet raised issues that
7+
# are actually important to catch. The following ensures that we do not ignore
8+
# those tools ever.
9+
default: none
10+
# We opt out of all suggested linters and manually pick what we want.
11+
# Please do not use enable-all.
1512
enable:
16-
# Enabled by default linters:
17-
- gosimple
18-
- govet
19-
- ineffassign
20-
- staticcheck
21-
- typecheck
22-
- unused
23-
# Disabled by default
2413
- asciicheck
2514
- bidichk
2615
- bodyclose
@@ -29,79 +18,94 @@ linters:
2918
- errname
3019
- errorlint
3120
- godot
32-
- gofmt
33-
- gofumpt
34-
- goimports
3521
- goprintffuncname
22+
- govet
23+
- ineffassign
3624
- misspell
3725
- nilerr
3826
- noctx
3927
- nolintlint
4028
- revive
41-
- usetesting
29+
- staticcheck
4230
- unconvert
31+
- unused
32+
- usetesting
4333
- wastedassign
4434
- whitespace
45-
46-
linters-settings:
47-
# We do not want to enforce every usage of fmt.Errorf to use %w.
48-
errorlint:
49-
errorf: false
50-
51-
# If we want to opt out of a lint, we require an explanation.
52-
nolintlint:
53-
allow-unused: false
54-
require-explanation: true
55-
require-specific: true
56-
57-
# Revive is yet another metalinter with a lot of useful lints.
58-
# The below opts in to all the ones we would like to use.
59-
revive:
60-
ignore-generated-header: true
61-
severity: warning
62-
confidence: 0.6
63-
rules:
64-
- name: atomic
65-
- name: blank-imports
66-
- name: bool-literal-in-expr
67-
- name: call-to-gc
68-
- name: confusing-results
69-
- name: constant-logical-expr
70-
- name: context-as-argument
71-
- name: context-keys-type
72-
- name: defer
73-
- name: dot-imports
74-
- name: duplicated-imports
75-
- name: early-return
76-
- name: error-naming
77-
- name: error-return
78-
- name: error-strings
79-
arguments:
80-
- out.Die
81-
- out.MaybeDie
82-
- out.DieString
83-
- out.MaybeDieString
84-
- name: get-return
85-
- name: identical-branches
86-
- name: if-return
87-
- name: modifies-value-receiver
88-
- name: optimize-operands-order
89-
- name: package-comments
90-
disabled: true # disabling this in favor of https://github.com/redpanda-data/redpanda/issues/6340
91-
- name: range
92-
- name: range-val-in-closure
93-
- name: receiver-naming
94-
- name: string-of-int
95-
- name: struct-tag
96-
- name: superfluous-else
97-
- name: time-equal
98-
- name: time-naming
99-
- name: unconditional-recursion
100-
- name: unnecessary-stmt
101-
- name: unreachable-code
102-
- name: unused-parameter
103-
- name: unused-receiver
104-
- name: useless-break
105-
- name: var-declaration
106-
- name: var-naming
107-
- name: waitgroup-by-value
35+
settings:
36+
errorlint:
37+
# We do not want to enforce every usage of fmt.Errorf to use %w.
38+
errorf: false
39+
nolintlint:
40+
# If we want to opt out of a lint, we require an explanation.
41+
require-explanation: true
42+
require-specific: true
43+
allow-unused: false
44+
# Revive is yet another metalinter with a lot of useful lints.
45+
# The below opts in to all the ones we would like to use.
46+
revive:
47+
confidence: 0.6
48+
severity: warning
49+
rules:
50+
- name: atomic
51+
- name: blank-imports
52+
- name: bool-literal-in-expr
53+
- name: call-to-gc
54+
- name: confusing-results
55+
- name: constant-logical-expr
56+
- name: context-as-argument
57+
- name: context-keys-type
58+
- name: defer
59+
- name: dot-imports
60+
- name: duplicated-imports
61+
- name: early-return
62+
- name: error-naming
63+
- name: error-return
64+
- name: error-strings
65+
exclude: ["Redpanda"]
66+
arguments:
67+
- out.Die
68+
- out.MaybeDie
69+
- out.DieString
70+
- out.MaybeDieString
71+
- name: get-return
72+
- name: identical-branches
73+
- name: if-return
74+
- name: modifies-value-receiver
75+
- name: optimize-operands-order
76+
- name: package-comments
77+
disabled: true
78+
- name: range
79+
- name: range-val-in-closure
80+
- name: receiver-naming
81+
- name: string-of-int
82+
- name: struct-tag
83+
- name: superfluous-else
84+
- name: time-equal
85+
- name: time-naming
86+
- name: unconditional-recursion
87+
- name: unnecessary-stmt
88+
- name: unreachable-code
89+
- name: unused-parameter
90+
- name: unused-receiver
91+
- name: useless-break
92+
- name: var-declaration
93+
- name: var-naming
94+
- name: waitgroup-by-value
95+
exclusions:
96+
generated: lax
97+
paths:
98+
- third_party$
99+
- builtin$
100+
- examples$
101+
formatters:
102+
enable:
103+
- gofmt
104+
- gofumpt
105+
- goimports
106+
exclusions:
107+
generated: lax
108+
paths:
109+
- third_party$
110+
- builtin$
111+
- examples$

src/go/rpk/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ VER := $(or $(VERSION),local-dev)
3030
IMG_TAG:= $(or $(VERSION),latest)
3131
BUILD_TIME=$(shell date -Iseconds)
3232
VER_PKG='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version'
33-
CONT_PKG='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common'
33+
CONT_PKG='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil'
3434

3535
LDFLAGS=-X $(VER_PKG).version=$(VER) -X $(VER_PKG).rev=$(REV) -X $(CONT_PKG).tag=$(IMG_TAG) -X ${VER_PKG}.hostOs=${GOOS} -X ${VER_PKG}.hostArch=${GOARCH} -X ${VER_PKG}.buildTime=${BUILD_TIME}
3636

src/go/rpk/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ out_dir="$(go env GOOS)-$(go env GOARCH)"
2222
mkdir -p "${out_dir}"
2323

2424
ver_pkg='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version'
25-
cont_pkg='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common'
25+
cont_pkg='github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil'
2626

2727
go build \
2828
-ldflags "-X ${ver_pkg}.version=${version} -X ${ver_pkg}.rev=${rev} -X ${cont_pkg}.tag=${img_tag} -X ${ver_pkg}.buildTime=${buildTime} -X ${ver_pkg}.hostOs=${hostOs} -X ${ver_pkg}.hostArch=${hostArch}" \

src/go/rpk/cmd/rpk/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ go_binary(
2121
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.version": "{STABLE_GIT_LATEST_TAG}",
2222
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.rev": "{STABLE_GIT_COMMIT}",
2323
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/version.buildTime": "{FORMATTED_DATE}",
24-
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common.tag": "{STABLE_GIT_LATEST_TAG}",
24+
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil.tag": "{STABLE_GIT_LATEST_TAG}",
2525
},
2626
)
2727

src/go/rpk/pkg/cli/cloud/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ go_library(
1515
"//src/go/rpk/pkg/cli/cloud/cluster",
1616
"//src/go/rpk/pkg/cli/cloud/mcp",
1717
"//src/go/rpk/pkg/cli/cloud/resourcegroup",
18-
"//src/go/rpk/pkg/cli/container/common",
18+
"//src/go/rpk/pkg/cli/container/containerutil",
1919
"//src/go/rpk/pkg/cli/profile",
2020
"//src/go/rpk/pkg/config",
2121
"//src/go/rpk/pkg/oauth",
2222
"//src/go/rpk/pkg/oauth/providers/auth0",
23-
"//src/go/rpk/pkg/os",
23+
"//src/go/rpk/pkg/osutil",
2424
"//src/go/rpk/pkg/out",
2525
"@com_github_spf13_afero//:afero",
2626
"@com_github_spf13_cobra//:cobra",

src/go/rpk/pkg/cli/cloud/byoc/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ go_library(
1414
"//src/go/rpk/pkg/config",
1515
"//src/go/rpk/pkg/oauth",
1616
"//src/go/rpk/pkg/oauth/providers/auth0",
17-
"//src/go/rpk/pkg/os",
17+
"//src/go/rpk/pkg/osutil",
1818
"//src/go/rpk/pkg/out",
1919
"//src/go/rpk/pkg/plugin",
2020
"//src/go/rpk/pkg/publicapi",

src/go/rpk/pkg/cli/cloud/byoc/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config"
2323
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth"
2424
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth/providers/auth0"
25-
rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/os"
25+
rpkos "github.com/redpanda-data/redpanda/src/go/rpk/pkg/osutil"
2626
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/out"
2727
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/plugin"
2828
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/publicapi"

src/go/rpk/pkg/cli/cloud/login.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ package cloud
1212
import (
1313
"fmt"
1414

15-
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/common"
15+
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/container/containerutil"
1616
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/profile"
1717
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config"
1818
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth"
@@ -137,7 +137,7 @@ rpk will talk to a localhost:9092 cluster until you swap to a different profile.
137137
// unless the user used --no-profile.
138138
if noProfile {
139139
// The current profile is seemingly pointing to a container cluster.
140-
if p.Name == common.ContainerProfileName {
140+
if p.Name == containerutil.ContainerProfileName {
141141
fmt.Printf("You are talking to a localhost 'rpk container' cluster (rpk profile name: %q)\n", p.Name)
142142
fmt.Println("To talk to a cloud cluster, use 'rpk cloud cluster select'.")
143143
return
@@ -158,7 +158,7 @@ rpk will talk to a localhost:9092 cluster until you swap to a different profile.
158158
return
159159
}
160160

161-
if p.Name == common.ContainerProfileName {
161+
if p.Name == containerutil.ContainerProfileName {
162162
fmt.Printf("You are talking to a localhost 'rpk container' cluster (rpk profile name: %q)\n", p.Name)
163163
} else {
164164
fmt.Printf("You are talking to a self hosted cluster (rpk profile name: %q)\n", p.Name)

0 commit comments

Comments
 (0)