Skip to content

Commit 0106792

Browse files
Nick Petersstrategicpause
authored andcommitted
chore: upgrade golangci-lint to v2.12.2 for Go 1.25 support
Upgrade golangci-lint from v1.60.3 to v2.12.2 and migrate the config to v2 format. The previous version was built with Go 1.23 and cannot analyze Go 1.25 code. Changes: - Migrate .golangci.yaml to v2 schema - Update GitHub Actions workflow to use golangci-lint-action v7 - Remove unused //nolint:gosec directives (gosec no longer flags these) - Add //nolint:gosec where needed for G101 and G115 false positives
1 parent 237d174 commit 0106792

11 files changed

Lines changed: 62 additions & 54 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ jobs:
3838
with:
3939
go-version: '1.25'
4040
- name: golangci-lint
41-
uses: golangci/golangci-lint-action@v6
41+
uses: golangci/golangci-lint-action@v7
4242
with:
4343
# Pin the version in case all the builds start to fail at the same time.
4444
# There may not be an automatic way (e.g., dependabot) to update a specific parameter of a GitHub Action,
4545
# so we will just update it manually whenever it makes sense (e.g., a feature that we want is added).
46-
version: v1.60.3
47-
args: --build-tags e2e,unit --fix=false --timeout=5m --out-format=colored-line-number
46+
version: v2.12.2
47+
args: --build-tags e2e,unit
4848
unit-tests:
4949
strategy:
5050
fail-fast: false

.golangci.yaml

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,25 @@
1-
# The sections in this file are ordered in the order presented in https://golangci-lint.run/usage/configuration/.
1+
version: "2"
2+
3+
# The sections in this file are ordered in the order presented in https://golangci-lint.run/docs/configuration/.
24
# The nested fields are ordered alphabetically.
35

4-
linters-settings:
5-
goheader:
6-
template-path: copyright_header
7-
goimports:
8-
local-prefixes: github.com/aws/shim-loggers-for-containerd
9-
gosec:
10-
config:
11-
G306: "0o644"
12-
lll:
13-
# 145 is just a lax value that does not require too much work to add this check,
14-
# and we don't want this to be too strict anyway.
15-
line-length: 145
16-
tab-width: 4
17-
makezero:
18-
always: true
19-
nolintlint:
20-
require-explanation: true
21-
require-specific: true
22-
stylecheck:
23-
# ST1003 is left out because it is a bit opinionated.
24-
checks: ["all", "-ST1003"]
25-
paralleltest:
26-
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of it.
27-
# Default: false
28-
ignore-missing: true
6+
formatters:
7+
enable:
8+
- goimports
9+
settings:
10+
goimports:
11+
local-prefixes:
12+
- github.com/aws/shim-loggers-for-containerd
13+
2914
linters:
15+
default: none
3016
enable:
3117
- errname
3218
- errorlint
3319
- forcetypeassert
3420
- gocritic
3521
- godot
3622
- goheader
37-
- goimports
3823
- gosec
3924
- lll
4025
- misspell
@@ -45,22 +30,44 @@ linters:
4530
- paralleltest
4631
- predeclared
4732
- revive
33+
- staticcheck
4834
- testableexamples
4935
- unconvert
5036
- unparam
5137
- usestdlibvars
5238
# TODO: Enable wastedassign after https://github.com/sanposhiho/wastedassign/issues/41 is fixed.
5339
# - wastedassign
5440
- whitespace
55-
- stylecheck
56-
issues:
57-
exclude-rules:
58-
- linters:
59-
- lll
60-
# A go:generate statement has to be in the same line: https://github.com/golang/go/issues/46050.
61-
source: "^//go:generate "
62-
# Some checks enabled in the stylecheck setting are disabled by default
63-
# (e.g., https://golangci-lint.run/usage/false-positives/#exc0013),
64-
# so we need to enable them explicitly here.
65-
exclude-use-default: false
66-
fix: true
41+
settings:
42+
goheader:
43+
template-path: copyright_header
44+
gosec:
45+
config:
46+
G306: "0o644"
47+
lll:
48+
# 145 is just a lax value that does not require too much work to add this check,
49+
# and we don't want this to be too strict anyway.
50+
line-length: 145
51+
tab-width: 4
52+
makezero:
53+
always: true
54+
nolintlint:
55+
require-explanation: true
56+
require-specific: true
57+
paralleltest:
58+
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of it.
59+
# Default: false
60+
ignore-missing: true
61+
staticcheck:
62+
checks: ["all", "-ST1003"]
63+
exclusions:
64+
presets:
65+
- comments
66+
- common-false-positives
67+
- legacy
68+
- std-error-handling
69+
rules:
70+
- linters:
71+
- lll
72+
# A go:generate statement has to be in the same line: https://github.com/golang/go/issues/46050.
73+
source: "^//go:generate "

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $(AWS_CONTAINERD_LOGGERS_BINARY):
2525

2626
.PHONY: test-unit
2727
test-unit: $(SOURCES)
28-
go test -tags unit -race -timeout 120s -cover $(shell go list ./... | grep -v e2e) --count=1
28+
go test -tags unit -race -timeout 120s -cover $(shell go list -tags unit ./... | grep -v -e e2e -e /mocks -e /debug) --count=1
2929

