Skip to content

Commit a93e36e

Browse files
authored
chore: migrate to golangci-lint v2 (#533)
1 parent 64cb824 commit a93e36e

56 files changed

Lines changed: 403 additions & 232 deletions

Some content is hidden

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

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
go-version-file: go.mod
1616

1717
- name: Lint
18-
uses: golangci/golangci-lint-action@v6.2.0
18+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
1919
with:
20-
version: v1.63
20+
version: v2.1.6
2121
args: --verbose
2222

2323
- name: Test

.golangci.yaml

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
issues:
2+
max-issues-per-linter: 0
3+
max-same-issues: 0
4+
5+
linters:
6+
settings:
7+
depguard:
8+
rules:
9+
main:
10+
list-mode: lax
11+
deny:
12+
# Cannot use gomodguard, which examines go.mod, as "golang.org/x/exp/slices" is not a module and doesn't appear in go.mod.
13+
- pkg: "golang.org/x/exp/slices"
14+
desc: "Use 'slices' instead"
15+
- pkg: "golang.org/x/exp/maps"
16+
desc: "Use 'maps' or 'github.com/samber/lo' instead"
17+
dupl:
18+
threshold: 100
19+
errcheck:
20+
check-type-assertions: true
21+
check-blank: true
22+
goconst:
23+
min-len: 3
24+
min-occurrences: 3
25+
gocritic:
26+
disabled-checks:
27+
- appendAssign
28+
- commentedOutCode
29+
- hugeParam
30+
- importShadow # FIXME
31+
- indexAlloc
32+
- rangeValCopy
33+
- regexpSimplify
34+
- sloppyReassign
35+
- unnamedResult
36+
- whyNoLint
37+
enabled-tags:
38+
- diagnostic
39+
- style
40+
- performance
41+
- experimental
42+
- opinionated
43+
gocyclo:
44+
min-complexity: 20
45+
gomodguard:
46+
blocked:
47+
modules:
48+
- github.com/hashicorp/go-version:
49+
recommendations:
50+
- github.com/aquasecurity/go-version
51+
reason: "`aquasecurity/go-version` is designed for our use-cases"
52+
- github.com/Masterminds/semver:
53+
recommendations:
54+
- github.com/aquasecurity/go-version
55+
reason: "`aquasecurity/go-version` is designed for our use-cases"
56+
gosec:
57+
excludes:
58+
- G101
59+
- G114
60+
- G115
61+
- G204
62+
- G304
63+
- G402
64+
govet:
65+
disable:
66+
- shadow
67+
misspell:
68+
locale: US
69+
ignore-rules:
70+
- behaviour
71+
- licence
72+
- optimise
73+
- simmilar
74+
perfsprint:
75+
# Optimizes even if it requires an int or uint type cast.
76+
int-conversion: true
77+
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
78+
err-error: true
79+
# Optimizes `fmt.Errorf`.
80+
errorf: true
81+
# Optimizes `fmt.Sprintf` with only one argument.
82+
sprintf1: false
83+
# Optimizes into strings concatenation.
84+
strconcat: false
85+
revive:
86+
max-open-files: 2048
87+
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md
88+
rules:
89+
- name: bool-literal-in-expr
90+
- name: context-as-argument
91+
arguments:
92+
- allowTypesBefore: "*testing.T"
93+
- name: duplicated-imports
94+
- name: early-return
95+
arguments:
96+
- preserve-scope
97+
- name: if-return
98+
- name: increment-decrement
99+
- name: indent-error-flow
100+
arguments:
101+
- preserve-scope
102+
- name: range
103+
- name: range-val-address
104+
- name: superfluous-else
105+
arguments:
106+
- preserve-scope
107+
- name: time-equal
108+
- name: unnecessary-stmt
109+
- name: unused-parameter
110+
- name: use-any
111+
112+
staticcheck:
113+
checks:
114+
- all
115+
- -QF1008 # Omit embedded fields from selector expression
116+
- -S1007 # Simplify regular expression by using raw string literal
117+
- -S1011 # Use a single append to concatenate two slices
118+
- -S1023 # Omit redundant control flow
119+
- -SA1019 # Using a deprecated function, variable, constant or field
120+
- -SA1024 # A string cutset contains duplicate characters
121+
- -SA4004 # The loop exits unconditionally after one iteration
122+
- -SA4023 # Impossible comparison of interface value with untyped nil
123+
- -SA4032 # Comparing runtime.GOOS or runtime.GOARCH against impossible value
124+
- -SA5011 # Possible nil pointer dereference
125+
- -ST1003 # Poorly chosen identifier
126+
- -ST1012 # Poorly chosen name for error variable
127+
128+
testifylint:
129+
enable-all: true
130+
131+
default: none
132+
133+
enable:
134+
- bodyclose
135+
- depguard
136+
- goconst
137+
- gocritic
138+
- gocyclo
139+
- gomodguard
140+
- gosec
141+
- govet
142+
- ineffassign
143+
- misspell
144+
- perfsprint
145+
- revive
146+
- staticcheck
147+
- testifylint
148+
- unconvert
149+
- unused
150+
- usestdlibvars
151+
- usetesting
152+
153+
exclusions:
154+
generated: lax
155+
paths:
156+
- "pkg/iac/scanners/terraform/parser/funcs" # copies of Terraform functions
157+
rules:
158+
- path: ".*_test.go$"
159+
linters:
160+
- goconst
161+
- gosec
162+
- unused
163+
- path: ".*_test.go$"
164+
linters:
165+
- govet
166+
text: "copylocks:"
167+
- path: ".*_test.go$"
168+
linters:
169+
- gocritic
170+
text: "commentFormatting:"
171+
- path: ".*_test.go$"
172+
linters:
173+
- gocritic
174+
text: "exitAfterDefer:"
175+
- path: ".*_test.go$"
176+
linters:
177+
- gocritic
178+
text: "importShadow:"
179+
- linters:
180+
- goconst
181+
text: "string `each` has 3 occurrences, make it a constant" # FIXME
182+
presets:
183+
- comments
184+
- common-false-positives
185+
- legacy
186+
- std-error-handling
187+
warn-unused: true
188+
189+
run:
190+
go: '1.24'
191+
timeout: 30m
192+
193+
formatters:
194+
enable:
195+
- gci
196+
- gofmt
197+
198+
exclusions:
199+
generated: lax
200+
201+
settings:
202+
gci:
203+
sections:
204+
- standard
205+
- default
206+
- prefix(github.com/aquasecurity/)
207+
- blank
208+
- dot
209+
gofmt:
210+
simplify: false
211+
212+
version: "2"

.golangci.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

pkg/db/advisory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/aquasecurity/trivy-db/pkg/types"
1010
)
1111

