Skip to content

Commit e0a8bd8

Browse files
authored
go1.21 support (#3922)
1 parent c37828a commit e0a8bd8

File tree

14 files changed

+55
-16
lines changed

14 files changed

+55
-16
lines changed

.github/workflows/documentation.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
name: Build and deploy documentation
1212
runs-on: ubuntu-latest
1313
env:
14-
GO_VERSION: '1.20'
14+
GO_VERSION: '1.21'
1515
NODE_VERSION: '20.x'
1616
CGO_ENABLED: 0
1717

.github/workflows/post-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
# ex:
1919
# - 1.18beta1 -> 1.18.0-beta.1
2020
# - 1.18rc1 -> 1.18.0-rc.1
21-
go-version: '1.20'
21+
go-version: '1.21'
2222

2323
- name: Update GitHub action config
2424
run: make assets/github-action-config.json

.github/workflows/pr-extra.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
# ex:
1818
# - 1.18beta1 -> 1.18.0-beta.1
1919
# - 1.18rc1 -> 1.18.0-rc.1
20-
go-version: '1.20'
20+
go-version: '1.21'
2121
- name: Run go list
2222
run: go list -json -m all > go.list
2323
- name: Nancy

.github/workflows/pr.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
pull_request:
77

88
env:
9-
GO_VERSION: '1.20'
9+
GO_VERSION: '1.21'
1010

1111
jobs:
1212
# Check if there is any dirty change for go mod tidy
@@ -41,7 +41,9 @@ jobs:
4141
# ex:
4242
# - 1.18beta1 -> 1.18.0-beta.1
4343
# - 1.18rc1 -> 1.18.0-rc.1
44-
go-version: ${{ env.GO_VERSION }}
44+
# TODO(ldez) must be changed after the first release of golangci-lint with go1.21
45+
# go-version: ${{ env.GO_VERSION }}
46+
go-version: '1.20'
4547
- name: lint
4648
uses: golangci/[email protected]
4749
with:
@@ -88,8 +90,8 @@ jobs:
8890
strategy:
8991
matrix:
9092
golang:
91-
- 1.19
9293
- '1.20'
94+
- '1.21'
9395
steps:
9496
- uses: actions/checkout@v3
9597
- name: Install Go

.github/workflows/tag.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
# ex:
1919
# - 1.18beta1 -> 1.18.0-beta.1
2020
# - 1.18rc1 -> 1.18.0-rc.1
21-
go-version: '1.20'
21+
go-version: '1.21'
2222
- name: Unshallow
2323
run: git fetch --prune --unshallow
2424

@@ -48,7 +48,7 @@ jobs:
4848
# ex:
4949
# - 1.18beta1 -> 1.18.0-beta.1
5050
# - 1.18rc1 -> 1.18.0-rc.1
51-
go-version: '1.20'
51+
go-version: '1.21'
5252

5353
- name: Unshallow
5454
run: git fetch --prune --unshallow

.golangci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ issues:
155155
text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead."
156156
- path: pkg/golinters/unused.go
157157
text: "rangeValCopy: each iteration copies 160 bytes \\(consider pointers or indexing\\)"
158+
- path: test/(fix|linters)_test.go
159+
text: "string `gocritic.go` has 3 occurrences, make it a constant"
158160

159161
run:
160162
timeout: 5m

build/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# stage 1 building the code
2-
FROM golang:1.20 as builder
2+
FROM golang:1.21 as builder
33

44
ARG VERSION
55
ARG SHORT_COMMIT
@@ -10,7 +10,7 @@ WORKDIR /golangci
1010
RUN CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=$VERSION -X main.commit=$SHORT_COMMIT -X main.date=$DATE" -o golangci-lint ./cmd/golangci-lint/main.go
1111

1212
# stage 2
13-
FROM golang:1.20
13+
FROM golang:1.21
1414
# related to https://github.com/golangci/golangci-lint/issues/3107
1515
ENV GOROOT /usr/local/go
1616
# don't place it into $GOPATH/bin because Drone mounts $GOPATH as volume

build/alpine.Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# stage 1 building the code
2-
FROM golang:1.20-alpine as builder
2+
FROM golang:1.21-alpine as builder
33

44
ARG VERSION
55
ARG SHORT_COMMIT
@@ -15,7 +15,7 @@ RUN apk --no-cache add gcc musl-dev git mercurial
1515
RUN CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=$VERSION -X main.commit=$SHORT_COMMIT -X main.date=$DATE" -o golangci-lint ./cmd/golangci-lint/main.go
1616

1717
# stage 2
18-
FROM golang:1.20-alpine
18+
FROM golang:1.21-alpine
1919
# related to https://github.com/golangci/golangci-lint/issues/3107
2020
ENV GOROOT /usr/local/go
2121
# gcc is required to support cgo;

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/golangci/golangci-lint
22

3-
go 1.19
3+
go 1.20
44

55
require (
66
4d63.com/gocheckcompilerdirectives v1.2.1

pkg/config/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ type Version struct {
4141
Debug bool `mapstructure:"debug"`
4242
}
4343

44-
func IsGreaterThanOrEqualGo118(v string) bool {
44+
func IsGreaterThanOrEqualGo121(v string) bool {
4545
v1, err := hcversion.NewVersion(strings.TrimPrefix(v, "go"))
4646
if err != nil {
4747
return false
4848
}
4949

50-
limit, err := hcversion.NewVersion("1.18")
50+
limit, err := hcversion.NewVersion("1.21")
5151
if err != nil {
5252
return false
5353
}

pkg/golinters/gocritic.go

+14
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,20 @@ func newGoCriticSettingsWrapper(settings *config.GoCriticSettings, logger loguti
283283
allCheckerMap[checkInfo.Name] = checkInfo
284284
}
285285

286+
if settings != nil && config.IsGreaterThanOrEqualGo121(settings.Go) {
287+
var enabledChecks []string
288+
for _, check := range settings.EnabledChecks {
289+
if check == "ruleguard" {
290+
logger.Warnf("%s: check %q is disabled for go1.21 https://github.com/golangci/golangci-lint/issues/3933", goCriticName, "ruleguard")
291+
continue
292+
}
293+
294+
enabledChecks = append(enabledChecks, check)
295+
}
296+
297+
settings.EnabledChecks = enabledChecks
298+
}
299+
286300
return &goCriticSettingsWrapper{
287301
GoCriticSettings: settings,
288302
logger: logger,

pkg/lint/linter/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (lc *Config) Name() string {
134134
}
135135

136136
func (lc *Config) WithNoopFallback(cfg *config.Config) *Config {
137-
if cfg != nil && config.IsGreaterThanOrEqualGo118(cfg.Run.Go) {
137+
if cfg != nil && config.IsGreaterThanOrEqualGo121(cfg.Run.Go) {
138138
lc.Linter = &Noop{
139139
name: lc.Linter.Name(),
140140
desc: lc.Linter.Desc(),

test/fix_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ func TestFix(t *testing.T) {
4343

4444
for _, input := range sources {
4545
input := input
46+
47+
// TODO(ldez): remove this limitation when gocritic/ruleguard will be fixed.
48+
if filepath.Base(input) == "gocritic.go" {
49+
t.Logf("skip gocritic because of a bug with ruleguard")
50+
continue
51+
}
52+
4653
t.Run(filepath.Base(input), func(t *testing.T) {
4754
t.Parallel()
4855

@@ -80,6 +87,13 @@ func TestFix_pathPrefix(t *testing.T) {
8087

8188
for _, input := range sources {
8289
input := input
90+
91+
// TODO(ldez): remove this limitation when gocritic/ruleguard will be fixed.
92+
if filepath.Base(input) == "gocritic.go" {
93+
t.Logf("skip gocritic because of a bug with ruleguard")
94+
continue
95+
}
96+
8397
t.Run(filepath.Base(input), func(t *testing.T) {
8498
t.Parallel()
8599

test/linters_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ func testSourcesFromDir(t *testing.T, dir string) {
6262

6363
for _, source := range sources {
6464
source := source
65+
66+
// TODO(ldez): remove this limitation when gocritic/ruleguard will be fixed.
67+
if filepath.Base(source) == "gocritic.go" {
68+
t.Logf("skip gocritic because of a bug with ruleguard")
69+
continue
70+
}
71+
6572
t.Run(filepath.Base(source), func(subTest *testing.T) {
6673
subTest.Parallel()
6774

0 commit comments

Comments
 (0)