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

revive: Invalid argument to the context-as-argument rule. Unrecognized key allowtypesbefore #3280

Open
4 tasks done
pmalek opened this issue Oct 6, 2022 · 4 comments
Open
4 tasks done
Labels
bug Something isn't working dependencies Relates to an upstream dependency

Comments

@pmalek
Copy link

pmalek commented Oct 6, 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

It seems that golangci-lint (starting with v1.50?) passes the arguments to linters in lower case and not "as is".

This causes in our cases panic in revive

panic: Invalid argument to the context-as-argument rule. Unrecognized key allowtypesbefore

goroutine 3957 [running]:
github.com/mgechev/revive/rule.getAllowTypesFromArguments({0xc002f5eb30?, 0x0?, 0x0?})
	/home/runner/go/pkg/mod/github.com/mgechev/revive@v1.2.4/rule/context-as-argument.go:98 +0x379
github.com/mgechev/revive/rule.(*ContextAsArgumentRule).Apply(0x22a5ac0, 0xc00146e300, {0xc002f5eb30?, 0x13?, 0x90a6c696e203d00?})
	/home/runner/go/pkg/mod/github.com/mgechev/revive@v1.2.4/rule/context-as-argument.go:22 +0xa5
github.com/mgechev/revive/lint.(*File).lint(0xc00146e300, {0xc002f5ec50, 0x1, 0x1}, {0x0, 0x3fe999999999999a, {0x16cc8c0, 0x7}, 0x0, 0xc002f5ab70, ...}, ...)
	/home/runner/go/pkg/mod/github.com/mgechev/revive@v1.2.4/lint/file.go:105 +0x19b
github.com/mgechev/revive/lint.(*Package).lint.func1(0xc002b82480?)
	/home/runner/go/pkg/mod/github.com/mgechev/revive@v1.2.4/lint/package.go:185 +0x85
created by github.com/mgechev/revive/lint.(*Package).lint
	/home/runner/go/pkg/mod/github.com/mgechev/revive@v1.2.4/lint/package.go:184 +0xac

which can be tracked down to: https://github.com/mgechev/revive/blob/v1.2.4/rule/context-as-argument.go#L82-L110.

The same config with the same code base works fine with v1.49

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version v1.50.0 built from (unknown, mod sum: "h1:+Xmyt8rKLauNLp2gzcxKMN8VNGqGc5Avc2ZLTwIOpEA=") on (unknown)

Configuration file

$ cat .golangci.yml
run:
  timeout: 5m
linters:
  enable:
  - revive
linters-settings:
  revive:
    rules:
      - name: context-as-argument
        arguments:
          - "allowTypesBefore": "*testing.T"
issues:
  fix: true

Go environment

$ go version && go env
go version go1.19.2 darwin/arm64
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/USER/Library/Caches/go-build"
GOENV="/Users/USER/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/USER/.gvm/pkgsets/go1.19.2/global/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/USER/.gvm/pkgsets/go1.19.2/global"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/USER/.gvm/gos/go1.19.2"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/USER/.gvm/gos/go1.19.2/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/USER/code_/gateway-operator/go.mod"
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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0m/_63w01516tgf3cftmp9h7ylm0000gn/T/go-build2415445190=/tmp/go-build -gno-record-gcc-switches -fno-common"

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
/Users/USER/code_/gateway-operator/bin/golangci-lint run -v
level=info msg="[config_reader] Config search paths: [./ /Users/USER/code_/gateway-operator /Users/USER/code_ /Users/USER /Users /]"
level=info msg="[config_reader] Used config file .golangci.yaml"
level=info msg="[lintersdb] Active 28 linters: [asciicheck bodyclose depguard dogsled durationcheck errcheck errorlint exhaustive exportloopref gci gofmt goimports gosec gosimple govet importas ineffassign misspell nilerr nolintlint predeclared revive staticcheck typecheck unconvert unparam unused wastedassign]"
level=info msg="[loader] Using build tags: [integration_tests e2e_tests]"
level=info msg="[loader] Go packages loading at mode 575 (types_sizes|compiled_files|deps|exports_file|files|name|imports) took 325.019583ms"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 6.31625ms"
panic: Invalid argument to the context-as-argument rule. Unrecognized key allowtypesbefore

