Skip to content

Commit 94e75ae

Browse files
author
Thomas Delbende
committed
chore: upgrade golangci-lint to v2, please linters
1 parent 7583c60 commit 94e75ae

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

+265
-233
lines changed

.golangci.yml

+67-52
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,86 @@
1+
version: "2"
12
run:
23
go: "1.24"
34
timeout: 5m
45

56
linters:
6-
enable-all: true
7+
default: all
78
disable:
8-
# Base linters disabled for all projects.
9-
- funlen
10-
- mnd # Same as above
9+
- contextcheck # Requires to change a lot of code to pass a context everywhere.
10+
- cyclop # We use maintidx to lint function complexity.
11+
- errorlint # Should be enabled, but it's difficult to test that we keep the same behavior with errors.As.
1112
- exhaustruct # This linter is meant to be used only for special cases. It is not recommended to use it for all files in a project.
12-
- gci # Conflicts with gofumpt.
13-
- ireturn # Complain that interface A implementation method return an interface B... it's a requirement of interface A that is unavoidable.
14-
- nonamedreturns # Warn for every named return, not useful.
13+
- funlen
14+
- gocognit # We use maintidx to lint function complexity.
15+
- gocyclo # We use maintidx to lint function complexity.
16+
- godox # Too many TODO in code, but should be removed and TODO fixed :)
17+
- gomoddirectives # We sometimes need to use mod replacements to fix upgrades.
1518
- interfacebloat # Warn when an interface has too many methods, not useful.
16-
# Deprecated and replaced linter.
17-
- tenv
18-
# We use maintidx to lint function complexity.
19-
- gocyclo
20-
- cyclop
21-
- gocognit
22-
23-
# Project specific disable.
19+
- ireturn # Complain that interface A implementation method return an interface B... it's a requirement of interface A that is unavoidable.
2420
- lll
25-
- varnamelen # I think there is too many false-positive.
26-
- godox # too many TODO in code, but should be removed and TODO fixed :)
21+
- mnd # Too picky.
22+
- musttag # json tags must be added public fields used in JSON. Disabled because it also reports errors on dependencies.
2723
- nestif # Too many error for now, which would require significant refactor.
24+
- nonamedreturns # Warn for every named return, not useful.
25+
- paralleltest # Requires reviewing all our tests. Should be done.
2826
- tagliatelle # Check struct tags. Too many errors we can't fix.
27+
- testpackage # Requires reviewing all our tests. Should be done.
28+
- tparallel # Requires reviewing all our tests. Should be done.
29+
- varnamelen # I think there is too many false-positive.
2930
- wrapcheck # Too many errors, which would require to refactor most returned errors.
30-
- errorlint # Should be enabled, but it's difficult to test that we keep the same behavior with errors.As.
31-
- contextcheck # Requires to change a lot of code to pass a context everywhere.
32-
- gomoddirectives # We sometimes need to use mod replacements to fix upgrades.
33-
- musttag # json tags must be added public fields used in JSON. Disabled because it also report errors on dependencies.
34-
# Requires to review all our tests. Should be done.
35-
- paralleltest
36-
- tparallel
37-
- testpackage
3831

39-
linters-settings:
40-
nolintlint:
41-
# Require nolint directives to mention the specific linter being suppressed.
42-
require-specific: true
43-
44-
tagliatelle:
45-
# Check struct tag name case.
46-
case:
47-
# Use the struct field name to check the name of the struct tag.
32+
settings:
33+
depguard:
34+
rules:
35+
main:
36+
deny:
37+
- pkg: io/ioutil
38+
desc: ioutil is deprecated starting with Go 1.16
39+
nolintlint:
40+
# Require nolint directives to mention the specific linter being suppressed.
41+
require-specific: true
42+
revive:
4843
rules:
49-
json: snake
50-
yaml: snake
44+
- name: exported
45+
disabled: true
46+
staticcheck:
47+
checks:
48+
- "all"
49+
- "-QF1008" # Omit embedded fields from selector expression
50+
- "-ST1000" # Incorrect or missing package comment
51+
tagliatelle:
52+
# Check struct tag name case.
53+
case:
54+
# Use the struct field name to check the name of the struct tag.
55+
rules:
56+
json: snake
57+
yaml: snake
5158

