golangci-lint icon indicating copy to clipboard operation
golangci-lint copied to clipboard

Revive linter has different behavior in linux and macOS

Open juanluisvaladas opened this issue 2 years ago • 3 comments

Welcome

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

Description of the problem

In my dev environment on mac I usually run the linting within docker, which underneath creates a linux VM which runs the containers. However, I tried to run the tests on macOS and got different results

I've managed to reproduce this with both 1.55.1 and 1.55.2. I'm only providing details for 1.55.2 though.

Version of golangci-lint

$ golangci-lint version
golangci-lint has version 1.52.2 built with go1.20.2 from da04413 on 2023-03-23T16:18:48Z

$ docker run --rm -v '<redacted>/go/src/github.com/k0sproject/k0s/build/cache':/run/k0s-build -v '<redacted>/go/src/github.com/k0sproject/k0s':/go/src/github.com/k0sproject/k0s -w /go/src/github.com/k0sproject/k0s -e GOOS -e CGO_ENABLED -e GOARCH --user 504:20 k0sbuild.docker-image.k0s golangci-lint version
golangci-lint has version v1.51.2 built from (unknown, mod sum: "h1:yIcsT1X9ZYHdSpeWXRT1ORC/FPGSqDHbHsu9uk4FK7M=") on (unknown)

The macOS version is acquired from brew and the linux version is compiled with github.com/golangci/golangci-lint/cmd/[email protected]

Configuration file

$ cat .golangci.yml
# options for analysis running
run:
  timeout: 8m

  build-tags:
    - hack
  skip-dirs-use-default: false
  skip-dirs:
    - build
    - docs
    - embedded-bins
    - examples
  skip-files:
    - "zz_*"
  tests: true
  modules-download-mode: readonly
  allow-parallel-runners: true

linters-settings:
  depguard:
    packages:
      - gopkg.in/yaml*
    additional-guards:
      # Only allow usages of the k8s cloud provider from within the k0s cloud
      # provider package. This is to ensure that it's not leaking global flags
      # into k0s.
      - packages:
          - k8s.io/cloud-provider*
        ignore-file-rules:
          - "**/pkg/k0scloudprovider/*.go"
  golint:
    min-confidence: 0
  goheader:
    template-path: .go-header.txt
    values:
      regexp:
        year: 202[0-9]

issues:
  max-issues-per-linter: 0
  max-same-issues: 0
  exclude-rules:
    # https://github.com/denis-tingaikin/go-header/issues/18
    # This means that the header checks are ineffective for all files with build tags.
    - source: "^//go:build"
      linters:
        - goheader
    # Ignore deprecations: They shouldn't break the CI. If this were the case,
    # it would be pointless to have them. There's no way in reporting them as
    # warnings without having a non-zero exit code.
    # https://github.com/golangci/golangci-lint/pull/3184#issuecomment-1235438429
    - linters:
        - staticcheck
      text: "^SA1019:"

Go environment

On macOS I'm deliberately overwriting GOOS to linux to reduce differences macOS:

$  go version
go version go1.20.2 darwin/arm64

$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="<redacted>/Library/Caches/go-build"
GOENV="<redacted>/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="<redacted>/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="<redacted>/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.20.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.2/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="0"
GOMOD="<redacted>/go/src/github.com/k0sproject/k0s/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3q/0qrlpcvj3sb44dx0_t33j7mc0000gr/T/go-build2820157178=/tmp/go-build -gno-record-gcc-switches"

linux:

$ k0s git:(lint-inttest) ✗ docker run --rm -v '<redacted>/go/src/github.com/k0sproject/k0s/build/cache':/run/k0s-build -v '<redacted>/go/src/github.com/k0sproject/k0s':/go/src/github.com/k0sproject/k0s -w /go/src/github.com/k0sproject/k0s -e GOOS -e CGO_ENABLED -e GOARCH --user 504:20 k0sbuild.docker-image.k0s go version
go version go1.20.2 linux/arm64

$ docker run --rm -v '<redacted>/go/src/github.com/k0sproject/k0s/build/cache':/run/k0s-build -v '<redacted>/go/src/github.com/k0sproject/k0s':/go/src/github.com/k0sproject/k0s -w /go/src/github.com/k0sproject/k0s -e GOOS -e CGO_ENABLED -e GOARCH --user 504:20 k0sbuild.docker-image.k0s go env
GO111MODULE=""
GOARCH="arm64"
GOBIN="/run/k0s-build/go/bin"
GOCACHE="/run/k0s-build/go/build"
GOENV="/run/k0s-build/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/run/k0s-build/go/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_arm64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/go/src/github.com/k0sproject/k0s/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1168590696=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

