Skip to content

Commit 3566b8e

Browse files
Merge pull request #115 from StackVista/STAC-0-migrate-golangcilint-v2
STAC-0: migrate to golangcilint v2
2 parents 2e0d321 + 9520ce0 commit 3566b8e

11 files changed

Lines changed: 72 additions & 66 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ jobs:
2828
runs-on: ubuntu-latest
2929
timeout-minutes: 10
3030
steps:
31-
- uses: actions/checkout@v4
31+
- uses: actions/checkout@v5
3232
- uses: actions/setup-go@v5
3333
with:
3434
go-version: "1.21"
3535
cache: false
3636
- name: golangci-lint
37-
uses: golangci/golangci-lint-action@v4
37+
uses: golangci/golangci-lint-action@v8
3838
with:
3939
# Require: The version of golangci-lint to use.
4040
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
4141
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
42-
version: v1.64.4
42+
version: v2.3.1
4343

4444
check-license:
4545
name: License scan

.golangci.yml

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,81 @@
1+
version: "2"
12
run:
2-
# default concurrency is a available CPU number
33
concurrency: 4
4-
5-
# timeout for analysis, e.g. 30s, 5m, default is 1m
6-
timeout: 5m
7-
8-
# exit code when at least one issue was found, default is 1
94
issues-exit-code: 1
10-
11-
# include test files or not, default is true
125
tests: true
13-
14-
linters-settings:
15-
depguard:
16-
rules:
17-
main:
18-
list-mode: lax
19-
allow:
20-
- $gostd
21-
- github.com/stackvista
22-
lll:
23-
line-length: 250
24-
mnd:
25-
checks:
26-
- argument
27-
- case
28-
- condition
29-
- return
30-
31-
nolintlint:
32-
allow-unused: true # report any unused nolint directives
33-
require-specific: true # don't require nolint directives to be specific about which linter is being skipped
34-
35-
stylecheck:
36-
37-
funlen:
38-
lines: 100
39-
statements: 60
40-
416
linters:
42-
disable-all: true
7+
default: none
438
enable:
44-
# - bodyclose TODO: enable when fixed
45-
# - depguard
9+
- copyloopvar
4610
- dogsled
4711
- dupl
4812
- errcheck
4913
- exhaustive
50-
- copyloopvar
5114
- funlen
5215
- gochecknoinits
5316
- goconst
5417
- gocritic
5518
- gocyclo
56-
- gofmt
57-
- goimports
58-
- mnd
5919
- goprintffuncname
60-
# - gosec TODO: enable when fixed
61-
- gosimple
6220
- govet
6321
- ineffassign
6422
- lll
6523
- misspell
24+
- mnd
6625
- nakedret
6726
- noctx
6827
- nolintlint
69-
# - revive TODO: enable when fixed
7028
- rowserrcheck
7129
- staticcheck
72-
# - stylecheck TODO: enable when fixed
73-
- typecheck
7430
- unconvert
7531
- unparam
7632
- unused
7733
- whitespace
34+
# - gosec TODO: enable when fixed
35+
# - bodyclose TODO: enable when fixed
36+
# - depguard
37+
# - revive TODO: enable when fixed
38+
# - stylecheck TODO: enable when fixed
39+
settings:
40+
depguard:
41+
rules:
42+
main:
43+
list-mode: lax
44+
allow:
45+
- $gostd
46+
- github.com/stackvista
47+
funlen:
48+
lines: 100
49+
statements: 60
50+
lll:
51+
line-length: 250
52+
mnd:
53+
checks:
54+
- argument
55+
- case
56+
- condition
57+
- return
58+
nolintlint:
59+
require-specific: true
60+
allow-unused: true
61+
exclusions:
62+
generated: lax
63+
presets:
64+
- comments
65+
- common-false-positives
66+
- legacy
67+
- std-error-handling
68+
paths:
69+
- third_party$
70+
- builtin$
71+
- examples$
72+
formatters:
73+
enable:
74+
- gofmt
75+
- goimports
76+
exclusions:
77+
generated: lax
78+
paths:
79+
- third_party$
80+
- builtin$
81+
- examples$

cmd/dashboard/dashboard_edit_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestShouldEditDashboard(t *testing.T) {
9696
"scope": "privateDashboard"
9797
}`),
9898
}
99-
cli.Deps.Editor = mockEditor
99+
cli.Editor = mockEditor
100100

101101
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--id", "1234")
102102

@@ -136,7 +136,7 @@ func TestShouldEditDashboardWithIdentifier(t *testing.T) {
136136
"description": "Updated via identifier"
137137
}`),
138138
}
139-
cli.Deps.Editor = mockEditor
139+
cli.Editor = mockEditor
140140

141141
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--identifier", "urn:custom:dashboard:edit-test")
142142

