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 linter rules configuration #1745

Closed
3 tasks done
vtvz opened this issue Feb 18, 2021 · 3 comments · Fixed by #1747
Closed
3 tasks done

Revive linter rules configuration #1745

vtvz opened this issue Feb 18, 2021 · 3 comments · Fixed by #1747
Assignees
Labels
bug Something isn't working

Comments

@vtvz
Copy link

vtvz commented Feb 18, 2021

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
@vtvz vtvz added the bug Something isn't working label Feb 18, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 18, 2021

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

@jpreese
Copy link
Member

jpreese commented Feb 18, 2021

Additional suggestion for gorevive rules configuration:

I just tried using this linter and noticed that if you specify a rules: block at all, the golanglint-ci will only use the set you gave it. In my case, I'd like to use all the defaults, except add some exceptions for Id vs ID in var-naming. But to do so would require adding in all of the other rules explicitly.

The alternative would be to add an issue exclusion in exclude-rules for golanglint-ci itself, but I don't see a way to exclude these errors specifically.

@ldez
Copy link
Member

ldez commented Feb 18, 2021

I created a fix (#1747) for the wrong types and the default rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants