Skip to content

Commit 2507064

Browse files
authored
upgrade: golangci-lint to v2 (#22648)
* fix: golangci-lint issues * migrate golangci-lint config to v2 * upgrade: golangci-lint to v2.4.0
1 parent 1e8510e commit 2507064

File tree

44 files changed

+255
-306
lines changed

Some content is hidden

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

44 files changed

+255
-306
lines changed

.github/workflows/reusable-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- name: Set golangci-lint version
5555
run: echo "GOLANGCI_LINT_VERSION=$(make --no-print-directory print-GOLANGCI_LINT_VERSION)" >> $GITHUB_ENV
5656
- name: lint-${{ matrix.directory }}
57-
uses: golangci/golangci-lint-action@82d40c283aeb1f2b6595839195e95c2d6a49081b # v5.0.0
57+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
5858
with:
5959
working-directory: ${{ matrix.directory }}
6060
version: ${{ env.GOLANGCI_LINT_VERSION }}

.golangci.yml

Lines changed: 109 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,118 @@
11
# Copyright (c) HashiCorp, Inc.
22
# SPDX-License-Identifier: BUSL-1.1
33

4+
version: "2"
5+
run:
6+
concurrency: 4
47
linters:
5-
disable-all: true
8+
default: none
69
enable:
7-
- gofmt
10+
- depguard
11+
- forbidigo
12+
- gomodguard
813
- govet
9-
- unconvert
10-
- staticcheck
1114
- ineffassign
15+
- staticcheck
16+
- unconvert
1217
- unparam
13-
- forbidigo
14-
- gomodguard
15-
- depguard
16-
17-
issues:
18-
# Disable the default exclude list so that all excludes are explicitly
19-
# defined in this file.
20-
exclude-use-default: false
21-
22-
exclude-rules:
23-
# Temp Ignore SA9004: only the first constant in this group has an explicit type
24-
# https://staticcheck.io/docs/checks#SA9004
25-
- linters: [staticcheck]
26-
text: "SA9004:"
27-
28-
- linters: [staticcheck]
29-
text: "SA1006:"
30-
31-
- linters: [staticcheck]
32-
text: 'SA1019: "io/ioutil" has been deprecated since Go 1.16'
33-
34-
# Allow usage of deprecated values.
35-
- linters: [ staticcheck ]
36-
text: 'SA1019:'
37-
path: "(agent/grpc-external|agent/grpc-internal)"
38-
39-
# An argument that always receives the same value is often not a problem.
40-
- linters: [unparam]
41-
text: "always receives"
42-
43-
- linters: [ unparam ]
44-
text: 'result \d+ \(bool\) is always false'
45-
46-
# Often functions will implement an interface that returns an error without
47-
# needing to return an error. Sometimes the error return value is unnecessary
48-
# but a linter can not tell the difference.
49-
- linters: [unparam]
50-
text: 'result \d+ \(error\) is always nil'
51-
52-
# Allow unused parameters to start with an underscore. Arguments with a name
53-
# of '_' are already ignored.
54-
# Ignoring longer names that start with underscore allow for better
55-
# self-documentation than a single underscore by itself. Underscore arguments
56-
# should generally only be used when a function is implementing an interface.
57-
- linters: [unparam]
58-
text: "`_[^`]*` is unused"
59-
60-
# Temp ignore some common unused parameters so that unparam can be added
61-
# incrementally.
62-
- linters: [unparam]
63-
text: "`(t|resp|req|entMeta)` is unused"
64-
65-
# Temp ignore everything in _ce(_test).go and _ent(_test).go. Many of these
66-
# could use underscore to ignore the unused arguments, but the "always returns"
67-
# issue will likely remain in CE, and will need to be excluded.
68-
- linters: [unparam]
69-
path: "(_ce.go|_ce_test.go|_ent.go|_ent_test.go)"
70-
71-
- linters: [ staticcheck ]
72-
text: 'SA1019:'
73-
74-
linters-settings:
75-
govet:
76-
enable-all: true
77-
disable:
78-
- fieldalignment
79-
- nilness
80-
- shadow
81-
- unusedwrite
82-
- printf
83-
gofmt:
84-
simplify: true
85-
forbidigo:
86-
# Forbid the following identifiers (list of regexp).
87-
# Format includes custom message based on https://github.com/ashanbrown/forbidigo/pull/11
88-
forbid:
89-
- '\bhtml\/template\b(# Use text/template instead)?'
90-
- '\bioutil\b(# Use io and os packages instead of ioutil)?'
91-
- '\brequire\.New\b(# Use package-level functions with explicit TestingT)?'
92-
- '\bassert\.New\b(# Use package-level functions with explicit TestingT)?'
93-
# Exclude godoc examples from forbidigo checks.
94-
# Default: true
95-
exclude_godoc_examples: false
96-
gomodguard:
97-
blocked:
98-
# List of blocked modules.
99-
modules:
100-
# Blocked module.
101-
- github.com/hashicorp/net-rpc-msgpackrpc:
102-
recommendations:
103-
- github.com/hashicorp/consul-net-rpc/net-rpc-msgpackrpc
104-
- github.com/hashicorp/go-msgpack:
105-
recommendations:
106-
- github.com/hashicorp/consul-net-rpc/go-msgpack
107-
- github.com/golang/protobuf:
108-
recommendations:
109-
- google.golang.org/protobuf
110-
111-
depguard:
18+
settings:
19+
depguard:
20+
rules:
21+
main:
22+
deny:
23+
- pkg: net/rpc
24+
desc: only use forked copy in github.com/hashicorp/consul-net-rpc/net/rpc
25+
- pkg: github.com/golang/protobuf
26+
desc: only use google.golang.org/protobuf
27+
forbidigo:
28+
forbid:
29+
- pattern: \bhtml\/template\b(# Use text/template instead)?
30+
- pattern: \bioutil\b(# Use io and os packages instead of ioutil)?
31+
- pattern: \brequire\.New\b(# Use package-level functions with explicit TestingT)?
32+
- pattern: \bassert\.New\b(# Use package-level functions with explicit TestingT)?
33+
gomodguard:
34+
blocked:
35+
modules:
36+
- github.com/hashicorp/net-rpc-msgpackrpc:
37+
recommendations:
38+
- github.com/hashicorp/consul-net-rpc/net-rpc-msgpackrpc
39+
- github.com/hashicorp/go-msgpack:
40+
recommendations:
41+
- github.com/hashicorp/consul-net-rpc/go-msgpack
42+
- github.com/golang/protobuf:
43+
recommendations:
44+
- google.golang.org/protobuf
45+
govet:
46+
disable:
47+
- fieldalignment
48+
- nilness
49+
- shadow
50+
- unusedwrite
51+
- printf
52+
enable-all: true
53+
exclusions:
54+
generated: lax
11255
rules:
113-
main:
114-
listMode: lax
115-
deny:
116-
- pkg: net/rpc
117-
desc: "only use forked copy in github.com/hashicorp/consul-net-rpc/net/rpc"
118-
- pkg: github.com/golang/protobuf
119-
desc: "only use google.golang.org/protobuf"
120-
121-
run:
122-
timeout: 10m
123-
concurrency: 4
124-
skip-dirs-use-default: false
56+
- linters:
57+
- staticcheck
58+
text: 'SA9004:'
59+
- linters:
60+
- staticcheck
61+
text: 'SA1006:'
62+
- linters:
63+
- staticcheck
64+
text: 'SA1019: "io/ioutil" has been deprecated since Go 1.16'
65+
- linters:
66+
- staticcheck
67+
path: (agent/grpc-external|agent/grpc-internal)
68+
text: 'SA1019:'
69+
- linters:
70+
- unparam
71+
text: always receives
72+
- linters:
73+
- unparam
74+
text: result \d+ \(bool\) is always false
75+
- linters:
76+
- unparam
77+
text: result \d+ \(error\) is always nil
78+
- linters:
79+
- unparam
80+
text: '`_[^`]*` is unused'
81+
- linters:
82+
- unparam
83+
text: '`(t|resp|req|entMeta)` is unused'
84+
- linters:
85+
- unparam
86+
path: (_ce.go|_ce_test.go|_ent.go|_ent_test.go)
87+
- linters:
88+
- staticcheck
89+
text: 'SA1019:'
90+
- linters:
91+
- staticcheck
92+
text: 'ST1005: error strings should not end with punctuation or newlines'
93+
- linters:
94+
- staticcheck
95+
text: 'ST1012: error var injectedError should have name of the form errFo'
96+
- linters:
97+
- staticcheck
98+
text: 'ST1005: error strings should not be capitalized'
99+
- linters:
100+
- staticcheck
101+
text: 'ST1012: error var'
102+
paths:
103+
- third_party$
104+
- builtin$
105+
- examples$
106+
- agent/consul
107+
formatters:
108+
enable:
109+
- gofmt
110+
settings:
111+
gofmt:
112+
simplify: true
113+
exclusions:
114+
generated: lax
115+
paths:
116+
- third_party$
117+
- builtin$
118+
- examples$

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ GO_MODULES := $(shell find . -name go.mod -exec dirname {} \; | grep -v "proto-g
1010
# These version variables can either be a valid string for "go install <module>@<version>"
1111
# or the string @DEV to imply use what is currently installed locally.
1212
###
13-
GOLANGCI_LINT_VERSION='v1.64.8'
13+
GOLANGCI_LINT_VERSION='v2.4.0'
1414
MOCKERY_VERSION='v3.5.2'
1515
BUF_VERSION='v1.26.0'
1616

acl/acl_ce.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,4 @@ type EnterpriseConfig struct {
3232
// no fields in CE
3333
}
3434

35-
func (_ *EnterpriseConfig) Close() {
36-
// do nothing
37-
}
35+
func (*EnterpriseConfig) Close() {}

acl/enterprisemeta_ce.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func NewEnterpriseMetaWithPartition(_, _ string) EnterpriseMeta {
117117
}
118118

119119
// FillAuthzContext stub
120-
func (_ *EnterpriseMeta) FillAuthzContext(_ *AuthorizerContext) {}
120+
func (*EnterpriseMeta) FillAuthzContext(_ *AuthorizerContext) {}
121121

122122
func NormalizeNamespace(_ string) string {
123123
return ""

agent/acl_endpoint.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ var aclDisabled = HTTPError{StatusCode: http.StatusUnauthorized, Reason: "ACL su
2626
// checkACLDisabled will return a standard response if ACLs are disabled. This
2727
// returns true if they are disabled and we should not continue.
2828
func (s *HTTPHandlers) checkACLDisabled() bool {
29-
if s.agent.config.ACLsEnabled {
30-
return false
31-
}
32-
return true
29+
return !(s.agent.config.ACLsEnabled)
3330
}
3431

3532
// ACLBootstrap is used to perform a one-time ACL bootstrap operation on

agent/acl_endpoint_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ import (
3434

3535
func isHTTPBadRequest(err error) bool {
3636
if err, ok := err.(HTTPError); ok {
37-
if err.StatusCode != 400 {
38-
return false
39-
}
40-
return true
37+
return err.StatusCode == http.StatusBadRequest
4138
}
4239
return false
4340
}

agent/agent.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4216,10 +4216,8 @@ func revertStaticConfig(oldCfg tlsutil.ProtocolConfig, newCfg tlsutil.ProtocolCo
42164216
newOldcfg := newCfg
42174217
newOldcfg.CertFile = oldCfg.CertFile
42184218
newOldcfg.KeyFile = oldCfg.KeyFile
4219-
if !reflect.DeepEqual(newOldcfg, oldCfg) {
4220-
return true
4221-
}
4222-
return false
4219+
4220+
return !reflect.DeepEqual(newOldcfg, oldCfg)
42234221
}
42244222

42254223
// reloadConfigInternal is mainly needed for some unit tests. Instead of parsing

agent/checks/check_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,11 +1198,10 @@ func mockUDPServer(ctx context.Context, network string, port int) {
11981198
}
11991199
}()
12001200

1201-
select {
1202-
case <-ctx.Done():
1203-
fmt.Println("cancelled")
1204-
close(chClose)
1205-
}
1201+
<-ctx.Done()
1202+
fmt.Println("cancelled")
1203+
close(chClose)
1204+
12061205
wg.Wait()
12071206
}
12081207

@@ -1366,7 +1365,7 @@ func TestCheckH2PING(t *testing.T) {
13661365
}
13671366

13681367
func TestCheckH2PING_TLS_BadVerify(t *testing.T) {
1369-
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return })
1368+
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
13701369
server := httptest.NewUnstartedServer(handler)
13711370
server.EnableHTTP2 = true
13721371
server.StartTLS()
@@ -1468,7 +1467,7 @@ func TestCheckH2CPING(t *testing.T) {
14681467

14691468
for _, tt := range tests {
14701469
t.Run(tt.desc, func(t *testing.T) {
1471-
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return })
1470+
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
14721471
h2chandler := h2c.NewHandler(handler, &http2.Server{})
14731472
server := httptest.NewUnstartedServer(h2chandler)
14741473
server.Config.ReadTimeout = tt.connTimeout

agent/config/config_ce.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ import (
1313
// EnterpriseMeta stub
1414
type EnterpriseMeta struct{}
1515

16-
func (_ *EnterpriseMeta) ToStructs() acl.EnterpriseMeta {
16+
func (*EnterpriseMeta) ToStructs() acl.EnterpriseMeta {
1717
return *structs.DefaultEnterpriseMetaInDefaultPartition()
1818
}

0 commit comments

Comments
 (0)