Skip to content

Commit 96973ba

Browse files
authored
Merge pull request #384 from tylerauerbeck/bump-golangcilint
chore: bump golangci-lint to v2
2 parents 97cc997 + 67b8ce4 commit 96973ba

File tree

5 files changed

+130
-181
lines changed

5 files changed

+130
-181
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
env:
1212
# Common versions
1313
GO_VERSION: '1.24'
14-
GOLANGCI_VERSION: 'v1.64.2'
14+
GOLANGCI_VERSION: 'v2.5'
1515
DOCKER_BUILDX_VERSION: 'v0.8.2'
1616

1717
# Common users. We can't run a step 'if secrets.AWS_USR != ""' but we can run
@@ -77,7 +77,7 @@ jobs:
7777
# this action because it leaves 'annotations' (i.e. it comments on PRs to
7878
# point out linter violations).
7979
- name: Lint
80-
uses: golangci/golangci-lint-action@v6
80+
uses: golangci/golangci-lint-action@v8
8181
with:
8282
args: --timeout=10m0s
8383
version: ${{ env.GOLANGCI_VERSION }}

.golangci.yml

Lines changed: 124 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -1,186 +1,135 @@
1-
run:
2-
timeout: 2m
3-
1+
version: "2"
42
output:
5-
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
63
formats:
7-
- format: colored-line-number
8-
9-
linters-settings:
10-
errcheck:
11-
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
12-
# default is false: such cases aren't reported by default.
13-
check-type-assertions: false
14-
15-
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
16-
# default is false: such cases aren't reported by default.
17-
check-blank: false
18-
19-
# comma-separated list of pairs of the form pkg:regex
20-
# the regex is used to ignore names within pkg. (default "fmt:.*").
21-
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
22-
exclude-functions:
23-
- fmt:.*
24-
- io/ioutil:^Read.*
25-
26-
revive:
27-
rules:
28-
- name: package-comments
29-
severity: warning
30-
disabled: true
31-
exclude: [ "" ]
32-
gofmt:
33-
# simplify code: gofmt with `-s` option, true by default
34-
simplify: true
35-
36-
goimports:
37-
# put imports beginning with prefix after 3rd-party packages;
38-
# it's a comma-separated list of prefixes
39-
local-prefixes: github.com/crossplane-contrib/provider-ansible
40-
41-
gocyclo:
42-
# minimal code complexity to report, 30 by default (but we recommend 10-20)
43-
min-complexity: 10
44-
45-
dupl:
46-
# tokens count to trigger issue, 150 by default
47-
threshold: 100
48-
49-
goconst:
50-
# minimal length of string constant, 3 by default
51-
min-len: 3
52-
# minimal occurrences count to trigger, 3 by default
53-
min-occurrences: 5
54-
55-
lll:
56-
# tab width in spaces. Default to 1.
57-
tab-width: 1
58-
59-
unparam:
60-
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
61-
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
62-
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
63-
# with golangci-lint call it on a directory with the changed file.
64-
check-exported: false
65-
66-
nakedret:
67-
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
68-
max-func-lines: 30
69-
70-
prealloc:
71-
# XXX: we don't recommend using this linter before doing performance profiling.
72-
# For most programs usage of prealloc will be a premature optimization.
73-
74-
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
75-
# True by default.
76-
simple: true
77-
range-loops: true # Report preallocation suggestions on range loops, true by default
78-
for-loops: false # Report preallocation suggestions on for loops, false by default
79-
80-
gocritic:
81-
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint` run to see all tags and checks.
82-
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
83-
enabled-tags:
84-
- performance
85-
86-
settings: # settings passed to gocritic
87-
captLocal: # must be valid enabled check name
88-
paramsOnly: true
89-
rangeValCopy:
90-
sizeThreshold: 32
91-
4+
text:
5+
path: stdout
926
linters:
937
enable:
94-
- gosimple
95-
- staticcheck
96-
- unused
97-
- govet
98-
- gocyclo
99-
- gocritic
8+
- asasalint
9+
- asciicheck
10+
- bidichk
11+
- bodyclose
12+
- contextcheck
13+
- durationcheck
14+
- errchkjson
15+
- errorlint
16+
- exhaustive
17+
- gocheckcompilerdirectives
18+
- gochecksumtype
10019
- goconst
101-
- goimports
102-
- gofmt # We enable this as well as goimports for its simplify mode.
20+
- gocritic
21+
- gocyclo
22+
- gosec
23+
- gosmopolitan
24+
- loggercheck
25+
- makezero
26+
- misspell
27+
- musttag
28+
- nakedret
29+
- nilerr
30+
- nilnesserr
31+
- noctx
10332
- prealloc
33+
- protogetter
34+
- reassign
35+
- recvcheck
10436
- revive
37+
- rowserrcheck
38+
- spancheck
39+
- sqlclosecheck
40+
- testifylint
10541
- unconvert
106-
- misspell
107-
- nakedret
108-
109-
presets:
110-
- bugs
111-
- unused
112-
fast: false
113-
114-
42+
- unparam
43+
- zerologlint
44+
settings:
45+
dupl:
46+
threshold: 100
47+
errcheck:
48+
check-type-assertions: false
49+
check-blank: false
50+
exclude-functions:
51+
- fmt:.*
52+
- io/ioutil:^Read.*
53+
goconst:
54+
min-len: 3
55+
min-occurrences: 5
56+
gocritic:
57+
enabled-tags:
58+
- performance
59+
settings:
60+
captLocal:
61+
paramsOnly: true
62+
rangeValCopy:
63+
sizeThreshold: 32
64+
gocyclo:
65+
min-complexity: 10
66+
lll:
67+
tab-width: 1
68+
nakedret:
69+
max-func-lines: 30
70+
prealloc:
71+
simple: true
72+
range-loops: true
73+
for-loops: false
74+
revive:
75+
rules:
76+
- name: package-comments
77+
severity: warning
78+
disabled: true
79+
exclude:
80+
- ""
81+
unparam:
82+
check-exported: false
83+
exclusions:
84+
generated: lax
85+
rules:
86+
- linters:
87+
- dupl
88+
- errcheck
89+
- gocyclo
90+
- gosec
91+
- scopelint
92+
- unparam
93+
path: _test(ing)?\.go
94+
- linters:
95+
- gocritic
96+
path: _test\.go
97+
text: (unnamedResult|exitAfterDefer)
98+
- linters:
99+
- gocritic
100+
text: '(hugeParam|rangeValCopy):'
101+
- linters:
102+
- staticcheck
103+
text: 'SA3000:'
104+
- linters:
105+
- gosec
106+
text: 'G101:'
107+
- linters:
108+
- gosec
109+
text: 'G104:'
110+
paths:
111+
- zz_generated\..+\.go$
112+
- third_party$
113+
- builtin$
114+
- examples$
115115
issues:
116-
# Excluding configuration per-path and per-linter
117-
exclude-rules:
118-
# Exclude some linters from running on tests files.
119-
- path: _test(ing)?\.go
120-
linters:
121-
- gocyclo
122-
- errcheck
123-
- dupl
124-
- gosec
125-
- scopelint
126-
- unparam
127-
128-
# Ease some gocritic warnings on test files.
129-
- path: _test\.go
130-
text: "(unnamedResult|exitAfterDefer)"
131-
linters:
132-
- gocritic
133-
134-
# These are performance optimisations rather than style issues per se.
135-
# They warn when function arguments or range values copy a lot of memory
136-
# rather than using a pointer.
137-
- text: "(hugeParam|rangeValCopy):"
138-
linters:
139-
- gocritic
140-
141-
# This "TestMain should call os.Exit to set exit code" warning is not clever
142-
# enough to notice that we call a helper method that calls os.Exit.
143-
- text: "SA3000:"
144-
linters:
145-
- staticcheck
146-
147-
- text: "k8s.io/api/core/v1"
148-
linters:
149-
- goimports
150-
151-
# This is a "potential hardcoded credentials" warning. It's triggered by
152-
# any variable with 'secret' in the same, and thus hits a lot of false
153-
# positives in Kubernetes land where a Secret is an object type.
154-
- text: "G101:"
155-
linters:
156-
- gosec
157-
- gas
158-
159-
# This is an 'errors unhandled' warning that duplicates errcheck.
160-
- text: "G104:"
161-
linters:
162-
- gosec
163-
- gas
164-
165-
exclude-files:
166-
- "zz_generated\\..+\\.go$"
167-
168-
# Independently from option `exclude` we use default exclude patterns,
169-
# it can be disabled by this option. To list all
170-
# excluded by default patterns execute `golangci-lint run --help`.
171-
# Default value for this option is true.
172-
exclude-use-default: false
173-
174-
# Show only new issues: if there are unstaged changes or untracked files,
175-
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
176-
# It's a super-useful option for integration of golangci-lint into existing
177-
# large codebase. It's not practical to fix all existing issues at the moment
178-
# of integration: much better don't allow issues in new code.
179-
# Default is false.
180-
new: false
181-
182-
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
183116
max-issues-per-linter: 0
184-
185-
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
186117
max-same-issues: 0
118+
new: false
119+
formatters:
120+
enable:
121+
- gofmt
122+
- goimports
123+
settings:
124+
gofmt:
125+
simplify: true
126+
goimports:
127+
local-prefixes:
128+
- github.com/crossplane-contrib/provider-ansible
129+
exclusions:
130+
generated: lax
131+
paths:
132+
- zz_generated\..+\.go$
133+
- third_party$
134+
- builtin$
135+
- examples$

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ GO_STATIC_PACKAGES = $(GO_PROJECT)/cmd/provider
2121
GO_LDFLAGS += -X $(GO_PROJECT)/internal/version.Version=$(VERSION)
2222
GO_SUBDIRS += cmd internal apis
2323
GO111MODULE = on
24-
GOLANGCILINT_VERSION = 1.64.2
24+
GOLANGCILINT_VERSION = 2.5.0
2525
RUNNING_IN_CI = true
2626
-include build/makelib/golang.mk
2727

@@ -143,4 +143,4 @@ help-special: crossplane.help
143143
.PHONY: crossplane.help help-special
144144

145145
vendor: modules.download
146-
vendor.check: modules.check
146+
vendor.check: modules.check

internal/ansible/ansible_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func TestAnsibleRunPolicyInit(t *testing.T) {
117117
t.Fatalf("Error occurred unexpectedly: %v", err)
118118
}
119119

120-
switch {
120+
switch { //nolint:staticcheck
121121
case tc.policy == "ObserveAndDelete":
122122
if testRunner.AnsibleRunPolicy.Name != "ObserveAndDelete" {
123123
t.Fatalf("Unexpected policy %v expected %v", testRunner.AnsibleRunPolicy.Name, "ObserveAndDelete")

internal/controller/ansibleRun/ansibleRun_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ func TestObserve(t *testing.T) {
643643
return nil
644644
},
645645
MockRun: func(ctx context.Context) (io.Reader, error) {
646-
cmd := exec.Command("ls")
646+
cmd := exec.Command("ls") //nolint:noctx
647647
cmd.Start()
648648
return nil, cmd.Wait()
649649
},

0 commit comments

Comments
 (0)