52-
depguard:
53-
rules:
54-
main:
55-
deny:
56-
- pkg: "io/ioutil"
57-
desc: "ioutil is deprecated starting with Go 1.16"
59+
exclusions:
60+
generated: lax
61+
presets:
62+
- common-false-positives
63+
- std-error-handling
64+
paths:
65+
- work
66+
- third_party$
67+
- builtin$
68+
- examples$
5869

5970
issues:
60-
include: # the list of ids of default excludes to include
61-
- EXC0005 # ineffective break statement
62-
- EXC0009 # create files/directories with minimum permissions
63-
# - EXC0011 # TODO: should have a package comment|comment should be of the form
64-
# - EXC0012 # TODO: exported var/functions should have a comment
65-
- EXC0013 # package comment should be of the form
66-
- EXC0014 # comment on exported var should be of the form
67-
6871
max-issues-per-linter: 0
6972
max-same-issues: 0
70-
exclude-dirs:
71-
- work
73+
74+
formatters:
75+
enable:
76+
- gofmt
77+
- gofumpt
78+
- goimports
79+
80+
exclusions:
81+
generated: lax
82+
paths:
83+
- work
84+
- third_party$
85+
- builtin$
86+
- examples$

agent/agent.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const (
119119

120120
var (
121121
// We want to reply with capitalized U to match output from a Zabbix agent.
122-
errUnsupportedKey = errors.New("Unsupported item key") //nolint:stylecheck
122+
errUnsupportedKey = errors.New("Unsupported item key") //nolint:staticcheck
123123
errFeatureUnavailable = errors.New("some features are unavailable")
124124
)
125125

@@ -2745,39 +2745,39 @@ func setupContainer(hostRootPath string) {
27452745
if os.Getenv("HOST_VAR") == "" {
27462746
// gopsutil will use HOST_VAR as prefix to host /var
27472747
// It's used at least for reading the number of connected user from /var/run/utmp
2748-
os.Setenv("HOST_VAR", filepath.Join(hostRootPath, "var"))
2748+
_ = os.Setenv("HOST_VAR", filepath.Join(hostRootPath, "var"))
27492749

27502750
// ... but /var/run is usually a symlink to /run.
27512751
varRun := filepath.Join(hostRootPath, "var/run")
27522752
target, err := os.Readlink(varRun)
27532753

27542754
if err == nil && target == "/run" {
2755-
os.Setenv("HOST_VAR", hostRootPath)
2755+
_ = os.Setenv("HOST_VAR", hostRootPath)
27562756
}
27572757
}
27582758

27592759
if os.Getenv("HOST_ETC") == "" {
2760-
os.Setenv("HOST_ETC", filepath.Join(hostRootPath, "etc"))
2760+
_ = os.Setenv("HOST_ETC", filepath.Join(hostRootPath, "etc"))
27612761
}
27622762

27632763
if os.Getenv("HOST_PROC") == "" {
2764-
os.Setenv("HOST_PROC", filepath.Join(hostRootPath, "proc"))
2764+
_ = os.Setenv("HOST_PROC", filepath.Join(hostRootPath, "proc"))
27652765
}
27662766

27672767
if os.Getenv("HOST_SYS") == "" {
2768-
os.Setenv("HOST_SYS", filepath.Join(hostRootPath, "sys"))
2768+
_ = os.Setenv("HOST_SYS", filepath.Join(hostRootPath, "sys"))
27692769
}
27702770

27712771
if os.Getenv("HOST_RUN") == "" {
2772-
os.Setenv("HOST_RUN", filepath.Join(hostRootPath, "run"))
2772+
_ = os.Setenv("HOST_RUN", filepath.Join(hostRootPath, "run"))
27732773
}
27742774

27752775
if os.Getenv("HOST_DEV") == "" {
2776-
os.Setenv("HOST_DEV", filepath.Join(hostRootPath, "dev"))
2776+
_ = os.Setenv("HOST_DEV", filepath.Join(hostRootPath, "dev"))
27772777
}
27782778

27792779
if os.Getenv("HOST_MOUNT_PREFIX") == "" {
2780-
os.Setenv("HOST_MOUNT_PREFIX", hostRootPath)
2780+
_ = os.Setenv("HOST_MOUNT_PREFIX", hostRootPath)
27812781
}
27822782
}
27832783
}

agent/agent_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
//nolint:scopelint
1817
package agent
1918