3030
.PHONY: test-e2e
3131
test-e2e:

args_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func TestGetAWSLogsArgs(t *testing.T) {
392392
credentialsEndpoint: "",
393393
expectedCredentialsEndpoint: "",
394394
},
395-
{
395+
{ //nolint:gosec // G101: test data, not real credentials
396396
name: "credentials endpoint provided",
397397
credentialsEndpoint: "http://localhost:8080/credentials",
398398
expectedCredentialsEndpoint: "http://localhost:8080/credentials",

debug/debug_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func StartStackTraceHandler() {
6464
// started by containerd, we can check the logs using `journalctl -u containerd.service`.
6565
func sendEventsToJournal(syslogIdentifier string, msg string, msgType journal.Priority, delay time.Duration) {
6666
vars := map[string]string{"SYSLOG_IDENTIFIER": syslogIdentifier}
67-
journal.Send(msg, msgType, vars) //nolint:errcheck,gosec // asynchronous process
67+
journal.Send(msg, msgType, vars) //nolint:errcheck // asynchronous process
6868
time.Sleep(delay * time.Second)
6969
}
7070

e2e/fluentd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func validateTestLogsInFluentd(dirName string, testLog string, testTag string) {
142142
})
143143
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
144144
gomega.Expect(fileName).ShouldNot(gomega.Equal(""))
145-
file, err := os.Open(fileName) //nolint:gosec // testing only
145+
file, err := os.Open(fileName)
146146
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
147147
defer file.Close() //nolint:errcheck // closing the file
148148
var lastLine string

e2e/jsonfile_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ var testJSONFile = func() {
268268
// readEnvelopeLines parses every JSON-line in the given file as a jsonFileEnvelope.
269269
// Empty lines are skipped. The test fails fast on any parse error.
270270
func readEnvelopeLines(path string) []jsonFileEnvelope {
271-
file, err := os.Open(path) //nolint:gosec // testing only
271+
file, err := os.Open(path)
272272
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
273273
defer file.Close() //nolint:errcheck // closing the file
274274

logger/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ func readFromContainerPipe(pipe io.Reader, buf []byte, bytesInBuffer, maxReadByt
479479
// Pipe is closed, set flag to true.
480480
eof = true
481481
}
482-
atomic.AddUint64(&bytesReadFromSrc, uint64(readBytesFromPipe))
482+
atomic.AddUint64(&bytesReadFromSrc, uint64(readBytesFromPipe)) //nolint:gosec // non-negative
483483
bytesInBuffer += readBytesFromPipe
484484
}
485485

logger/common_linux_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func TestTracingLogRouting(t *testing.T) {
6565
require.Equal(t, uint64(len(inputForStdout)+len(inputForStderr)), atomic.LoadUint64(&bytesReadFromSrc))
6666
// Exclude the new line characters because they will be removed when sending logs to the log driver.
6767
require.Equal(t,
68+
//nolint:gosec // G115: values are small test constants, no overflow risk.
6869
uint64(len(inputForStdout)+len(inputForStderr)-countOfNewLinesForStdout-countOfNewLinesForStderr),
6970
atomic.LoadUint64(&bytesSentToDst))
7071
require.Equal(t,

logger/common_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ func (d *dummyClient) Log(msg *dockerlogger.Message) error {
7272
if err != nil {
7373
return err
7474
}
75-
f, err := os.OpenFile(logDestinationFileName, os.O_APPEND|os.O_RDWR, 0644) //nolint:gosec // testing only
75+
f, err := os.OpenFile(logDestinationFileName, os.O_APPEND|os.O_RDWR, 0644)
7676
if err != nil {
7777
return fmt.Errorf("unable to open file %s to record log message: %w", logDestinationFileName, err)
7878
}
7979
defer f.Close() //nolint:errcheck // testing only
8080
b, err = json.Marshal(msg)
8181
require.NoError(d.t, err)
82-
f.Write(b) //nolint:errcheck,gosec // testing only
83-
f.Write([]byte{'\n'}) //nolint:errcheck,gosec // testing only
82+
f.Write(b) //nolint:errcheck // testing only
83+
f.Write([]byte{'\n'}) //nolint:errcheck // testing only
8484

8585
return nil
8686
}
@@ -93,7 +93,7 @@ func checkLogFile(t *testing.T, fileName string, expectedNumLines int,
9393
lastPartialID string
9494
lastPartialOrdinal int
9595
)
96-
file, err := os.Open(fileName) //nolint:gosec // testing only
96+
file, err := os.Open(fileName)
9797
require.NoError(t, err)
9898
defer file.Close() //nolint:errcheck // testing only
9999

@@ -275,7 +275,7 @@ func TestPipeNotBroken(t *testing.T) {
275275
require.NoError(t, err)
276276

277277
// Verify that the log destination received partial msg only.
278-
file, err := os.Open(logDestinationFileName) //nolint:gosec // testing only
278+
file, err := os.Open(logDestinationFileName)
279279
require.NoError(t, err)
280280
defer file.Close() //nolint:errcheck // testing only
281281

0 commit comments

Comments
 (0)