Skip to content

Revive linter rules configuration #1745

Closed
@vtvz

Description

@vtvz

Some revive rules are not configurable due to invalid type. You can reproduce the error using these rule config one by one:

- name: cognitive-complexity
  arguments: [ 7 ]
- name: line-length-limit
  arguments: [ 110 ]
- name: function-result-limit
  arguments: [ 3 ]
- name: argument-limit
  arguments: [ 4 ]
- name: cyclomatic
  arguments: [ 10 ]
- name: max-public-structs
  arguments: [ 3 ]

These broken rules are commented in the full config listed below

  • 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).

Please include the following information:

Version of golangci-lint
$ golangci-lint --version
golangci-lint has version 1.37.0 built from 34e5fc63 on 2021-02-17T09:32:37Z
Config file
# cat .golangci.yml
linters-settings:
  dupl:
    threshold: 100
  funlen:
    lines: 100
    statements: 50
  gci:
    local-prefixes: github.com/golangci/golangci-lint
  goconst:
    min-len: 2
    min-occurrences: 2
  gocritic:
    enabled-tags:
      - diagnostic
      - experimental
      - opinionated
      - performance
      - style
    disabled-checks:
      - dupImport # https://github.com/go-critic/go-critic/issues/845
      - ifElseChain
      - octalLiteral
      - whyNoLint
      - wrapperFunc
  gocyclo:
    min-complexity: 15
  goimports:
    local-prefixes: app
  golint:
    min-confidence: 0
  gomnd:
    settings:
      mnd:
        # don't include the "operation" and "assign"
        checks: [ argument,case,condition,return ]
  govet:
    check-shadowing: true
    settings:
      printf:
        funcs:
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
  lll:
    line-length: 140
  maligned:
    suggest-new: true
  misspell:
    locale: US
  nolintlint:
    allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
    allow-unused: false # report any unused nolint directives
    require-explanation: false # don't require an explanation for nolint directives
    require-specific: false # don't require nolint directives to be specific about which linter is being skipped
  revive:
    ignore-generated-header: false
    severity: "warning"
    confidence: 0.8
    error-code: 2
    warning-code: 1
    rules:
      - name: blank-imports
      - name: context-keys-type
      - name: time-naming
      - name: var-declaration
      - name: unexported-return
      - name: errorf
      - name: context-as-argument
      - name: dot-imports
      - name: error-return
      - name: error-strings
      - name: error-naming
      - name: if-return
      - name: increment-decrement
      - name: var-naming
      - name: package-comments
      - name: range
      - name: receiver-naming
      - name: indent-error-flow
      - name: empty-block
      - name: superfluous-else
      - name: confusing-naming
      - name: get-return
      - name: modifies-parameter
      - name: confusing-results
      - name: deep-exit
      - name: unused-parameter
      - name: unreachable-code
      - name: flag-parameter
      - name: unnecessary-stmt
      - name: struct-tag
      - name: modifies-value-receiver
      - name: constant-logical-expr
      - name: bool-literal-in-expr
      - name: redefines-builtin-id
      - name: imports-blacklist
      - name: range-val-in-closure
      - name: range-val-address
      - name: waitgroup-by-value
      - name: atomic
      - name: empty-lines
      - name: call-to-gc
      - name: duplicated-imports
      - name: import-shadowing
      - name: bare-return
      - name: unused-receiver
      - name: unhandled-error
      - name: string-of-int
      - name: defer
        arguments: [ [ "call-chain","loop" ] ]
      - name: unconditional-recursion
      - name: early-return
      - name: identical-branches
      - name: unexported-naming
      # BROKEN RULES ARE COMMENTED
      # - name: cognitive-complexity
      #   arguments: [ 7 ]
      # - name: line-length-limit
      #   arguments: [ 110 ]
      # - name: function-result-limit
      #   arguments: [ 3 ]
      # - name: argument-limit
      #   arguments: [ 4 ]
      # - name: cyclomatic
      #   arguments: [ 10 ]
      # - name: max-public-structs
      #   arguments: [ 3 ]