12-
func (dbc Config) PutAdvisory(tx *bolt.Tx, bktNames []string, key string, advisory interface{}) error {
12+
func (dbc Config) PutAdvisory(tx *bolt.Tx, bktNames []string, key string, advisory any) error {
1313
if err := dbc.put(tx, bktNames, key, advisory); err != nil {
1414
return oops.With("key", key).Wrapf(err, "failed to put advisory")
1515
}

pkg/db/advisory_detail.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const (
1111
advisoryDetailBucket = "advisory-detail"
1212
)
1313

14-
func (dbc Config) PutAdvisoryDetail(tx *bolt.Tx, vulnID, pkgName string, nestedBktNames []string, advisory interface{}) error {
14+
func (dbc Config) PutAdvisoryDetail(tx *bolt.Tx, vulnID, pkgName string, nestedBktNames []string, advisory any) error {
1515
bktNames := append([]string{advisoryDetailBucket, vulnID}, nestedBktNames...)
1616
if err := dbc.put(tx, bktNames, pkgName, advisory); err != nil {
1717
return oops.With("vuln_id", vulnID).With("package_name", pkgName).Wrapf(err, "failed to put advisory detail")
@@ -53,7 +53,7 @@ func (dbc Config) saveAdvisories(tx *bolt.Tx, bkt *bolt.Bucket, bktNames []strin
5353
return eb.Wrapf(err, "unable to save advisories")
5454
}
5555
} else {
56-
detail := map[string]interface{}{}
56+
detail := map[string]any{}
5757
if err := json.Unmarshal(v, &detail); err != nil {
5858
return eb.Wrapf(err, "json unmarshal error")
5959
}

pkg/db/advisory_detail_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestConfig_SaveAdvisoryDetails(t *testing.T) {
6868
})
6969

7070
if tt.wantErr != "" {
71-
require.NotNil(t, err)
71+
require.Error(t, err)
7272
assert.Contains(t, err.Error(), tt.wantErr)
7373
return
7474
}

pkg/db/advisory_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ func TestConfig_ForEachAdvisory(t *testing.T) {
8888
got, err := dbc.ForEachAdvisory([]string{tt.args.source}, tt.args.pkgName)
8989

9090
if tt.wantErr != "" {
91-
require.NotNil(t, err)
91+
require.Error(t, err)
9292
assert.Contains(t, err.Error(), tt.wantErr)
9393
return
9494
}
9595

96-
assert.NoError(t, err)
96+
require.NoError(t, err)
9797

9898
// Compare
99-
assert.Equal(t, len(tt.want), len(got))
99+
assert.Len(t, got, len(tt.want))
100100
for cveID, g := range got {
101101
wantAdvisory, ok := tt.want[cveID]
102102
if !ok {
@@ -210,10 +210,10 @@ func TestConfig_GetAdvisories(t *testing.T) {
210210

211211
switch {
212212
case tt.wantErr != "":
213-
require.NotNil(t, err)
213+
require.Error(t, err)
214214
assert.Contains(t, err.Error(), tt.wantErr)
215215
default:
216-
assert.NoError(t, err)
216+
require.NoError(t, err)
217217
}
218218

219219
// Compare

pkg/db/db.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/aquasecurity/trivy-db/pkg/types"
1616
)
1717

18-
type CustomPut func(dbc Operation, tx *bolt.Tx, adv interface{}) error
18+
type CustomPut func(dbc Operation, tx *bolt.Tx, adv any) error
1919

2020
const SchemaVersion = 2
2121

@@ -39,7 +39,7 @@ type Operation interface {
3939
GetVulnerability(vulnerabilityID string) (vulnerability types.Vulnerability, err error)
4040

4141
SaveAdvisoryDetails(tx *bolt.Tx, cveID string) (err error)
42-
PutAdvisoryDetail(tx *bolt.Tx, vulnerabilityID, pkgName string, nestedBktNames []string, advisory interface{}) (err error)
42+
PutAdvisoryDetail(tx *bolt.Tx, vulnerabilityID, pkgName string, nestedBktNames []string, advisory any) (err error)
4343
DeleteAdvisoryDetailBucket() error
4444

4545
PutDataSource(tx *bolt.Tx, bktName string, source types.DataSource) (err error)
@@ -73,7 +73,7 @@ func Init(dbDir string, opts ...Option) (err error) {
7373
}
7474

7575
eb := oops.With("db_dir", dbDir)
76-
if err = os.MkdirAll(dbDir, 0700); err != nil {
76+
if err = os.MkdirAll(dbDir, 0o700); err != nil {
7777
return eb.Wrapf(err, "failed to mkdir")
7878
}
7979
dbPath := Path(dbDir)
@@ -92,7 +92,7 @@ func Init(dbDir string, opts ...Option) (err error) {
9292
debug.SetPanicOnFault(false)
9393
}()
9494

95-
db, err = bolt.Open(dbPath, 0644, dbOptions.boltOptions)
95+
db, err = bolt.Open(dbPath, 0o644, dbOptions.boltOptions)
9696
if err != nil {
9797
return eb.Wrapf(err, "failed to open db")
9898
}
@@ -127,7 +127,7 @@ func (dbc Config) BatchUpdate(fn func(tx *bolt.Tx) error) error {
127127
return nil
128128
}
129129

130-
func (dbc Config) put(tx *bolt.Tx, bktNames []string, key string, value interface{}) error {
130+
func (dbc Config) put(tx *bolt.Tx, bktNames []string, key string, value any) error {
131131
if len(bktNames) == 0 {
132132
return oops.Errorf("empty bucket name")
133133
}

0 commit comments

Comments
 (0)