macOS output:

$ golangci-lint cache clean
$ golangci-lint run --disable-all --enable revive --verbose pkg/component/controller/...
INFO [config_reader] Config search paths: [./ <redacted>/go/src/github.com/k0sproject/k0s <redacted>/go/src/github.com/k0sproject <redacted>/go/src/github.com <redacted>/go/src <redacted>/go <redacted> /Users /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 1 linters: [revive]
INFO [loader] Using build tags: [hack]
INFO [loader] Go packages loading at mode 7 (compiled_files|name|files) took 812.343708ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 6.44125ms
INFO [linters_context/goanalysis] analyzers took 2.531204876s with top 10 stages: the_only_name: 2.531204876s
INFO [runner] Issues before processing: 78, after processing: 8
INFO [runner] Processors filtering stat (out/in): source_code: 8/8, severity-rules: 8/8, path_prefixer: 8/8, path_prettifier: 78/78, exclude: 78/78, uniq_by_line: 8/9, max_same_issues: 8/8, fixer: 8/8, sort_results: 8/8, skip_dirs: 78/78, exclude-rules: 9/78, diff: 8/8, max_per_file_from_linter: 8/8, path_shortener: 8/8, autogenerated_exclude: 78/78, nolint: 9/9, skip_files: 78/78, identifier_marker: 78/78, max_from_linter: 8/8, cgo: 78/78, filename_unadjuster: 78/78
INFO [runner] processing took 8.553627ms with stages: autogenerated_exclude: 2.083208ms, nolint: 2.043417ms, exclude-rules: 1.834625ms, path_prettifier: 1.212459ms, identifier_marker: 959.624µs, source_code: 351µs, skip_dirs: 28.625µs, skip_files: 28.459µs, cgo: 5.041µs, uniq_by_line: 1.75µs, filename_unadjuster: 1.708µs, path_shortener: 1.001µs, max_per_file_from_linter: 876ns, max_same_issues: 584ns, fixer: 334ns, exclude: 291ns, max_from_linter: 166ns, severity-rules: 166ns, sort_results: 125ns, path_prefixer: 84ns, diff: 84ns
INFO [runner] linters took 1.417822209s with stages: revive: 1.409211917s
pkg/component/controller/workerconfig/reconciler.go:99:20: unused-parameter: parameter 'k0sVars' seems to be unused, consider removing or renaming it as _ (revive)
func NewReconciler(k0sVars constant.CfgVars, nodeSpec *v1beta1.ClusterSpec, clientFactory kubeutil.ClientFactoryInterface, leaderElector leaderelector.Interface, konnectivityEnabled bool) (*Reconciler, error) {
                   ^
pkg/component/controller/workerconfig/reconciler_test.go:764:3: redefines-builtin-id: redefinition of the built-in function len (revive)
		len := len(*calls)
		^
pkg/component/controller/autopilot.go:41:26: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (a *Autopilot) Init(ctx context.Context) error {
                         ^
pkg/component/controller/k0scloudprovider_test.go:32:28: unused-parameter: parameter 'node' seems to be unused, consider removing or renaming it as _ (revive)
func EmptyAddressCollector(node *v1.Node) []v1.NodeAddress {
                           ^
pkg/component/controller/apiendpointreconciler_test.go:186:37: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (fr fakeResolver) LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error) {
                                    ^
pkg/component/controller/extensions_controller.go:62:74: unused-parameter: parameter 'kubeClientFactory' seems to be unused, consider removing or renaming it as _ (revive)
func NewExtensionsController(s manifestsSaver, k0sVars constant.CfgVars, kubeClientFactory kubeutil.ClientFactoryInterface, leaderElector leaderelector.Interface) *ExtensionsController {
                                                                         ^
pkg/component/controller/extensions_controller.go:77:43: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (ec *ExtensionsController) Reconcile(ctx context.Context, clusterConfig *k0sAPI.ClusterConfig) error {
                                          ^
pkg/component/controller/extensions_controller.go:226:38: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (cr *ChartReconciler) uninstall(ctx context.Context, chart v1beta1.Chart) error {
                                     ^
INFO File cache stats: 6 entries of total size 66.8KiB
INFO Memory: 24 samples, avg is 37.3MB, max is 53.1MB
INFO Execution took 2.244727s

Linux output:


$ docker run --rm -v '<redacted>/go/src/github.com/k0sproject/k0s/build/cache':/run/k0s-build -v '<redacted>/go/src/github.com/k0sproject/k0s':/go/src/github.com/k0sproject/k0s -w /go/src/github.com/k0sproject/k0s -e GOOS -e CGO_ENABLED -e GOARCH --user 504:20 k0sbuild.docker-image.k0s golangci-lint cache clean

$ docker run --rm -v '<redacted>/go/src/github.com/k0sproject/k0s/build/cache':/run/k0s-build -v '<redacted>/go/src/github.com/k0sproject/k0s':/go/src/github.com/k0sproject/k0s -w /go/src/github.com/k0sproject/k0s -e GOOS -e CGO_ENABLED -e GOARCH --user 504:20 k0sbuild.docker-image.k0s golangci-lint run --disable-all --enable revive --verbose pkg/component/controller/...

level=info msg="[config_reader] Config search paths: [./ /go/src/github.com/k0sproject/k0s /go/src/github.com/k0sproject /go/src/github.com /go/src /go / /run/k0s-build]"
level=info msg="[config_reader] Used config file .golangci.yml"
level=info msg="[lintersdb] Active 1 linters: [revive]"
level=info msg="[loader] Using build tags: [hack]"
level=info msg="[loader] Go packages loading at mode 7 (files|name|compiled_files) took 6.579204295s"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 23.76175ms"
level=info msg="[linters_context/goanalysis] analyzers took 6.531471544s with top 10 stages: the_only_name: 6.531471544s"
level=info msg="[runner] Issues before processing: 69, after processing: 0"
level=info msg="[runner] Processors filtering stat (out/in): skip_files: 69/69, autogenerated_exclude: 69/69, identifier_marker: 69/69, cgo: 69/69, filename_unadjuster: 69/69, path_prettifier: 69/69, exclude: 69/69, exclude-rules: 0/69, skip_dirs: 69/69"
level=info msg="[runner] processing took 34.800548ms with stages: path_prettifier: 18.254833ms, autogenerated_exclude: 13.760125ms, exclude-rules: 1.427375ms, identifier_marker: 881.75µs, skip_dirs: 437.792µs, skip_files: 17.375µs, cgo: 9.833µs, filename_unadjuster: 6.959µs, max_same_issues: 1.292µs, nolint: 1.126µs, source_code: 375ns, diff: 334ns, severity-rules: 293ns, exclude: 292ns, uniq_by_line: 251ns, path_shortener: 126ns, max_from_linter: 125ns, sort_results: 125ns, max_per_file_from_linter: 84ns, path_prefixer: 83ns"
level=info msg="[runner] linters took 3.895292294s with stages: revive: 3.860404793s"
level=info msg="File cache stats: 0 entries of total size 0B"
level=info msg="Memory: 107 samples, avg is 29.2MB, max is 52.1MB"
level=info msg="Execution took 10.504905255s"

Code example or link to a public repository

The issue can be easily reproduced in our public repository in a mac with docker:

$ git clone [email protected]:k0sproject/k0s.git
$ cd k0s
$ make lint # This takes a fairly high amount of time
$ golangci-lint run --verbose

The output won't be exactly the same because the .golangci.yml in the repo has more linters than I'm mentioning and here I'm linting less directories so that I can show the minimum reproducible problem.

juanluisvaladas avatar Apr 04 '23 12:04 juanluisvaladas

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

boring-cyborg[bot] avatar Apr 04 '23 12:04 boring-cyborg[bot]

EDIT: Issue can be reviewed now.

juanluisvaladas avatar Apr 04 '23 12:04 juanluisvaladas

i upgrade golangci-lint from 1.51.1 to 1.52.2, also see the unused-parameter warning from revive.

in v1.52.0, revive is bump from 1.2.5 to 1.3.0, which now enables unused-parameter by default https://github.com/mgechev/revive/pull/799.

@juanluisvaladas you are comparing golangci-lint 1.51.2 and 1.52.2, i suspect it's not the difference between linux and macOS, but the versions.

kauruus avatar May 25 '23 11:05 kauruus