linters:
  enable:
    - bodyclose
    - deadcode
    - dogsled
    - dupl
    - errcheck
    - exhaustive
    - funlen
    - gochecknoinits
    - goconst
    - gocritic
    - gocyclo
    - gofmt
    - goimports
    - golint
    - gomnd
    - goprintffuncname
    - gosec
    - gosimple
    - govet
    - ineffassign
    - interfacer
    - lll
    - misspell
    - nakedret
    - noctx
    - nolintlint
    - revive
    - rowserrcheck
    - scopelint
    - staticcheck
    - structcheck
    - stylecheck
    - typecheck
    - unconvert
    - unparam
    - unused
    - varcheck
    - whitespace

  # don't enable:
  # - asciicheck
  # - gochecknoglobals
  # - gocognit
  # - godot
  # - godox
  # - goerr113
  # - maligned
  # - nestif
  # - prealloc
  # - testpackage
  # - wsl

issues:
  # Excluding configuration per-path, per-linter, per-text and per-source
  exclude-rules:
    - path: _test\.go
      linters:
        - gomnd

    # https://github.com/go-critic/go-critic/issues/926
    - linters:
        - gocritic
      text: "unnecessaryDefer:"

    # TODO temporary rule, must be removed
    # seems related to v0.34.1, but I was not able to reproduce locally,
    # I was also not able to reproduce in the CI of a fork,
    # only the golangci-lint CI seems to be affected by this invalid analysis.
    - path: pkg/golinters/scopelint.go
      text: 'directive `//nolint:interfacer` is unused for linter interfacer'
Go environment
$ go version && go env
go version go1.16 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/terraform/.meta/go/gocache"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/terraform/.meta/go/gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/terraform/.meta/go/gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="0"
GOMOD="/dev/null"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2190622253=/tmp/go-build -gno-record-gcc-switches"
Verbose output of running

With - { name: cognitive-complexity, arguments: [ 7 ] } enabled

$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /terraform/test /terraform / /home/user] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 38 linters: [bodyclose deadcode dogsled dupl errcheck exhaustive funlen gochecknoinits goconst gocritic gocyclo gofmt goimports golint gomnd goprintffuncname gosec gosimple govet ineffassign interfacer lll misspell nakedret noctx nolintlint revive rowserrcheck scopelint staticcheck structcheck stylecheck typecheck unconvert unparam unused varcheck whitespace] 
INFO [loader] Go packages loading at mode 575 (deps|exports_file|compiled_files|imports|name|types_sizes|files) took 214.027035ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 346.369µs 
panic: invalid argument type for cognitive-complexity, expected int64, got int

goroutine 3741 [running]:
github.com/mgechev/revive/rule.(*CognitiveComplexityRule).Apply(0x167f6e0, 0xc01216aac0, 0xc0007a2700, 0x1, 0x1, 0x167f6e0, 0x0, 0x0)
        github.com/mgechev/revive@v1.0.3/rule/cognitive-complexity.go:25 +0x15f
github.com/mgechev/revive/lint.(*File).lint(0xc01216aac0, 0xc009ea7400, 0x35, 0x40, 0x0, 0x3fe999999999999a, 0xc000449e10, 0x7, 0xc00ef7eea0, 0x2, ...)
        github.com/mgechev/revive@v1.0.3/lint/file.go:108 +0x378
github.com/mgechev/revive/lint.(*Package).lint.func1(0xc009ea7400, 0x35, 0x40, 0x0, 0x3fe999999999999a, 0xc000449e10, 0x7, 0xc00ef7eea0, 0x2, 0x1, ...)
        github.com/mgechev/revive@v1.0.3/lint/package.go:173 +0xb5
created by github.com/mgechev/revive/lint.(*Package).lint
        github.com/mgechev/revive@v1.0.3/lint/package.go:172 +0x185

With - {name: line-length-limit, arguments: [ 110 ]} enabled

INFO [config_reader] Config search paths: [./ /terraform/test /terraform / /home/user] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 38 linters: [bodyclose deadcode dogsled dupl errcheck exhaustive funlen gochecknoinits goconst gocritic gocyclo gofmt goimports golint gomnd goprintffuncname gosec gosimple govet ineffassign interfacer lll misspell nakedret noctx nolintlint revive rowserrcheck scopelint staticcheck structcheck stylecheck typecheck unconvert unparam unused varcheck whitespace] 
INFO [loader] Go packages loading at mode 575 (files|deps|exports_file|imports|name|types_sizes|compiled_files) took 210.423617ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 366.745µs 
panic: invalid value passed as argument number to the "line-length-limit" rule

goroutine 3401 [running]:
github.com/mgechev/revive/rule.(*LineLengthLimitRule).Apply(0x167f6e0, 0xc00096a1c0, 0xc0003db680, 0x1, 0x1, 0x167f6e0, 0x0, 0x0)
        github.com/mgechev/revive@v1.0.3/rule/line-length-limit.go:25 +0x107
