Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with gomoddirectives using Go 1.18 and multi-module setup #2752

Closed
4 tasks done
vendion opened this issue Apr 9, 2022 · 5 comments
Closed
4 tasks done

Problem with gomoddirectives using Go 1.18 and multi-module setup #2752

vendion opened this issue Apr 9, 2022 · 5 comments
Assignees
Labels
bug Something isn't working dependencies Relates to an upstream dependency

Comments

@vendion
Copy link

vendion commented Apr 9, 2022

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

After upgrading to Go 1.18 and converting my project to a multi-module repo I get the following warning when trying to do golang-lint run ./... on my project.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.45.2 built from 8bdc4d3 on 2022-03-25T14:09:43Z

Configuration file

$ cat .golangci.toml
[run]
timeout = "5m"
deadline = "5m"

[linters-settings]

[linters-settings.govet]
check-shadowing = true

[linters-settings.gocyclo]
min-complexity = 12.0

[linters-settings.goconst]
min-len = 3.0
min-occurrences = 3.0

[linters-settings.misspell]
locale = "US"

[linters-settings.goimports]
local-prefixes = "Utiliflex/light"

[linters-settings.gofumpt]
lang-version = "1.18"
module-path = "Utiliflex/light"

[linters-settings.gosimple]
go = "1.18"

[linters-settings.goheader]

[linters]
enable-all = true
disable = [
"maligned",
"scopelint",
"gomnd",
"goconst",
"godox",
"nestif",
"gci",
"interfacer",
"paralleltest",
"tagliatelle",
"varnamelen",
"golint",
"containedctx"
]

[issues]
exclude-use-default = false
max-per-linter = 0
max-same-issues = 0
exclude = []
fix = true

[[issues.exclude-rules]]
path = "sts6/cmd/vend_test.go"
text = "package should be `cmd_test` instead of `cmd`"

[[issues.exclude-rules]]
path = "sts6/cmd/vend.go"
text = "assignOp: replace `m = m & 0x3fff` with `m &= 0x3fff`"

[[issues.exclude-rules]]
path = "_test.go"
linters = ["testpackage", "exhaustivestruct"]

[[issues.exclude-rules]]
path = "main_test.go"
text = "`(TestSerialEmpty|TestSerialReport)` - `t` is unused"

Go environment

