Skip to content

Commit

Permalink
go1.20 support (#3414)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Feb 2, 2023
1 parent abe878d commit 3a6f840
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# ex:
# - 1.18beta1 -> 1.18.0-beta.1
# - 1.18rc1 -> 1.18.0-rc.1
go-version: 1.19
go-version: '1.20'

- name: Update GitHub action config
run: make assets/github-action-config.json
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-extra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
# ex:
# - 1.18beta1 -> 1.18.0-beta.1
# - 1.18rc1 -> 1.18.0-rc.1
go-version: 1.19
go-version: '1.20'
- name: Run go list
run: go list -json -m all > go.list
- name: Nancy
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

env:
GO_VERSION: 1.19
GO_VERSION: '1.20'

jobs:
# Check if there is any dirty change for go mod tidy
Expand Down Expand Up @@ -41,7 +41,9 @@ jobs:
# ex:
# - 1.18beta1 -> 1.18.0-beta.1
# - 1.18rc1 -> 1.18.0-rc.1
go-version: ${{ env.GO_VERSION }}
# TODO(ldez) must be changed after the first release of golangci-lint with go1.20
# go-version: ${{ env.GO_VERSION }}
go-version: 1.19
- name: lint
uses: golangci/golangci-lint-action@v3.4.0
with:
Expand Down Expand Up @@ -88,8 +90,8 @@ jobs:
strategy:
matrix:
golang:
- 1.18
- 1.19
- '1.20'
steps:
- uses: actions/checkout@v3
- name: Install Go
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# ex:
# - 1.18beta1 -> 1.18.0-beta.1
# - 1.18rc1 -> 1.18.0-rc.1
go-version: 1.19
go-version: '1.20'
- name: Unshallow
run: git fetch --prune --unshallow

Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
# ex:
# - 1.18beta1 -> 1.18.0-beta.1
# - 1.18rc1 -> 1.18.0-rc.1
go-version: 1.19
go-version: '1.20'

- name: Unshallow
run: git fetch --prune --unshallow
Expand Down
4 changes: 2 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# stage 1 building the code
FROM golang:1.19 as builder
FROM golang:1.20 as builder

ARG VERSION
ARG SHORT_COMMIT
Expand All @@ -10,7 +10,7 @@ WORKDIR /golangci
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

# stage 2
FROM golang:1.19
FROM golang:1.20
# related to https://github.com/golangci/golangci-lint/issues/3107
ENV GOROOT /usr/local/go
# don't place it into $GOPATH/bin because Drone mounts $GOPATH as volume
Expand Down
4 changes: 2 additions & 2 deletions build/alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# stage 1 building the code
FROM golang:1.19-alpine as builder
FROM golang:1.20-alpine as builder

ARG VERSION
ARG SHORT_COMMIT
Expand All @@ -15,7 +15,7 @@ RUN apk --no-cache add gcc musl-dev git mercurial
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

# stage 2
FROM golang:1.19-alpine
FROM golang:1.20-alpine
# related to https://github.com/golangci/golangci-lint/issues/3107
ENV GOROOT /usr/local/go
# gcc is required to support cgo;
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
github.com/golangci/gofmt v0.0.0-20220901101216-f2edd75033f2
github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0
github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca
github.com/golangci/misspell v0.3.5
github.com/golangci/misspell v0.4.0
github.com/golangci/revgrep v0.0.0-20220804021717-745bb2f7c2e6
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4
github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8
Expand Down Expand Up @@ -112,7 +112,7 @@ require (
gitlab.com/bosi/decorder v0.2.3
golang.org/x/tools v0.5.0
gopkg.in/yaml.v3 v3.0.1
honnef.co/go/tools v0.3.3
honnef.co/go/tools v0.4.0-0.dev.0.20221209223220-58c4d7e4b720
mvdan.cc/gofumpt v0.4.0
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed
mvdan.cc/unparam v0.0.0-20221223090309-7455f1af531d
Expand Down Expand Up @@ -179,7 +179,7 @@ require (
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/exp/typeparams v0.0.0-20220827204233-334a2380cb91 // indirect
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.4.0 // indirect
Expand Down
11 changes: 6 additions & 5 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/golinters/goanalysis/runner_loadingpackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ func (lp *loadingPackage) convertError(err error) []packages.Error {
// If you see this error message, please file a bug.
lp.log.Warnf("Internal error: error %q (%T) without position", err, err)
}

return errs
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/gofmt_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func extractIssuesFromPatch(patch string, lintCtx *linter.Context, linterName st
}

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

var issues []result.Issue
Expand Down
3 changes: 1 addition & 2 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {

linter.NewConfig(golinters.NewGochecknoinits()).
WithSince("v1.12.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/leighmcculloch/gochecknoinits"),
WithPresets(linter.PresetStyle),

linter.NewConfig(golinters.NewGocognit(gocognitCfg)).
WithSince("v1.20.0").
Expand Down
12 changes: 12 additions & 0 deletions pkg/lint/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,17 @@ func (cl *ContextLoader) debugPrintLoadedPackages(pkgs []*packages.Package) {

func (cl *ContextLoader) parseLoadedPackagesErrors(pkgs []*packages.Package) error {
for _, pkg := range pkgs {
var errs []packages.Error
for _, err := range pkg.Errors {
// quick fix: skip error related to `go list` invocation by packages.Load()
// The behavior has been changed between go1.19 and go1.20, the error is now inside the JSON content.
// https://github.com/golangci/golangci-lint/pull/3414#issuecomment-1364756303
if strings.Contains(err.Msg, "# command-line-arguments") {
continue
}

errs = append(errs, err)

if strings.Contains(err.Msg, "no Go files") {
return errors.Wrapf(exitcodes.ErrNoGoFiles, "package %s", pkg.PkgPath)
}
Expand All @@ -169,6 +179,8 @@ func (cl *ContextLoader) parseLoadedPackagesErrors(pkgs []*packages.Package) err
return errors.Wrap(exitcodes.ErrFailure, err.Msg)
}
}

pkg.Errors = errs
}

return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/lint/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func (r Runner) Run(ctx context.Context, linters []*linter.Config, lintCtx *lint

return
}

issues = append(issues, linterIssues...)
})
}
Expand Down
10 changes: 6 additions & 4 deletions test/testdata/notcompiles/typecheck_many_issues.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//go:build go1.20

//golangcitest:args -Etypecheck
package testdata

func TypeCheckBadCalls() {
typecheckNotExists1.F1() // want "undeclared name: `typecheckNotExists1`"
typecheckNotExists2.F2() // want "undeclared name: `typecheckNotExists2`"
typecheckNotExists3.F3() // want "undeclared name: `typecheckNotExists3`"
typecheckNotExists4.F4() // want "undeclared name: `typecheckNotExists4`"
typecheckNotExists1.F1() // want "undefined: typecheckNotExists1"
typecheckNotExists2.F2() // want "undefined: typecheckNotExists2"
typecheckNotExists3.F3() // want "undefined: typecheckNotExists3"
typecheckNotExists4.F4() // want "undefined: typecheckNotExists4"
}

0 comments on commit 3a6f840

Please sign in to comment.