Skip to content

Commit ed66469

Browse files
authored
Upgrade golangci-lint to v2 (#8986)
1 parent 4421299 commit ed66469

File tree

75 files changed

+269
-264
lines changed

Some content is hidden

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

75 files changed

+269
-264
lines changed

.github/workflows/docker-publish-exp-image.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ jobs:
5454

5555
- name: Checks validator
5656
run: make checks-validator
57-
env:
58-
GOLANGCI_LINT_FLAGS: --out-format github-actions
5957

6058
- name: Set up QEMU
6159
uses: docker/setup-qemu-action@v3

.github/workflows/docker-publish.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ jobs:
5252

5353
- name: Checks validator
5454
run: make checks-validator
55-
env:
56-
GOLANGCI_LINT_FLAGS: --out-format github-actions
5755

5856
- name: Configure AWS Credentials
5957
uses: aws-actions/configure-aws-credentials@v4

.github/workflows/test.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ jobs:
3030
make gen
3131
make validate-clients-untracked-files
3232
- name: Checks validator
33-
env:
34-
GOLANGCI_LINT_FLAGS: --out-format github-actions
3533
run: make checks-validator
3634

3735
test-go:

.golangci.yml

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,64 @@
1+
version: "2"
12
run:
23
tests: false
3-
timeout: 5m
4-
54
linters:
6-
disable-all: true
5+
default: none
76
enable:
87
- bodyclose
8+
- copyloopvar
99
- dogsled
10+
- err113
1011
- errcheck
1112
- gochecknoinits
1213
- goconst
1314
- gocritic
1415
- gocyclo
15-
- err113
16-
- gofmt
17-
- goimports
18-
- mnd
1916
- goprintffuncname
2017
- gosec
21-
- gosimple
2218
- govet
2319
- ineffassign
2420
- misspell
21+
- mnd
2522
- nakedret
26-
- copyloopvar
2723
- staticcheck
28-
- stylecheck
29-
- typecheck
3024
- unconvert
3125
- unparam
3226
- unused
3327
- whitespace
34-
35-
linters-settings:
36-
mnd:
37-
ignored-files:
38-
- 'pkg/actions/lua/.*'
39-
40-
issues:
41-
exclude-dirs:
42-
- pkg/metastore/hive/gen-go
28+
settings:
29+
mnd:
30+
ignored-files:
31+
- pkg/actions/lua/.*
32+
staticcheck:
33+
checks:
34+
- all
35+
- -ST1000
36+
- -ST1003
37+
- -ST1016
38+
- -ST1020
39+
- -ST1021
40+
- -ST1022
41+
- -QF1001 # Apply De Morgan’s law
42+
exclusions:
43+
generated: lax
44+
presets:
45+
- comments
46+
- common-false-positives
47+
- legacy
48+
- std-error-handling
49+
paths:
50+
- pkg/metastore/hive/gen-go
51+
- third_party$
52+
- builtin$
53+
- examples$
54+
formatters:
55+
enable:
56+
- gofmt
57+
- goimports
58+
exclusions:
59+
generated: lax
60+
paths:
61+
- pkg/metastore/hive/gen-go
62+
- third_party$
63+
- builtin$
64+
- examples$

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ OPENAPI_RUST_GENERATOR_IMAGE=openapitools/openapi-generator-cli:v7.5.0
1414
OPENAPI_RUST_GENERATOR=$(DOCKER) run --user $(UID_GID) --rm -v $(shell pwd):/mnt $(OPENAPI_RUST_GENERATOR_IMAGE)
1515
PY_OPENAPI_GENERATOR=$(DOCKER) run -e PYTHON_POST_PROCESS_FILE="/mnt/clients/python-static/pydantic.sh" --user $(UID_GID) --rm -v $(shell pwd):/mnt $(OPENAPI_GENERATOR_IMAGE)
1616

17-
GOLANGCI_LINT_VERSION=v1.63.4
17+
GOLANGCI_LINT=github.com/golangci/golangci-lint/v2/cmd/[email protected]
1818
BUF_CLI_VERSION=v1.28.1
1919

2020
ifndef PACKAGE_VERSION
@@ -105,7 +105,7 @@ gen-metastore: ## Run Metastore Code generation
105105
@thrift -r --gen go --gen go:package_prefix=github.com/treeverse/lakefs/pkg/metastore/hive/gen-go/ -o pkg/metastore/hive pkg/metastore/hive/hive_metastore.thrift
106106

107107
tools: ## Install tools
108-
$(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
108+
$(GOCMD) install $(GOLANGCI_LINT)
109109
$(GOCMD) install github.com/bufbuild/buf/cmd/buf@$(BUF_CLI_VERSION)
110110

111111
client-python: api/swagger.yml ## Generate SDK for Python client - openapi generator version 7.0.0
@@ -185,7 +185,7 @@ build: gen docs ## Download dependencies and build the default binary
185185
$(GOBUILD) -o $(LAKECTL_BINARY_NAME) -ldflags $(LD_FLAGS) -v ./cmd/$(LAKECTL_BINARY_NAME)
186186

187187
lint: ## Lint code
188-
$(GOCMD) run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run $(GOLANGCI_LINT_FLAGS)
188+
$(GOCMD) run $(GOLANGCI_LINT) run $(GOLANGCI_LINT_FLAGS)
189189
npx [email protected] $(UI_DIR)/src --ext .js,.jsx,.ts,.tsx
190190

191191
esti: ## run esti (system testing)

cmd/lakectl/cmd/annotate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func stringTrimLen(str string, size int) string {
9999
}
100100

101101
func splitOnNewLine(str string) string {
102-
return strings.SplitN(str, "\\n", 2)[0] //nolint: mnd
102+
return strings.SplitN(str, "\\n", 2)[0] //nolint:mnd
103103
}
104104

105105
//nolint:gochecknoinits

cmd/lakectl/cmd/docs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ func genMarkdownForCmd(cmd *cobra.Command, w io.Writer, topLevel bool) error {
146146
}
147147

148148
if cmd.Runnable() {
149-
buf.WriteString(fmt.Sprintf("```\n%s\n```\n\n", cmd.UseLine()))
149+
_, _ = fmt.Fprintf(buf, "```\n%s\n```\n\n", cmd.UseLine())
150150
}
151151

152152
if len(cmd.Example) > 0 {
153153
buf.WriteString("#### Examples\n{:.no_toc}\n\n")
154-
buf.WriteString(fmt.Sprintf("```\n%s\n```\n\n", cmd.Example))
154+
_, _ = fmt.Fprintf(buf, "```\n%s\n```\n\n", cmd.Example)
155155
}
156156

157157
if err := printOptions(buf, cmd); err != nil {

cmd/lakectl/cmd/doctor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func ListRepositoriesAndAnalyze(ctx context.Context) error {
122122
configFileName := viper.GetViper().ConfigFileUsed()
123123
msgOnErrUnknownConfig := "It looks like you have a problem with your `" + configFileName + "` file."
124124
msgOnErrWrongEndpointURI := "It looks like endpoint url is wrong."
125-
msgOnErrCredential := "It seems like the `access_key_id` or `secret_access_key` you supplied are wrong." //nolint: gosec
125+
msgOnErrCredential := "It seems like the `access_key_id` or `secret_access_key` you supplied are wrong." //nolint:gosec
126126

127127
WriteIfVerbose(analyzingMessageTemplate, &UserMessage{Message: "Trying to get endpoint URL and parse it as a URL format."})
128128
// getClient might die on url.Parse error, so check it first.

cmd/lakectl/cmd/import.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ var importCmd = &cobra.Command{
104104
if status.Error != nil {
105105
DieFmt("Import failed: %s", status.Error.Message)
106106
}
107-
_ = bar.Set64(*status.IngestedObjects)
108-
if updatedAt == status.UpdateTime {
107+
if status.IngestedObjects != nil {
108+
_ = bar.Set64(*status.IngestedObjects)
109+
}
110+
if updatedAt.Equal(status.UpdateTime) {
109111
updateFailures += 1
110112
}
111113
if updateFailures >= maxUpdateFailures {
@@ -194,7 +196,7 @@ func branchExists(ctx context.Context, client *apigen.ClientWithResponses, repos
194196
return RetrieveError(resp, err), false
195197
}
196198

197-
//nolint:gochecknoinits,mnd
199+
//nolint:gochecknoinits
198200
func init() {
199201
importCmd.Flags().String("from", "", "prefix to read from (e.g. \"s3://bucket/sub/path/\"). must not be in a storage namespace")
200202
_ = importCmd.MarkFlagRequired("from")

cmd/lakectl/cmd/local_commit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func TestUncommittedOutsideOfPrefix(t *testing.T) {
167167
expectedResult: true,
168168
},
169169
{
170-
name: "Uncommitted changes - on the boundry",
170+
name: "Uncommitted changes - on the boundary",
171171
h: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
172172
var res *apigen.DiffList
173173
w.Header().Set("Content-Type", "application/json")

cmd/lakectl/cmd/retry_client_test.go

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,24 @@ func TestLakectlRetryPolicy(t *testing.T) {
5353
expectedError: context.Canceled.Error(),
5454
},
5555
{
56-
name: "Transport Error - Too Many Redirects",
57-
getTestContext: func() context.Context {
58-
return context.Background()
59-
},
56+
name: "Transport Error - Too Many Redirects",
57+
getTestContext: context.Background,
6058
resp: nil,
6159
err: &url.Error{Op: http.MethodGet, URL: testURL, Err: errors.New(tooManyRedirectsErrorMessage)},
6260
expectedShouldRetry: false,
6361
expectedError: tooManyRedirectsErrorMessage,
6462
},
6563
{
66-
name: "Transport Error - Random Transport Error",
67-
getTestContext: func() context.Context {
68-
return context.Background()
69-
},
64+
name: "Transport Error - Random Transport Error",
65+
getTestContext: context.Background,
7066
resp: nil,
7167
err: &url.Error{Op: http.MethodGet, URL: testURL, Err: errors.New(someRandomErrorMessage)},
7268
expectedShouldRetry: true,
7369
expectedError: "",
7470
},
7571
{
76-
name: "HTTP Status - 429 Too Many Requests",
77-
getTestContext: func() context.Context {
78-
return context.Background()
79-
},
72+
name: "HTTP Status - 429 Too Many Requests",
73+
getTestContext: context.Background,
8074
resp: &http.Response{
8175
StatusCode: http.StatusTooManyRequests,
8276
},
@@ -85,10 +79,8 @@ func TestLakectlRetryPolicy(t *testing.T) {
8579
expectedError: "",
8680
},
8781
{
88-
name: "HTTP Status - 500 Internal Server Error",
89-
getTestContext: func() context.Context {
90-
return context.Background()
91-
},
82+
name: "HTTP Status - 500 Internal Server Error",
83+
getTestContext: context.Background,
9284
resp: &http.Response{
9385
StatusCode: http.StatusInternalServerError,
9486
},
@@ -97,10 +89,8 @@ func TestLakectlRetryPolicy(t *testing.T) {
9789
expectedError: "",
9890
},
9991
{
100-
name: "HTTP Status - 503 Service Unavailable",
101-
getTestContext: func() context.Context {
102-
return context.Background()
103-
},
92+
name: "HTTP Status - 503 Service Unavailable",
93+
getTestContext: context.Background,
10494
resp: &http.Response{
10595
StatusCode: http.StatusServiceUnavailable,
10696
},
@@ -109,10 +99,8 @@ func TestLakectlRetryPolicy(t *testing.T) {
10999
expectedError: "",
110100
},
111101
{
112-
name: "HTTP Status - 401 Unauthorized",
113-
getTestContext: func() context.Context {
114-
return context.Background()
115-
},
102+
name: "HTTP Status - 401 Unauthorized",
103+
getTestContext: context.Background,
116104
resp: &http.Response{
117105
StatusCode: http.StatusUnauthorized,
118106
},
@@ -121,10 +109,8 @@ func TestLakectlRetryPolicy(t *testing.T) {
121109
expectedError: "",
122110
},
123111
{
124-
name: "HTTP Status - 404 Not Found",
125-
getTestContext: func() context.Context {
126-
return context.Background()
127-
},
112+
name: "HTTP Status - 404 Not Found",
113+
getTestContext: context.Background,
128114
resp: &http.Response{
129115
StatusCode: http.StatusNotFound,
130116
},
@@ -133,10 +119,8 @@ func TestLakectlRetryPolicy(t *testing.T) {
133119
expectedError: "",
134120
},
135121
{
136-
name: "HTTP Status - 200 Ok",
137-
getTestContext: func() context.Context {
138-
return context.Background()
139-
},
122+
name: "HTTP Status - 200 Ok",
123+
getTestContext: context.Background,
140124
resp: &http.Response{
141125
StatusCode: http.StatusOK,
142126
},
@@ -145,10 +129,8 @@ func TestLakectlRetryPolicy(t *testing.T) {
145129
expectedError: "",
146130
},
147131
{
148-
name: "HTTP Status - 201 Created",
149-
getTestContext: func() context.Context {
150-
return context.Background()
151-
},
132+
name: "HTTP Status - 201 Created",
133+
getTestContext: context.Background,
152134
resp: &http.Response{
153135
StatusCode: http.StatusCreated,
154136
},

cmd/lakectl/cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func getCommitFlags(cmd *cobra.Command) (string, map[string]string) {
403403
return message, kvPairs
404404
}
405405

406-
func getKV(cmd *cobra.Command, name string) (map[string]string, error) { //nolint:unparam
406+
func getKV(cmd *cobra.Command, name string) (map[string]string, error) {
407407
kvList, err := cmd.Flags().GetStringSlice(name)
408408
if err != nil {
409409
return nil, err

cmd/lakefs/cmd/common_helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import (
88
)
99

1010
func printMsgAndExit(params ...any) {
11-
fmt.Fprintln(os.Stderr, "Error:", fmt.Sprint(params...))
11+
_, _ = fmt.Fprintln(os.Stderr, "Error:", fmt.Sprint(params...))
1212
os.Exit(1)
1313
}
1414

1515
func printInfo(params ...any) {
1616
colorMsg := text.FgHiBlue.Sprintf("Info: %s", fmt.Sprint(params...))
17-
fmt.Fprintln(os.Stderr, colorMsg)
17+
_, _ = fmt.Fprintln(os.Stderr, colorMsg)
1818
}
1919

2020
func printNonFatalError(params ...any) {
2121
colorMsg := text.FgHiRed.Sprintf("Error: %s", fmt.Sprint(params...))
22-
fmt.Fprintln(os.Stderr, colorMsg)
22+
_, _ = fmt.Fprintln(os.Stderr, colorMsg)
2323
}

cmd/lakefs/cmd/kv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ var kvScanCmd = &cobra.Command{
156156
},
157157
}
158158

159-
//nolint:gochecknoinits,mnd
159+
//nolint:gochecknoinits
160160
func init() {
161161
rootCmd.AddCommand(kvCmd)
162162
kvCmd.AddCommand(kvGetCmd)

contrib/auth/acl/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// nolint:stylecheck
1+
//nolint:stylecheck
22
package acl
33

44
import (

contrib/auth/acl/service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func TestAuthService_ListPaged(t *testing.T) {
227227
}
228228
letters := model.ConvertUsersDataList(values)
229229
for _, c := range letters {
230-
got = got + c.Username
230+
got += c.Username
231231
}
232232
if paginator.NextPageToken == "" {
233233
if size > 0 && len(letters) > size {

esti/auth_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestSuperPermissions(t *testing.T) {
9090
require.Equal(t, http.StatusOK, resCommit.StatusCode(), "Super unexpectedly failed to read branch commit")
9191

9292
// creating a branch should succeed
93-
branch1 := "feature-1"
93+
const branch1 = "feature-1"
9494
resAddBranch, err := superClient.CreateBranchWithResponse(ctx, repo, apigen.CreateBranchJSONRequestBody{
9595
Name: branch1,
9696
Source: mainBranch,
@@ -146,7 +146,7 @@ func TestWriterPermissions(t *testing.T) {
146146
require.Equal(t, http.StatusOK, resCommit.StatusCode(), "Writer unexpectedly failed to read branch commit")
147147

148148
// creating a branch should succeed
149-
branch1 := "feature-1"
149+
const branch1 = "feature-1"
150150
resAddBranch, err := writerClient.CreateBranchWithResponse(ctx, repo, apigen.CreateBranchJSONRequestBody{
151151
Name: branch1,
152152
Source: mainBranch,
@@ -315,7 +315,7 @@ func TestCreatePolicy(t *testing.T) {
315315
})
316316
require.NoError(t, err)
317317
// TODO (niro): https://github.com/treeverse/fluffy/issues/320
318-
//require.NotNil(t, resp.JSON400, "wrong response: %s", resp.Status())
318+
// require.NotNil(t, resp.JSON400, "wrong response: %s", resp.Status())
319319
require.Nil(t, resp.JSON201)
320320
})
321321
}

0 commit comments

Comments
 (0)