@@ -153,7 +153,7 @@ func TestEditDashboardNoChanges(t *testing.T) {
153153

154154
// Custom editor that returns exactly the same content as input
155155
noChangeEditor := &NoChangeEditor{}
156-
cli.Deps.Editor = noChangeEditor
156+
cli.Editor = noChangeEditor
157157

158158
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--id", "1234")
159159

@@ -186,7 +186,7 @@ func TestEditDashboardWithJsonOutput(t *testing.T) {
186186
"description": "Testing JSON output"
187187
}`),
188188
}
189-
cli.Deps.Editor = mockEditor
189+
cli.Editor = mockEditor
190190

191191
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--id", "1234", "--output", "json")
192192

@@ -204,7 +204,7 @@ func TestEditDashboardNoChangesJsonOutput(t *testing.T) {
204204

205205
// Use NoChangeEditor that returns exactly the same content
206206
noChangeEditor := &NoChangeEditor{}
207-
cli.Deps.Editor = noChangeEditor
207+
cli.Editor = noChangeEditor
208208

209209
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--id", "1234", "--output", "json")
210210

@@ -223,7 +223,7 @@ func TestEditDashboardInvalidJson(t *testing.T) {
223223
mockEditor := &MockEditor{
224224
Content: []byte(`{"invalid": json syntax}`),
225225
}
226-
cli.Deps.Editor = mockEditor
226+
cli.Editor = mockEditor
227227

228228
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--id", "1234")
229229

@@ -242,7 +242,7 @@ func TestEditDashboardEditorError(t *testing.T) {
242242
mockEditor := &MockEditor{
243243
Error: errors.New("editor failed to open"),
244244
}
245-
cli.Deps.Editor = mockEditor
245+
cli.Editor = mockEditor
246246

247247
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--id", "1234")
248248

@@ -275,7 +275,7 @@ func TestEditDashboardUsesReverseEditorByDefault(t *testing.T) {
275275
mockEditor := &MockEditor{
276276
Content: []byte(`{"name": "changed-by-reverse-editor"}`),
277277
}
278-
cli.Deps.Editor = mockEditor
278+
cli.Editor = mockEditor
279279

280280
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--id", "1234")
281281

@@ -324,7 +324,7 @@ func TestEditDashboardApiErrors(t *testing.T) {
324324
mockEditor := &MockEditor{
325325
Content: []byte(`{"name": "changed"}`),
326326
}
327-
cli.Deps.Editor = mockEditor
327+
cli.Editor = mockEditor
328328
}
329329

330330
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--id", "1234")

cmd/stackpack/stackpack_describe.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func RunStackpackDescribeCommand(args *DescribeArgs) di.CmdWithApiFn {
8585
}
8686
}
8787

88+
//nolint:staticcheck
8889
notFound := fmt.Errorf("StackPack '%s' not found.", args.Name)
8990
if cli.IsJson() {
9091
cli.Printer.PrintErrJson(notFound)

cmd/stackpack/stackpack_test_cmd_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ func TestConfirmUpload(t *testing.T) {
437437
// In a real test environment, you'd mock the stdin reader
438438

439439
// Just verify the function signature is correct
440+
//nolint:staticcheck
440441
var confirmFunc func(*di.Deps, string) bool = confirmUpload
441442
assert.NotNil(t, confirmFunc)
442443

758 Bytes
Binary file not shown.

internal/client/stackstate_version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ func CheckVersionCompatibility(version stackstate_api.ServerVersion, minVersion
6363
}
6464

6565
func NewAPIVersionMismatchError(got string, expected string) common.CLIError {
66-
return common.NewAPIVersionError(fmt.Errorf("Incompatible API version: got '%s', but need '%s'-compatible version", got, expected))
66+
return common.NewAPIVersionError(fmt.Errorf("incompatible API version: got '%s', but need '%s'-compatible version", got, expected))
6767
}

internal/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (c *Config) GetContext(name string) (*NamedContext, common.CLIError) {
8181
}
8282
}
8383

84-
return nil, common.NewNotFoundError(fmt.Errorf("Context with name '%s' not found", name))
84+
return nil, common.NewNotFoundError(fmt.Errorf("context with name '%s' not found", name))
8585
}
8686

8787
// UnmarshalYAML unmarshals the StsContext YAML part into a struct, ensuring that any defaults are set.
@@ -153,7 +153,7 @@ func (c *StsContext) Validate(contextName string) common.CLIError {
153153

154154
authenticationTokens := util.RemoveEmpty([]string{c.APIToken, c.ServiceToken, c.K8sSAToken})
155155
if len(authenticationTokens) > 1 {
156-
errors = append(errors, fmt.Errorf("Can only specify one of {api-token | service-token | k8s-sa-token}"))
156+
errors = append(errors, fmt.Errorf("can only specify one of {api-token | service-token | k8s-sa-token}"))
157157
}
158158

159159
if c.HasCaCertificateFromArgSet() {

internal/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ current-context: default
181181
assert.NoError(t, err)
182182
assert.ErrorContains(t, c.Contexts[0].Context.Validate(c.Contexts[0].Name), `Failed to validate the 'default' context:
183183
* URL localhost:8080 must start with "https://" or "http://"
184-
* Can only specify one of {api-token | service-token | k8s-sa-token}`)
184+
* can only specify one of {api-token | service-token | k8s-sa-token}`)
185185
}
186186

187187
func TestMergeWithNoTokenOverride(t *testing.T) {

main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func TestExitCodeOnError(t *testing.T) {
190190
main()
191191
return
192192
}
193-
cmd := exec.Command(os.Args[0], "-test.run=TestExitCodeOnError") //nolint:gosec
193+
cmd := exec.Command(os.Args[0], "-test.run=TestExitCodeOnError") //nolint:gosec,noctx
194194
cmd.Env = append(os.Environ(), "BE_CRASHER=1")
195195
err := cmd.Run()
196196
if e, ok := err.(*exec.ExitError); ok && !e.Success() {

0 commit comments

Comments
 (0)