golangci-lint "DecodeRune not declared by package utf8" with golang 1.13

Created on 3 Sep 2019  路  17Comments  路  Source: golangci/golangci-lint

Please include the following information:

  1. Version of golangci-lint: golangci-lint --version (or git commit if you don't use binary distribution)
$ golangci-lint --version
golangci-lint has version 1.17.1 built from 4ba2155 on 2019-06-10T09:07:35Z
  1. Config file: cat .golangci.yml - none

  2. Go environment: go version && go env

$ go version
go version go1.13 darwin/amd64

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/foo/Library/Caches/go-build"
GOENV="/Users/foo/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/foo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/foo/go/src/github.com/gardener/gardener-extensions/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/p9/6dr9snnx6ws1dxkj4b66st6r0000gn/T/go-build176963248=/tmp/go-build -gno-record-gcc-switches -fno-common"
  1. Verbose output of running: golangci-lint run -v
$ golangci-lint run ./...

foo.go:1: /usr/local/go/src/regexp/regexp.go:967:22: DecodeRuneInString not declared by package utf8 (typecheck)
bar.go:1: /usr/local/go/src/mime/encodedword.go:130:22: DecodeRuneInString not declared by package utf8 (typecheck)
baz.go:1: /usr/local/go/src/go/token/token.go:317:16: DecodeRuneInString not declared by package utf8

Most helpful comment

Thanks, to explain what seems to be going on here:

golangci-lint, built with Go 1.12, will generate this error when linting Go 1.13 code.

If you're using a pre-built binary of golangci-lint then you'll run in to this error.

As @stevenh said, rebuilding golangci-lint fixes the error. Specifically, if you're currently following the golangci-lint install instructions (which downloads a pre-built binary from GitHub) then this will not work with Go 1.13. You'll have to install golangci-lint from source instead (at least until golangci-lint releases a version built with Go 1.13).

If you're installing golangci-lint with:

curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh

Use this instead:

GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint

All 17 comments

FYI same issue here, but affecting multiple functions not declared by package utf8 (typecheck):

  • DecodeRune
  • DecodeRuneInString
  • ValidString

If you rebuild with golang 1.13 it seem to work after that.

/cc @jirfag

Exactly the same issue for me

Temp workaround for me:

.golangci.yml

issues:
  exclude:
    - "not declared by package utf8"
    - "unicode/utf8/utf8.go"

Thanks, to explain what seems to be going on here:

golangci-lint, built with Go 1.12, will generate this error when linting Go 1.13 code.

If you're using a pre-built binary of golangci-lint then you'll run in to this error.

As @stevenh said, rebuilding golangci-lint fixes the error. Specifically, if you're currently following the golangci-lint install instructions (which downloads a pre-built binary from GitHub) then this will not work with Go 1.13. You'll have to install golangci-lint from source instead (at least until golangci-lint releases a version built with Go 1.13).

If you're installing golangci-lint with:

curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh

Use this instead:

GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint

So I guess what we need is just another release on GoReleaser built with Go 1.13. Using GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint certainly works but AFAIK will alaways get the latest master instead of a released version which, in most cases, is not desirable.

But just building golangci-lint with Go 1.13 doesn't seem to fix the underlying issue. It's not like DecodeRune changed since 1.13 so there must be something internally in golangci-lint that goes wrong and might also go wrong for other packages?

But just building golangci-lint with Go 1.13 doesn't seem to fix the underlying issue. It's not like DecodeRune changed since 1.13 so there must be something internally in golangci-lint that goes wrong and might also go wrong for other packages?

I believe it is because Go 1.13 added binary integer literals and they are being used in the standard library but Go 1.12 doesn't recognize them thus can't really build the module and as such DecodeRune is not being reported as available by runtime.

Does it make sense?

While

GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint

is a valid workaround, it builds the master branch.

To get the latest release instead, use

GO111MODULE=off go get gopkg.in/golangci/golangci-lint.v1/cmd/golangci-lint

To get the latest release instead, use

GO111MODULE=off go get gopkg.in/golangci/golangci-lint.v1/cmd/golangci-lint

I would expect this to pull the latest tagged version for major version 1 and instead it pulled master for me; have CI now failing on funLen linter which was just merged to master.

And to make matters worse I can't install the specific version via go modules because from go-1.13 point of view the mod file is corrupted (fix is already in master). Vicious circle :D

Hi! sorry for the slow response.
I've published the 1.18.0 release. Please, check that everything works

Thanks for the update to 1.18.0 @jirfag but this still panics for us in bodyclose as captured here so still unable to use:
https://github.com/golangci/golangci-lint/issues/622
https://github.com/golangci/golangci-lint/issues/608

My issue is resolved with 1.18.0 release. Please update your golangci-lint:

$ curl -sfL "https://install.goreleaser.com/github.com/golangci/golangci-lint.sh" | sh -s -- -b $(go env GOPATH)/bin v1.18.0

Thank you @jirfag !

This issue was not resolved for me by the 1.18.0 release.

@joeblubaugh please more details

Was this page helpful?
0 / 5 - 0 ratings

Related issues

grongor picture grongor  路  4Comments

KeepMasterBranch picture KeepMasterBranch  路  3Comments

rhcarvalho picture rhcarvalho  路  4Comments

ferhatelmas picture ferhatelmas  路  4Comments

DarthHater picture DarthHater  路  4Comments