Skip to content

revive: rules's severity config has no effect #3111

New issue

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

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

Already on GitHub? # to your account

Closed
4 tasks done
hbollon opened this issue Aug 18, 2022 · 6 comments · Fixed by #4452 or #4472
Closed
4 tasks done

revive: rules's severity config has no effect #3111

hbollon opened this issue Aug 18, 2022 · 6 comments · Fixed by #4452 or #4472
Labels
area: severity dependencies Relates to an upstream dependency

Comments

@hbollon
Copy link

hbollon commented Aug 18, 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

I tried to configure specific severity for some revive's rules but they are completely ignored.
I tried with revive directly and it works perfectly with this config file:

#  When set to false, ignores files with "GENERATED" header, similar to golint
ignoreGeneratedHeader = true

# Sets the default severity to "warning"
severity = "error"

# Sets the default failure confidence. This means that linting errors
# with less than 0.8 confidence will be ignored.
confidence = 0.8

# Sets the error code for failures with severity "error"
errorCode = 0

# Sets the error code for failures with severity "warning"
warningCode = 0

# Configuration of the `cyclomatic` rule. Here we specify that
# the rule should fail if it detects code with higher complexity than 10.
[rule.var-naming]
  severity = "warning"

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.48.0 built from 2d8fea81 on 2022-08-04T18:44:38Z

Configuration file

# Golangci-lint documentation: https://golangci-lint.run/

# Analysis running options
run:
  # Timeout for analysis
  timeout: 5m

  # Disable tests to avoid redundancy with test workflow
  tests: false
  modules-download-mode: vendor

issues:
  # Maximum issues count per one linter
  max-issues-per-linter: 0
  # Maximum count of issues with the same text
  max-same-issues: 0

severity:
  default-severity: error
  case-sensitive: true
  rules:
    - linters:
        - godox
        - goconst
        - lll
        - misspell
      severity: warning

# Configuration of specific linters
linters-settings:
  goconst:
    min-len: 2
    min-occurrences: 3
  gosimple:
    go: "1.18"
    checks: ["all"]
  govet:
    check-shadowing: true
    settings:
      printf:
        funcs:
          - (github.com/sirupsen/logrus).Debugf
          - (github.com/sirupsen/logrus).Infof
          - (github.com/sirupsen/logrus).Warnf
          - (github.com/sirupsen/logrus).Errorf
          - (github.com/sirupsen/logrus).Fatalf
  misspell:
    locale: US
  lll:
    line-length: 140
  revive:
    ignore-generated-header: false
    severity: error
    confidence: 0.8
    rules:
      - name: blank-imports
        severity: warning
      - name: context-as-argument
        severity: warning
      - name: context-keys-type
        severity: warning
      - name: cyclomatic
        severity: warning
        arguments:
          - 30 # Maximum cyclomatic complexity
      - name: error-return
        severity: warning
      - name: error-strings
        severity: warning
      - name: error-naming
        severity: warning
      - name: exported
        severity: warning
      - name: if-return
        severity: warning
      - name: increment-decrement
        severity: warning
      - name: var-naming
        severity: warning
      - name: var-declaration
        severity: warning
      - name: package-comments
        severity: warning
      - name: range
        severity: warning
      - name: receiver-naming
        severity: warning
      - name: time-naming
        severity: warning
      - name: unexported-return
        severity: warning
      - name: indent-error-flow
        severity: warning
      - name: errorf
        severity: warning
      - name: empty-block
        severity: warning
      - name: superfluous-else
        severity: warning
      - name: unreachable-code
        severity: warning
      - name: redefines-builtin-id
        severity: warning
  staticcheck:
    go: "1.18"
    checks: ["all"]

linters:
  disable-all: true
  enable:
    - deadcode
    - errcheck
    - exportloopref
    - goconst
    - godox
    - gofmt
    - goimports
    - gosec
    - gosimple
    - govet
    - ineffassign
    - lll
    - misspell
    - prealloc
    - revive
    - rowserrcheck
    - staticcheck
    - typecheck
    - unconvert
    - unparam
    - unused
    - varcheck
    - whitespace

Go environment