$ go version && go env
go version go1.18 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vendion/.cache/go-build"
GOENV="/home/vendion/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/vendion/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/vendion/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3125924384=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /home/vendion/work/Light-STS6/src /home/vendion/work/Light-STS6 /home/vendion/work /home/vendion /home /]
INFO [config_reader] Used config file .golangci.toml
INFO [lintersdb] Active 75 linters: [asciicheck bidichk bodyclose contextcheck cyclop deadcode decorder depguard dogsled dupl durationcheck errcheck errchkjson errname errorlint exhaustive exhaustivestruct exportloopref forbidigo forcetypeassert funlen gochecknoglobals gochecknoinits gocognit gocritic gocyclo godot goerr113 gofmt gofumpt goheader goimports gomoddirectives gomodguard goprintffuncname gosec gosimple govet grouper ifshort importas ineffassign ireturn lll maintidx makezero misspell nakedret nilerr nilnil nlreturn noctx nolintlint prealloc predeclared promlinter revive rowserrcheck sqlclosecheck staticcheck structcheck stylecheck tenv testpackage thelper tparallel typecheck unconvert unparam unused varcheck wastedassign whitespace wrapcheck wsl]
INFO [loader] Go packages loading at mode 575 (deps|files|types_sizes|compiled_files|exports_file|imports|name) took 205.530148ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 3.160349ms
INFO [linters context] importas settings found, but no aliases listed. List aliases under alias: key.
WARN [linters context] running gomoddirectives failed: failed to get module file: unmarshaling error: invalid character '{' after top-level value: {
"Path": "Utiliflex/light",
"Main": true,
"Dir": "/home/vendion/work/Light-STS6/src",
"GoMod": "/home/vendion/work/Light-STS6/src/go.mod",
"GoVersion": "1.18"
}
{
"Path": "Utiliflex/light/light-keyprn",
"Main": true,
"Dir": "/home/vendion/work/Light-STS6/src/keyprn",
"GoMod": "/home/vendion/work/Light-STS6/src/keyprn/go.mod",
"GoVersion": "1.18"
}
{
"Path": "Utiliflex/light/light-keyreq",
"Main": true,
"Dir": "/home/vendion/work/Light-STS6/src/keyreq",
"GoMod": "/home/vendion/work/Light-STS6/src/keyreq/go.mod",
"GoVersion": "1.18"
}
{
"Path": "Utiliflex/light/light-license",
"Main": true,
"Dir": "/home/vendion/work/Light-STS6/src/license",
"GoMod": "/home/vendion/work/Light-STS6/src/license/go.mod",
"GoVersion": "1.18"
}
{
"Path": "Utiliflex/light/light-load",
"Main": true,
"Dir": "/home/vendion/work/Light-STS6/src/load",
"GoMod": "/home/vendion/work/Light-STS6/src/load/go.mod",
"GoVersion": "1.18"
}
: if you are not using go modules it is suggested to disable this linter
INFO [linters context/goanalysis] analyzers took 17.014560914s with top 10 stages: buildir: 6.667148938s, exhaustive: 1.077890746s, the_only_name: 460.508768ms, bidichk: 423.732207ms, buildssa: 419.413098ms, wastedassign: 401.651745ms, inspect: 370.409402ms, nilness: 345.133345ms, ctrlflow: 340.908923ms, printf: 340.622257ms
INFO [runner] Issues before processing: 259, after processing: 0
INFO [runner] Processors filtering stat (out/in): filename_unadjuster: 259/259, skip_dirs: 259/259, exclude: 259/259, autogenerated_exclude: 259/259, identifier_marker: 259/259, exclude-rules: 226/259, nolint: 0/226, cgo: 259/259, path_prettifier: 259/259,skip_files: 259/259
INFO [runner] processing took 13.756902ms with stages: nolint: 6.362732ms, identifier_marker: 5.462864ms, exclude-rules: 1.028677ms, path_prettifier: 434.817µs, autogenerated_exclude: 347.778µs, skip_dirs: 71.913µs, cgo: 29.15µs, filename_unadjuster: 14.324µs, max_same_issues: 1.197µs, source_code: 722ns, uniq_by_line: 425ns, skip_files: 365ns, max_from_linter: 364ns, diff: 312ns, max_per_file_from_linter: 235ns, exclude: 234ns, severity-rules: 229ns, sort_results: 228ns, path_shortener: 208ns, path_prefixer: 128ns
INFO [runner] linters took 3.241932537s with stages: goanalysis_metalinter: 3.227829196s
INFO fixer took 0s with no stages
INFO File cache stats: 24 entries of total size 64.9KiB
INFO Memory: 36 samples, avg is 325.7MB, max is 512.4MB
INFO Execution took 3.45831862s

Code example or link to a public repository

// add your code here
@vendion vendion added the bug Something isn't working label Apr 9, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 9, 2022

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez
Copy link
Member

ldez commented Apr 9, 2022

Hello,

I created a directory tree based on your log and your configuration, but I don't reproduce your problem.