github.com/mgechev/revive/lint.(*File).lint(0xc00096a1c0, 0xc00017f800, 0x35, 0x40, 0x0, 0x3fe999999999999a, 0xc0005c4fa0, 0x7, 0xc004bce030, 0x2, ...)
        github.com/mgechev/revive@v1.0.3/lint/file.go:108 +0x378
github.com/mgechev/revive/lint.(*Package).lint.func1(0xc00017f800, 0x35, 0x40, 0x0, 0x3fe999999999999a, 0xc0005c4fa0, 0x7, 0xc004bce030, 0x2, 0x1, ...)
        github.com/mgechev/revive@v1.0.3/lint/package.go:173 +0xb5
created by github.com/mgechev/revive/lint.(*Package).lint
        github.com/mgechev/revive@v1.0.3/lint/package.go:172 +0x185

With - {name: function-result-limit, arguments: [ 3 ]} enabled

INFO [config_reader] Config search paths: [./ /terraform/test /terraform / /home/user] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 38 linters: [bodyclose deadcode dogsled dupl errcheck exhaustive funlen gochecknoinits goconst gocritic gocyclo gofmt goimports golint gomnd goprintffuncname gosec gosimple govet ineffassign interfacer lll misspell nakedret noctx nolintlint revive rowserrcheck scopelint staticcheck structcheck stylecheck typecheck unconvert unparam unused varcheck whitespace] 
INFO [loader] Go packages loading at mode 575 (files|name|types_sizes|compiled_files|deps|exports_file|imports) took 206.970753ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 340.791µs 
panic: invalid value passed as return results number to the "function-result-limit" rule; need int64 but got int

goroutine 3777 [running]:
github.com/mgechev/revive/rule.(*FunctionResultsLimitRule).Apply(0x167f6e0, 0xc027225340, 0xc00098cb10, 0x1, 0x1, 0x167f6e0, 0x0, 0x0)
        github.com/mgechev/revive@v1.0.3/rule/function-result-limit.go:21 +0x20b
github.com/mgechev/revive/lint.(*File).lint(0xc027225340, 0xc02722c000, 0x35, 0x40, 0x0, 0x3fe999999999999a, 0xc0002a3fe0, 0x7, 0xc02721b5c0, 0x2, ...)
        github.com/mgechev/revive@v1.0.3/lint/file.go:108 +0x378
github.com/mgechev/revive/lint.(*Package).lint.func1(0xc02722c000, 0x35, 0x40, 0x0, 0x3fe999999999999a, 0xc0002a3fe0, 0x7, 0xc02721b5c0, 0x2, 0x1, ...)
        github.com/mgechev/revive@v1.0.3/lint/package.go:173 +0xb5
created by github.com/mgechev/revive/lint.(*Package).lint
        github.com/mgechev/revive@v1.0.3/lint/package.go:172 +0x185

With - {name: argument-limit, arguments: [ 4 ]} enabled

INFO [config_reader] Config search paths: [./ /terraform/test /terraform / /home/user] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 38 linters: [bodyclose deadcode dogsled dupl errcheck exhaustive funlen gochecknoinits goconst gocritic gocyclo gofmt goimports golint gomnd goprintffuncname gosec gosimple govet ineffassign interfacer lll misspell nakedret noctx nolintlint revive rowserrcheck scopelint staticcheck structcheck stylecheck typecheck unconvert unparam unused varcheck whitespace] 
INFO [loader] Go packages loading at mode 575 (files|imports|name|compiled_files|deps|exports_file|types_sizes) took 247.290096ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 343.924µs 
panic: invalid value passed as argument number to the "argument-list" rule

goroutine 3752 [running]:
github.com/mgechev/revive/rule.(*ArgumentsLimitRule).Apply(0x167f6e0, 0xc027a5d980, 0xc000647450, 0x1, 0x1, 0x167f6e0, 0x0, 0x0)
        github.com/mgechev/revive@v1.0.3/rule/argument-limit.go:21 +0x165
github.com/mgechev/revive/lint.(*File).lint(0xc027a5d980, 0xc022b8c400, 0x35, 0x40, 0x0, 0x3fe999999999999a, 0xc0001cda40, 0x7, 0xc00bdf12f0, 0x2, ...)
        github.com/mgechev/revive@v1.0.3/lint/file.go:108 +0x378
