Skip to content

Commit bd2f263

Browse files
committed
fix: Migrate golangci-lint to v2
Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
1 parent 96a867f commit bd2f263

File tree

4 files changed

+67
-120
lines changed

4 files changed

+67
-120
lines changed

.golangci.yaml

Lines changed: 54 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,90 @@
1-
enable:
2-
3-
run:
4-
deadline: 10m
5-
1+
version: "2"
62
linters:
7-
disable-all: true
3+
default: none
84
enable:
95
- asciicheck
106
- bodyclose
11-
# TODO(mem): - containedctx
12-
# TODO(mem):- contextcheck
13-
# TODO(mem): - cyclop
147
- decorder
15-
# - depguard
168
- dogsled
17-
# TODO(mem): - dupl
189
- dupword
1910
- durationcheck
20-
- errchkjson
2111
- errcheck
12+
- errchkjson
2213
- errname
23-
# TODO(mem): - errorlint
24-
# TODO(mem): - exhaustive
2514
- gocheckcompilerdirectives
26-
# - TODO(mem): gochecknoglobals
2715
- gochecknoinits
2816
- goconst
2917
- gocritic
30-
# - gocognit
3118
- gocyclo
32-
- gofmt
33-
- gofumpt
34-
- goimports
35-
# - golint
36-
# TODO(mem): - gomnd
3719
- goprintffuncname
38-
# - gosec
3920
- gosmopolitan
40-
- grouper
41-
- gosimple
4221
- govet
43-
# TODO(mem): fails because we are runnig in a container?: - importas
22+
- grouper
4423
- ineffassign
4524
- interfacebloat
46-
# TODO(mem): - ireturn
47-
# - lll
4825
- loggercheck
49-
# TODO(mem): - maintidx
5026
- mirror
5127
- misspell
52-
# TODO(mem): fails because it's trying to run `go list all`?: - musttag
5328
- nakedret
5429
- nestif
55-
# TODO(mem): - noctx
5630
- nolintlint
5731
- nosprintfhostport
58-
# TODO(mem): - paralleltest
59-
# TODO(mem): - prealloc
60-
# TODO(mem): - promlinter
6132
- reassign
62-
# TODO(mem): - revive
6333
- rowserrcheck
6434
- sqlclosecheck
6535
- staticcheck
66-
# TODO(mem): - tagalign
67-
- tenv
6836
- testableexamples
69-
# TODO(mem): - thelper
70-
- typecheck
7137
- unconvert
72-
# TODO(mem): - unparam
73-
# TODO(mem): - varnamelen
74-
- wastedassign
7538
- unused
39+
- wastedassign
7640
- whitespace
77-
# TODO(mem): - wsl
7841
- zerologlint
79-
80-
linters-settings:
81-
goconst:
82-
ignore-tests: false
83-
min-len: 5
84-
min-occurrences: 5
85-
gocyclo:
86-
min-complexity: 18
87-
golint:
88-
ignore-tests: false
89-
min-confidence: 3
90-
rowserrcheck:
91-
packages:
92-
- github.com/jmoiron/sqlx
93-
gocritic:
94-
enabled-checks:
95-
- appendAssign
96-
- argOrder
97-
- assignOp
98-
- badCall
99-
- badCond
100-
- captLocal
101-
- caseOrder
102-
- codegenComment
103-
- commentFormatting
104-
- defaultCaseOrder
105-
- deprecatedComment
106-
- dupArg
107-
- dupBranchBody
108-
- dupCase
109-
- dupSubExpr
110-
- elseif
111-
- exitAfterDefer
112-
- flagDeref
113-
- flagName
114-
- ifElseChain
115-
- mapKey
116-
- newDeref
117-
- offBy1
118-
- regexpMust
119-
# - ruleguard
120-
- singleCaseSwitch
121-
- sloppyLen
122-
- stringXbytes
123-
- switchTrue
124-
- typeSwitchVar
125-
- underef
126-
- unlambda
127-
- unslice
128-
- valSwap
129-
- wrapperFunc
130-
settings:
131-
ruleguard:
132-
rules: "internal/rules/rules.go"
133-
importas:
134-
no-unaliased: true
135-
no-extra-aliases: true
136-
alias:
137-
- pkg: github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring
138-
alias: sm
139-
- pkg: github.com/prometheus/client_model/go
140-
alias: dto
141-
142-
issues:
143-
exclude:
144-
- "(func|method|type|var|struct field|func parameter|method parameter) [^ ]+ should be .*"
145-
# new: true
146-
# new-from-rev: v0.0.3
42+
settings:
43+
goconst:
44+
min-len: 5
45+
min-occurrences: 5
46+
gocritic:
47+
enabled-checks:
48+
- stringXbytes
49+
- ruleguard
50+
settings:
51+
ruleguard:
52+
rules: internal/rules/rules.go
53+
gocyclo:
54+
min-complexity: 18
55+
importas:
56+
alias:
57+
- pkg: github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring
58+
alias: sm
59+
- pkg: github.com/prometheus/client_model/go
60+
alias: dto
61+
no-unaliased: true
62+
no-extra-aliases: true
63+
rowserrcheck:
64+
packages:
65+
- github.com/jmoiron/sqlx
66+
exclusions:
67+
generated: lax
68+
presets:
69+
- comments
70+
- common-false-positives
71+
- legacy
72+
- std-error-handling
73+
rules:
74+
- path: (.+)\.go$
75+
text: (func|method|type|var|struct field|func parameter|method parameter) [^ ]+ should be .*
76+
paths:
77+
- third_party$
78+
- builtin$
79+
- examples$
80+
formatters:
81+
enable:
82+
- gofmt
83+
- gofumpt
84+
- goimports
85+
exclusions:
86+
generated: lax
87+
paths:
88+
- third_party$
89+
- builtin$
90+
- examples$

