Skip to content

Commit 1fe6bc6

Browse files
ldezSeigeC
authored andcommitted
go1.20 support (golangci#3414)
1 parent 6222a2c commit 1fe6bc6

File tree

14 files changed

+44
-26
lines changed

14 files changed

+44
-26
lines changed

.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.19
21+
go-version: '1.20'
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.19
20+
go-version: '1.20'
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.19
9+
GO_VERSION: '1.20'
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.20
45+
# go-version: ${{ env.GO_VERSION }}
46+
go-version: 1.19
4547
- name: lint
4648
uses: golangci/golangci-lint-action@v3.4.0
4749
with:
@@ -88,8 +90,8 @@ jobs:
8890
strategy:
8991
matrix:
9092
golang:
91-
- 1.18
9293
- 1.19
94+
- '1.20'
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.19
21+
go-version: '1.20'
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.19
51+
go-version: '1.20'
5252

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

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.19 as builder
2+
FROM golang:1.20 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.19
13+
FROM golang:1.20
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.19-alpine as builder
2+
FROM golang:1.20-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.19-alpine
18+
FROM golang:1.20-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

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ require (
3939
github.com/golangci/gofmt v0.0.0-20220901101216-f2edd75033f2
4040
github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0
4141
github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca
42-
github.com/golangci/misspell v0.3.5
42+
github.com/golangci/misspell v0.4.0
4343
github.com/golangci/revgrep v0.0.0-20220804021717-745bb2f7c2e6
4444
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4
4545
github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8
@@ -112,7 +112,7 @@ require (
112112
gitlab.com/bosi/decorder v0.2.3
113113
golang.org/x/tools v0.5.0
114114
gopkg.in/yaml.v3 v3.0.1
115-
honnef.co/go/tools v0.3.3
115+
honnef.co/go/tools v0.4.0-0.dev.0.20221209223220-58c4d7e4b720
116116
mvdan.cc/gofumpt v0.4.0
117117
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed
118118
mvdan.cc/unparam v0.0.0-20221223090309-7455f1af531d
@@ -179,7 +179,7 @@ require (
179179
go.uber.org/multierr v1.6.0 // indirect
180180
go.uber.org/zap v1.17.0 // indirect
181181
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
182-
golang.org/x/exp/typeparams v0.0.0-20220827204233-334a2380cb91 // indirect
182+
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
183183
golang.org/x/mod v0.7.0 // indirect
184184
golang.org/x/sync v0.1.0 // indirect
185185
golang.org/x/sys v0.4.0 // indirect

go.sum

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/goanalysis/runner_loadingpackage.go

+1
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ func (lp *loadingPackage) convertError(err error) []packages.Error {
434434
// If you see this error message, please file a bug.
435435
lp.log.Warnf("Internal error: error %q (%T) without position", err, err)
436436
}
437+
437438
return errs
438439
}
439440

pkg/golinters/gofmt_common.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func extractIssuesFromPatch(patch string, lintCtx *linter.Context, linterName st
242242
}
243243

244244
if len(diffs) == 0 {
245-
return nil, fmt.Errorf("got no diffs from patch parser: %v", diffs)
245+
return nil, fmt.Errorf("got no diffs from patch parser: %v", patch)
246246
}
247247

248248
var issues []result.Issue

pkg/lint/lintersdb/manager.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
453453

454454
linter.NewConfig(golinters.NewGochecknoinits()).
455455
WithSince("v1.12.0").
456-
WithPresets(linter.PresetStyle).
457-
WithURL("https://github.com/leighmcculloch/gochecknoinits"),
456+
WithPresets(linter.PresetStyle),
458457

459458
linter.NewConfig(golinters.NewGocognit(gocognitCfg)).
460459
WithSince("v1.20.0").

pkg/lint/load.go

+12
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,17 @@ func (cl *ContextLoader) debugPrintLoadedPackages(pkgs []*packages.Package) {
160160

161161
func (cl *ContextLoader) parseLoadedPackagesErrors(pkgs []*packages.Package) error {
162162
for _, pkg := range pkgs {
163+
var errs []packages.Error
163164
for _, err := range pkg.Errors {
165+
// quick fix: skip error related to `go list` invocation by packages.Load()
166+
// The behavior has been changed between go1.19 and go1.20, the error is now inside the JSON content.
167+
// https://github.com/golangci/golangci-lint/pull/3414#issuecomment-1364756303
168+
if strings.Contains(err.Msg, "# command-line-arguments") {
169+
continue
170+
}
171+
172+
errs = append(errs, err)
173+
164174
if strings.Contains(err.Msg, "no Go files") {
165175
return errors.Wrapf(exitcodes.ErrNoGoFiles, "package %s", pkg.PkgPath)
166176
}
@@ -169,6 +179,8 @@ func (cl *ContextLoader) parseLoadedPackagesErrors(pkgs []*packages.Package) err
169179
return errors.Wrap(exitcodes.ErrFailure, err.Msg)
170180
}
171181
}
182+
183+
pkg.Errors = errs
172184
}
173185

174186
return nil

pkg/lint/runner.go

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func (r Runner) Run(ctx context.Context, linters []*linter.Config, lintCtx *lint
208208

209209
return
210210
}
211+
211212
issues = append(issues, linterIssues...)
212213
})
213214
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
//go:build go1.20
2+
13
//golangcitest:args -Etypecheck
24
package testdata
35

46
func TypeCheckBadCalls() {
5-
typecheckNotExists1.F1() // want "undeclared name: `typecheckNotExists1`"
6-
typecheckNotExists2.F2() // want "undeclared name: `typecheckNotExists2`"
7-
typecheckNotExists3.F3() // want "undeclared name: `typecheckNotExists3`"
8-
typecheckNotExists4.F4() // want "undeclared name: `typecheckNotExists4`"
7+
typecheckNotExists1.F1() // want "undefined: typecheckNotExists1"
8+
typecheckNotExists2.F2() // want "undefined: typecheckNotExists2"
9+
typecheckNotExists3.F3() // want "undefined: typecheckNotExists3"
10+
typecheckNotExists4.F4() // want "undefined: typecheckNotExists4"
911
}

0 commit comments

Comments
 (0)