$ go version && go env
go version go1.18.3 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/hbollon/.cache/go-build"
GOENV="/home/hbollon/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/hbollon/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/hbollon/go"
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.18.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="0"
GOMOD="/home/hbollon/git/camptocamp/github.com/pulumi-aws-schweizmobil/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 -m64 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3768830388=/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/hbollon/git/camptocamp/github.com/pulumi-aws-schweizmobil /home/hbollon/git/camptocamp/github.com /home/hbollon/git/camptocamp /home/hbollon/git /home/hbollon /home /] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 23 linters: [deadcode errcheck exportloopref goconst godox gofmt goimports gosec gosimple govet ineffassign lll misspell prealloc revive rowserrcheck staticcheck typecheck unconvert unparam unused varcheck whitespace] 
INFO [loader] Go packages loading at mode 575 (exports_file|imports|name|types_sizes|compiled_files|deps|files) took 297.133506ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 3.516474ms 
WARN [linter] revive: the following rules (context-keys-type,errorf,time-naming,unexported-return,var-declaration) are ignored due to a performance problem (https://github.com/golangci/golangci-lint/issues/2997) 
WARN [linter] revive: the following rules (context-keys-type,errorf,time-naming,unexported-return,var-declaration) are ignored due to a performance problem (https://github.com/golangci/golangci-lint/issues/2997) 
WARN [linter] revive: the following rules (context-keys-type,errorf,time-naming,unexported-return,var-declaration) are ignored due to a performance problem (https://github.com/golangci/golangci-lint/issues/2997) 
WARN [linter] revive: the following rules (context-keys-type,errorf,time-naming,unexported-return,var-declaration) are ignored due to a performance problem (https://github.com/golangci/golangci-lint/issues/2997) 
WARN [linter] revive: the following rules (context-keys-type,errorf,time-naming,unexported-return,var-declaration) are ignored due to a performance problem (https://github.com/golangci/golangci-lint/issues/2997) 
WARN [linter] revive: the following rules (context-keys-type,errorf,time-naming,unexported-return,var-declaration) are ignored due to a performance problem (https://github.com/golangci/golangci-lint/issues/2997) 
INFO [linters context/goanalysis] analyzers took 28.882281765s with top 10 stages: buildir: 22.87677273s, inspect: 1.227991458s, fact_deprecated: 961.468251ms, ctrlflow: 795.982667ms, printf: 661.610435ms, buildssa: 460.026843ms, nilness: 415.28584ms, fact_purity: 410.979807ms, SA5012: 278.633748ms, typedness: 272.857575ms 
WARN [linters context] rowserrcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649. 
INFO [runner] Issues before processing: 54, after processing: 8 
INFO [runner] Processors filtering stat (out/in): autogenerated_exclude: 54/54, severity-rules-case-sensitive: 8/8, path_prefixer: 8/8, sort_results: 8/8, cgo: 54/54, skip_files: 54/54, uniq_by_line: 8/8, source_code: 8/8, path_shortener: 8/8, filename_unadjuster: 54/54, identifier_marker: 54/54, exclude: 54/54, diff: 8/8, max_same_issues: 8/8, path_prettifier: 54/54, exclude-rules: 8/54, nolint: 8/8, max_per_file_from_linter: 8/8, max_from_linter: 8/8, skip_dirs: 54/54 
INFO [runner] processing took 5.025759ms with stages: exclude-rules: 2.342011ms, identifier_marker: 1.184585ms, nolint: 1.026599ms, path_prettifier: 226.442µs, autogenerated_exclude: 115.616µs, skip_dirs: 57.544µs, source_code: 55.683µs, uniq_by_line: 4.459µs, cgo: 3.697µs, path_shortener: 3.105µs, filename_unadjuster: 2.186µs, severity-rules-case-sensitive: 1.212µs, max_per_file_from_linter: 987ns, max_same_issues: 546ns, skip_files: 229ns, exclude: 221ns, diff: 187ns, max_from_linter: 182ns, sort_results: 161ns, path_prefixer: 107ns 
INFO [runner] linters took 6.877429384s with stages: goanalysis_metalinter: 6.872331656s, rowserrcheck: 6.736µs 
internal/pkg/components/foundations/dns.go:42:28: Error return value of `f.errorWrapper.Wrap` is not checked (errcheck)
		defer f.errorWrapper.Wrap(err)
		                         ^
internal/pkg/components/foundations/ecr.go:67: internal/pkg/components/foundations/ecr.go:67: Line contains TODO/BUG/FIXME: "TODO" (godox)
			// TODO
internal/pkg/components/foundations/ecr.go:72: internal/pkg/components/foundations/ecr.go:72: Line contains TODO/BUG/FIXME: "TODO" (godox)
				// TODO
internal/pkg/components/foundations/ecr.go:113: internal/pkg/components/foundations/ecr.go:113: Line contains TODO/BUG/FIXME: "TODO" (godox)
			// TODO
internal/pkg/components/foundations/ecr.go:118: internal/pkg/components/foundations/ecr.go:118: Line contains TODO/BUG/FIXME: "TODO" (godox)
				// TODO
internal/pkg/components/foundations/network.go:107: internal/pkg/components/foundations/network.go:107: Line contains TODO/BUG/FIXME: "TODO" (godox)
				// TODO
internal/pkg/components/foundations/dns.go:13:23: var-naming: method newDnsZone should be newDNSZone (revive)
func (f *Foundations) newDnsZone(ctx *pulumi.Context) (err error) {
                      ^
internal/pkg/components/foundations/foundations.go:85:6: exported: type name will be used as foundations.FoundationsArgs by other packages, and that stutters; consider calling this Args (revive)
type FoundationsArgs struct {
     ^
INFO File cache stats: 19 entries of total size 61.7KiB 
INFO Memory: 73 samples, avg is 462.4MB, max is 667.2MB 
INFO Execution took 7.182767414s

Additionally, there is severity informations parsed with jq:

$ golangci-lint run --out-format json | jq  '.Issues[] | {text: .Text, severity: .Severity }'
WARN [linters context] rowserrcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649. 
{
  "text": "Error return value of `f.errorWrapper.Wrap` is not checked",
  "severity": "error"
}
{
  "text": "internal/pkg/components/foundations/ecr.go:67: Line contains TODO/BUG/FIXME: \"TODO\"",
  "severity": "warning"
}
{
  "text": "internal/pkg/components/foundations/ecr.go:72: Line contains TODO/BUG/FIXME: \"TODO\"",
  "severity": "warning"
}
{
  "text": "internal/pkg/components/foundations/ecr.go:113: Line contains TODO/BUG/FIXME: \"TODO\"",
  "severity": "warning"
}
{
  "text": "internal/pkg/components/foundations/ecr.go:118: Line contains TODO/BUG/FIXME: \"TODO\"",
  "severity": "warning"
}
{
  "text": "internal/pkg/components/foundations/network.go:107: Line contains TODO/BUG/FIXME: \"TODO\"",
  "severity": "warning"
}
{
  "text": "var-naming: method newDnsZone should be newDNSZone",
  "severity": "error"
}
{
  "text": "exported: type name will be used as foundations.FoundationsArgs by other packages, and that stutters; consider calling this Args",
  "severity": "error"
}

var-naming and exported should be at warning level according to my configuration file...

Code example or link to a public repository

package main

func newDnsZone() error {
	return nil
}

func main() {
	newDnsZone()
}

With my config it should return:

$ golangci-lint run --out-format json | jq  '.Issues[] | {text: .Text, severity: .Severity }'
WARN [linters context] rowserrcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649. 
{
  "text": "Error return value is not checked",
  "severity": "error"
}
{
  "text": "var-naming: func newDnsZone should be newDNSZone",
  "severity": "error"
}

Which is not the intended result since the var-naming rule appear as error and not warning

@hbollon hbollon added the bug Something isn't working label Aug 18, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 18, 2022

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

@hbollon hbollon changed the title revive: rule's severity config has not effect revive: rules's severity config has no effect Aug 18, 2022
@ldez ldez added question Further information is requested and removed bug Something isn't working labels Sep 9, 2022
@geoff-maddock

This comment was marked as off-topic.

@ubiuser

This comment was marked as off-topic.

@avinash-fam
Copy link

Is this being worked on?

@felipe-lopez-solaris

This comment was marked as off-topic.

@ldez ldez added dependencies Relates to an upstream dependency and removed question Further information is requested labels Mar 8, 2024
@ldez
Copy link
Member

ldez commented Mar 8, 2024

Fixed by #4452

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
area: severity dependencies Relates to an upstream dependency
Projects
None yet
6 participants