.
├── .golangci.toml
├── go.mod
├── keyprn
│   └── go.mod
├── keyreq
│   └── go.mod
├── license
│   └── go.mod
├── load
│   └── go.mod
└── main.go
$ go version          
go version go1.18 linux/amd64
$ golangci-lint version
golangci-lint has version 1.45.2 built from 8bdc4d3f on 2022-03-24T11:51:26Z
$ golangci-lint run -v                              
INFO [config_reader] Config search paths: [./ /home/ldez/sources/experimental/golangci /home/ldez/sources/experimental /home/ldez/sources /home/ldez /home /] 
INFO [config_reader] Used config file .golangci.toml 
INFO [lintersdb] Active 75 linters: [asciicheck bidichk bodyclose contextcheck cyclop deadcode decorder depguard dogsled dupl durationcheck errcheck errchkjson errname errorlint exhaustive exhaustivestruct exportloopref forbidigo forcetypeassert funlen gochecknoglobals gochecknoinits gocognit gocritic gocyclo godot goerr113 gofmt gofumpt goheader goimports gomoddirectives gomodguard goprintffuncname gosec gosimple govet grouper ifshort importas ineffassign ireturn lll maintidx makezero misspell nakedret nilerr nilnil nlreturn noctx nolintlint prealloc predeclared promlinter revive rowserrcheck sqlclosecheck staticcheck structcheck stylecheck tenv testpackage thelper tparallel typecheck unconvert unparam unused varcheck wastedassign whitespace wrapcheck wsl] 
INFO [loader] Go packages loading at mode 575 (files|name|compiled_files|deps|exports_file|imports|types_sizes) took 84.422958ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 92.734µs 
WARN [linters context] bodyclose is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
WARN [linters context] contextcheck is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
INFO [linters context] importas settings found, but no aliases listed. List aliases under alias: key. 
INFO [linters context/goanalysis] analyzers took 0s with no stages 
WARN [linters context] gosimple is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
WARN [linters context] nilerr is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
WARN [linters context] noctx is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
WARN [linters context] rowserrcheck is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
WARN [linters context] sqlclosecheck is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
WARN [linters context] staticcheck is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
WARN [linters context] structcheck is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
WARN [linters context] stylecheck is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
WARN [linters context] tparallel is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
WARN [linters context] unparam is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
WARN [linters context] wastedassign is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
WARN [linters context] unused is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
INFO [runner] Processors filtering stat (out/in): autogenerated_exclude: 1/1, max_per_file_from_linter: 1/1, max_from_linter: 1/1, source_code: 1/1, cgo: 1/1, skip_dirs: 1/1, exclude-rules: 1/1, path_shortener: 1/1, path_prefixer: 1/1, filename_unadjuster: 1/1, uniq_by_line: 1/1, diff: 1/1, max_same_issues: 1/1, sort_results: 1/1, path_prettifier: 1/1, skip_files: 1/1, identifier_marker: 1/1, exclude: 1/1, nolint: 1/1, severity-rules: 1/1 
INFO [runner] processing took 147.173µs with stages: identifier_marker: 43.152µs, path_prettifier: 28.435µs, nolint: 27.906µs, autogenerated_exclude: 17.009µs, source_code: 11.288µs, skip_dirs: 6.524µs, exclude-rules: 6.087µs, uniq_by_line: 1.114µs, cgo: 1.031µs, max_from_linter: 922ns, path_shortener: 797ns, filename_unadjuster: 628ns, max_per_file_from_linter: 521ns, max_same_issues: 476ns, skip_files: 389ns, exclude: 278ns, severity-rules: 210ns, diff: 189ns, sort_results: 124ns, path_prefixer: 93ns 
INFO [runner] linters took 90.744789ms with stages: goanalysis_metalinter: 90.396075ms, structcheck: 26.643µs, stylecheck: 25.653µs, unparam: 23.117µs, bodyclose: 11.57µs, tparallel: 7.828µs, wastedassign: 7.049µs, gosimple: 6.766µs, unused: 6.366µs, staticcheck: 5.97µs, contextcheck: 5.413µs, noctx: 4.006µs, nilerr: 3.932µs, rowserrcheck: 3.751µs, sqlclosecheck: 3.677µs 
INFO fixer took 0s with no stages                 
main.go:6:2: use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
        fmt.Println("Hello")
        ^
INFO File cache stats: 1 entries of total size 66B 
INFO Memory: 3 samples, avg is 50.2MB, max is 53.0MB 
INFO Execution took 181.724714ms  

can you provide an example? (at least a files tree and go.mod files content)

@ldez ldez added the feedback required Requires additional feedback label Apr 9, 2022
@gnuletik
Copy link
Contributor

I'm also having this error while running golangci-lint on CI but can't reproduce it locally (I tried running go clean -modcache but it doesn't help reproducing the issue).

I'm using a go.work file at the root of my repo.

@gnuletik
Copy link
Contributor

OK, a golangci-lint cache clean helped reproducing.

Here is a repo to reproduce

git clone https://github.com/gnuletik/gomoddirectives-repro
cd gomoddirectives-repro/
bash -c 'cd hello && golangci-lint cache clean && golangci-lint run --config ../.golangci-lint.yml'

It should show a warning:

WARN [linters context] running gomoddirectives failed: failed to get module file: unmarshaling error: invalid character '{' after top-level value: {
	"Path": "example.com/hello",
	"Main": true,
	"Dir": "/tmp/gomoddirectives-repro/hello",
	"GoMod": "/tmp/gomoddirectives-repro/hello/go.mod",
	"GoVersion": "1.18"
}
{
	"Path": "example.com/pkg",
	"Main": true,
	"Dir": "/tmp/gomoddirectives-repro/pkg",
	"GoMod": "/tmp/gomoddirectives-repro/pkg/go.mod",
	"GoVersion": "1.18"
}
: if you are not using go modules it is suggested to disable this linter

@ldez ldez self-assigned this Apr 25, 2022
@ldez ldez added dependencies Relates to an upstream dependency and removed feedback required Requires additional feedback labels Apr 25, 2022
@ldez
Copy link
Member

ldez commented Apr 25, 2022

Problem fixed by v0.2.3.
The update of the linter will be done automatically at the end of the week.

@ldez ldez closed this as completed Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Relates to an upstream dependency
Projects
None yet
Development

No branches or pull requests

3 participants