2019
import (

agent/service_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
//nolint:scopelint
1817
package agent
1918

2019
import "testing"

agent/state/state.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func load(readOnly bool, persistentPath string, cachePath string) (*State, error
119119
decoder := json.NewDecoder(f)
120120
err = decoder.Decode(&state.persistent)
121121

122-
f.Close()
122+
_ = f.Close()
123123

124124
if err != nil {
125125
return nil, err
@@ -146,7 +146,7 @@ func load(readOnly bool, persistentPath string, cachePath string) (*State, error
146146
logger.V(1).Printf("unable to load state cache: %v", err)
147147
}
148148

149-
f.Close()
149+
_ = f.Close()
150150
} else {
151151
logger.V(1).Printf("unable to load state cache: %v", err)
152152
}
@@ -274,13 +274,13 @@ func (s *State) savePersistent() error {
274274

275275
err = s.savePersistentTo(w)
276276
if err != nil {
277-
w.Close()
277+
_ = w.Close()
278278

279279
return err
280280
}
281281

282282
_ = w.Sync()
283-
w.Close()
283+
_ = w.Close()
284284

285285
err = os.Rename(s.persistentPath+tmpExt, s.persistentPath)
286286
if err != nil {
@@ -378,12 +378,12 @@ func (s *State) writeCache(onlyIfFileExists bool) error {
378378

379379
_, err = w.Write(data)
380380
if err != nil {
381-
w.Close()
381+
_ = w.Close()
382382

383383
return err
384384
}
385385

386-
w.Close()
386+
_ = w.Close()
387387

388388
err = os.Rename(tmpCachePath, cachePath)
389389

agent/state/state_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ func TestSkipCacheWriteIfRemoved(t *testing.T) {
607607
}
608608

609609
// user now remove the state.cache.json
610-
os.Remove(cachePath)
610+
_ = os.Remove(cachePath)
611611

612612
_ = state.SetBleemeoCredentials(agentID, password2)
613613
_ = state.Set("key2", cacheKeyString2)

api/api.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (api *API) init() {
121121
indexFile, err := staticFolder.Open(indexFileName)
122122
if err == nil {
123123
indexBody, err = io.ReadAll(indexFile)
124-
indexFile.Close()
124+
_ = indexFile.Close()
125125
}
126126

127127
if err != nil {
@@ -142,7 +142,7 @@ func (api *API) init() {
142142
diagnosticFile, err := staticFolder.Open("static/diagnostic.html")
143143
if err == nil {
144144
diagnosticBody, err = io.ReadAll(diagnosticFile)
145-
diagnosticFile.Close()
145+
_ = diagnosticFile.Close()
146146
}
147147

148148
if err != nil {

bleemeo/internal/cache/cache.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func (c *Cache) AccountConfigsByUUID() map[string]bleemeoTypes.GloutonAccountCon
277277
_, isHost := config.AgentConfigByName[bleemeo.AgentType_vSphereHost]
278278
_, isCluster := config.AgentConfigByName[bleemeo.AgentType_vSphereCluster]
279279

280-
if !(isVM || isHost || isCluster) {
280+
if !isVM && !isHost && !isCluster {
281281
config.VSphereIntegration = false
282282
}
283283

bleemeo/internal/common/diagnostic.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,17 @@ func diagnosticTLS(builder io.Writer, tlsConfig *tls.Config, host string, hostPo
105105
rawConn.LocalAddr().String(),
106106
err,
107107
)
108-
rawConn.Close()
108+
109+
_ = rawConn.Close()
109110
} else {
110111
fmt.Fprintf(
111112
builder,
112113
"Glouton is able to establish TLS connection to %s (%s)\n",
113114
hostPort,
114115
rawConn.RemoteAddr().String(),
115116
)
116-
tlsConn.Close()
117+
118+
_ = tlsConn.Close()
117119
}
118120
}
119121

bleemeo/internal/mqtt/state.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ func (rs *reloadState) SetPendingPoints(points []gloutonTypes.MetricPoint) {
130130
func (rs *reloadState) Close() {
131131
// Consume all events on channels to make sure the paho client is not blocked.
132132
go func() {
133-
for range rs.notificationChannel { //nolint:revive
133+
for range rs.notificationChannel {
134134
}
135135
}()
136136
go func() {
137-
for range rs.connectChannel { //nolint:revive
137+
for range rs.connectChannel {
138138
}
139139
}()
140140

0 commit comments

Comments
 (0)