goroutine 3381 [running]:
github.com/mgechev/revive/rule.getAllowTypesFromArguments({0x140040fcd70?, 0x0?, 0x0?})
        /Users/USER/.gvm/pkgsets/go1.19.2/global/pkg/mod/github.com/mgechev/revive@v1.2.4/rule/context-as-argument.go:98 +0x34c
github.com/mgechev/revive/rule.(*ContextAsArgumentRule).Apply(0x102513350, 0x14000ee4480, {0x140040fcd70?, 0x13?, 0x72616e552e637000?})
        /Users/USER/.gvm/pkgsets/go1.19.2/global/pkg/mod/github.com/mgechev/revive@v1.2.4/rule/context-as-argument.go:22 +0xe0
github.com/mgechev/revive/lint.(*File).lint(0x14000ee4480, {0x140040fce70, 0x1, 0x1}, {0x0, 0x3fe999999999999a, {0x1016d7002, 0x7}, 0x0, 0x14002836570, ...}, ...)
        /Users/USER/.gvm/pkgsets/go1.19.2/global/pkg/mod/github.com/mgechev/revive@v1.2.4/lint/file.go:105 +0x15c
github.com/mgechev/revive/lint.(*Package).lint.func1(0x14004d4a170?)
        /Users/USER/.gvm/pkgsets/go1.19.2/global/pkg/mod/github.com/mgechev/revive@v1.2.4/lint/package.go:185 +0x70
created by github.com/mgechev/revive/lint.(*Package).lint
        /Users/USER/.gvm/pkgsets/go1.19.2/global/pkg/mod/github.com/mgechev/revive@v1.2.4/lint/package.go:184 +0xa8

Code example or link to a public repository

// add your code here
@pmalek pmalek added the bug Something isn't working label Oct 6, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 6, 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 Oct 7, 2022

Hello,

[x] Yes, I've tried with the standalone linter if available

As you have checked this, can you give me the output of the revive command line?

@ldez ldez added the feedback required Requires additional feedback label Oct 7, 2022
@pmalek
Copy link
Author

pmalek commented Oct 7, 2022

Hello,

[x] Yes, I've tried with the standalone linter if available

As you have checked this, can you give me the output of the revive command line?

Sure,

revive -config revive.toml ./...

With the following config:

[rule.context-as-argument]
  arguments = [{allowTypesBefore = "*testing.T"}]

as taken from here: https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-as-argument

@ldez
Copy link
Member

ldez commented Oct 7, 2022

It's related to github.com/spf13/viper@v1.13.0 (#3205)

spf13/viper#1387

So it's a breaking change inside Viper introduced by a bug fix, the new behavior will not change because it's the expected behavior from the Viper point of view, but it's a major problem for us.

spf13/viper#1431

EDIT: I reverted the update of Viper #3284 (golangci-lint v1.50.1)

@ldez ldez removed the feedback required Requires additional feedback label Oct 7, 2022
MadVikingGod added a commit to MadVikingGod/opentelemetry-go-contrib that referenced this issue Oct 20, 2022
This is currently incompatible with viper v1.13.0. Status for the linter found at
golangci/golangci-lint#3280
MadVikingGod added a commit to MadVikingGod/opentelemetry-go that referenced this issue Oct 20, 2022
This is currently incompatible with viper v1.13.0. Status for the linter found at
golangci/golangci-lint#3280
MrAlias pushed a commit to open-telemetry/opentelemetry-go that referenced this issue Nov 3, 2022
This is currently incompatible with viper v1.13.0. Status for the linter found at
golangci/golangci-lint#3280
NullBrotasli added a commit to NullBrotasli/opentelemetry-go that referenced this issue Nov 14, 2022
This is currently incompatible with viper v1.13.0. Status for the linter found at
golangci/golangci-lint#3280
MrAlias added a commit to open-telemetry/opentelemetry-go-contrib that referenced this issue Feb 27, 2023
This is currently incompatible with viper v1.13.0. Status for the linter found at
golangci/golangci-lint#3280

Co-authored-by: Tyler Yahn <codingalias@gmail.com>
@ldez ldez added the dependencies Relates to an upstream dependency label Jun 2, 2024
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

2 participants