cli/probe.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring"
1211
sm "github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring"
1312
"github.com/urfave/cli/v2"
1413
)
@@ -231,12 +230,12 @@ func (c ProbesClient) updateProbe(ctx *cli.Context) error {
231230
}
232231
defer func() { _ = cleanup(ctx.Context) }()
233232

234-
var probeUpdateFunc func(ctx context.Context, probe synthetic_monitoring.Probe) (*synthetic_monitoring.Probe, []byte, error)
233+
var probeUpdateFunc func(ctx context.Context, probe sm.Probe) (*sm.Probe, []byte, error)
235234

236235
if ctx.Bool("reset-token") {
237236
probeUpdateFunc = smClient.ResetProbeToken
238237
} else {
239-
probeUpdateFunc = func(ctx context.Context, probe synthetic_monitoring.Probe) (*synthetic_monitoring.Probe, []byte, error) {
238+
probeUpdateFunc = func(ctx context.Context, probe sm.Probe) (*sm.Probe, []byte, error) {
240239
newProbe, err := smClient.UpdateProbe(ctx, probe)
241240

242241
return newProbe, nil, err //nolint:wrapcheck // this function is an adapter

examples/list-checks/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ func main() {
4444
}
4545

4646
// Delete the access token when we are done.
47-
defer c.DeleteToken(ctx)
47+
defer func() {
48+
_ = c.DeleteToken(ctx)
49+
}()
4850

4951
err = listChecks(ctx, c, os.Stdout)
5052
if err != nil {

examples/remove-probe/main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"os"
1010
"strings"
1111

12-
"github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring"
12+
sm "github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring"
1313
smapi "github.com/grafana/synthetic-monitoring-api-go-client"
1414
)
1515

@@ -43,7 +43,9 @@ func main() {
4343
}
4444

4545
// delete the token we created by calling c.Install above.
46-
defer c.DeleteToken(ctx)
46+
defer func() {
47+
_ = c.DeleteToken(ctx)
48+
}()
4749

4850
probe, err := findProbe(ctx, cfg.ProbeName, installResp.TenantInfo.ID, c)
4951
if err != nil {
@@ -104,10 +106,10 @@ func processFlags(args []string) (config, error) {
104106
return cfg, nil
105107
}
106108

107-
func findProbe(ctx context.Context, name string, tenantID int64, client *smapi.Client) (synthetic_monitoring.Probe, error) {
109+
func findProbe(ctx context.Context, name string, tenantID int64, client *smapi.Client) (sm.Probe, error) {
108110
existingProbes, err := client.ListProbes(ctx)
109111
if err != nil {
110-
return synthetic_monitoring.Probe{}, fmt.Errorf("listing probes: %w", err)
112+
return sm.Probe{}, fmt.Errorf("listing probes: %w", err)
111113
}
112114

113115
for _, p := range existingProbes {
@@ -116,10 +118,10 @@ func findProbe(ctx context.Context, name string, tenantID int64, client *smapi.C
116118
}
117119
}
118120

119-
return synthetic_monitoring.Probe{}, fmt.Errorf(`Probe "%s" not found.`, name)
121+
return sm.Probe{}, fmt.Errorf(`probe "%s" not found`, name)
120122
}
121123

122-
func removeProbeFromChecks(ctx context.Context, probe synthetic_monitoring.Probe, client *smapi.Client) error {
124+
func removeProbeFromChecks(ctx context.Context, probe sm.Probe, client *smapi.Client) error {
123125
checks, err := client.ListChecks(ctx)
124126
if err != nil {
125127
return fmt.Errorf("cannot list checks: %w", err)

0 commit comments

Comments
 (0)