github.com/mgechev/revive/lint.(*Package).lint.func1(0xc022b8c400, 0x35, 0x40, 0x0, 0x3fe999999999999a, 0xc0001cda40, 0x7, 0xc00bdf12f0, 0x2, 0x1, ...)
        github.com/mgechev/revive@v1.0.3/lint/package.go:173 +0xb5
created by github.com/mgechev/revive/lint.(*Package).lint
        github.com/mgechev/revive@v1.0.3/lint/package.go:172 +0x185

With - {name: cyclomatic, arguments: [ 10 ]} enabled

INFO [config_reader] Config search paths: [./ /terraform/test /terraform / /home/user] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 38 linters: [bodyclose deadcode dogsled dupl errcheck exhaustive funlen gochecknoinits goconst gocritic gocyclo gofmt goimports golint gomnd goprintffuncname gosec gosimple govet ineffassign interfacer lll misspell nakedret noctx nolintlint revive rowserrcheck scopelint staticcheck structcheck stylecheck typecheck unconvert unparam unused varcheck whitespace] 
INFO [loader] Go packages loading at mode 575 (compiled_files|deps|files|name|types_sizes|exports_file|imports) took 217.868064ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 379.115µs 
panic: invalid argument for cyclomatic complexity

goroutine 3495 [running]:
github.com/mgechev/revive/rule.(*CyclomaticRule).Apply(0x167f6e0, 0xc005ad3540, 0xc00058c730, 0x1, 0x1, 0x167f6e0, 0x0, 0x0)
        github.com/mgechev/revive@v1.0.3/rule/cyclomatic.go:22 +0x17b
github.com/mgechev/revive/lint.(*File).lint(0xc005ad3540, 0xc00d4d5000, 0x35, 0x40, 0x0, 0x3fe999999999999a, 0xc0001afed0, 0x7, 0xc005224300, 0x2, ...)
        github.com/mgechev/revive@v1.0.3/lint/file.go:108 +0x378
github.com/mgechev/revive/lint.(*Package).lint.func1(0xc00d4d5000, 0x35, 0x40, 0x0, 0x3fe999999999999a, 0xc0001afed0, 0x7, 0xc005224300, 0x2, 0x1, ...)
        github.com/mgechev/revive@v1.0.3/lint/package.go:173 +0xb5
created by github.com/mgechev/revive/lint.(*Package).lint
        github.com/mgechev/revive@v1.0.3/lint/package.go:172 +0x185

With - {name: max-public-structs, arguments: [ 3 ]} enabled

INFO [config_reader] Config search paths: [./ /terraform/test /terraform / /home/user] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 38 linters: [bodyclose deadcode dogsled dupl errcheck exhaustive funlen gochecknoinits goconst gocritic gocyclo gofmt goimports golint gomnd goprintffuncname gosec gosimple govet ineffassign interfacer lll misspell nakedret noctx nolintlint revive rowserrcheck scopelint staticcheck structcheck stylecheck typecheck unconvert unparam unused varcheck whitespace] 
INFO [loader] Go packages loading at mode 575 (name|types_sizes|deps|exports_file|files|imports|compiled_files) took 211.412993ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 622.966µs 
panic: invalid value passed as argument number to the "max-public-structs" rule

goroutine 3400 [running]:
github.com/mgechev/revive/rule.(*MaxPublicStructsRule).Apply(0x167f6e0, 0xc004a056c0, 0xc000745ed0, 0x1, 0x1, 0x167f6e0, 0x0, 0x0)
        github.com/mgechev/revive@v1.0.3/rule/max-public-structs.go:30 +0x2b7
github.com/mgechev/revive/lint.(*File).lint(0xc004a056c0, 0xc00eef2800, 0x35, 0x40, 0x0, 0x3fe999999999999a, 0xc000480fb0, 0x7, 0xc00ff85260, 0x2, ...)
        github.com/mgechev/revive@v1.0.3/lint/file.go:108 +0x378
github.com/mgechev/revive/lint.(*Package).lint.func1(0xc00eef2800, 0x35, 0x40, 0x0, 0x3fe999999999999a, 0xc000480fb0, 0x7, 0xc00ff85260, 0x2, 0x1, ...)
        github.com/mgechev/revive@v1.0.3/lint/package.go:173 +0xb5
created by github.com/mgechev/revive/lint.(*Package).lint
        github.com/mgechev/revive@v1.0.3/lint/package.go:172 +0x185

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions