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 - exported rule does not work #2439

Closed
4 tasks done
vigo opened this issue Dec 30, 2021 · 8 comments
Closed
4 tasks done

revive - exported rule does not work #2439

vigo opened this issue Dec 30, 2021 · 8 comments
Labels
area: config Related to .golangci.yml and/or cli options question Further information is requested

Comments

@vigo
Copy link

vigo commented Dec 30, 2021

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

package main

import "fmt"

type Foo struct{}

func main() {
	f := &Foo{}
	fmt.Println(f)
}

Standalone revive usage gives:

$ revive ./...
main.go:5:6: exported type Foo should have comment or be unexported

but golangci-lint run -v gives nothing:

INFO [config_reader] Config search paths: [./ /tmp/foo /tmp / /Users/vigo] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 1 linters: [revive]       
INFO [loader] Go packages loading at mode 7 (compiled_files|files|name) took 88.506709ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 273.708µs 
INFO [linters context/goanalysis] analyzers took 0s with no stages 
INFO [runner] Issues before processing: 2, after processing: 0 
INFO [runner] Processors filtering stat (out/in): skip_dirs: 2/2, identifier_marker: 2/2, exclude: 2/2, skip_files: 2/2, exclude-rules: 0/2, path_prettifier: 2/2, autogenerated_exclude: 2/2, cgo: 2/2, filename_unadjuster: 2/2 
INFO [runner] processing took 314.337µs with stages: skip_dirs: 111.25µs, exclude-rules: 50.959µs, autogenerated_exclude: 49.292µs, path_prettifier: 48µs, identifier_marker: 47.125µs, cgo: 3.959µs, max_same_issues: 625ns, nolint: 625ns, filename_unadjuster: 542ns, diff: 292ns, max_from_linter: 251ns, severity-rules: 251ns, exclude: 249ns, source_code: 209ns, sort_results: 207ns, uniq_by_line: 166ns, skip_files: 84ns, path_prefixer: 84ns, max_per_file_from_linter: 84ns, path_shortener: 83ns 
INFO [runner] linters took 747.209µs with stages: revive: 357.917µs 
INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 3 samples, avg is 45.1MB, max is 45.1MB 
INFO Execution took 100.412625ms      

I tried every possible config options... Here is what use: .golangci.yml

run:
  concurrency: 4
  timeout: 1m

linters-settings:
  revive:
    ignore-generated-header: true
    severity: warning
    rules:
      - name: exported
        arguments: [ "checkPrivateReceivers", "sayRepetitiveInsteadOfStutters" ]

linters:
  disable-all: true
  enable:
    - revive

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.43.0 built from 861262b on 2021-11-02T20:54:42Z

Configuration file

$ cat .golangci.yml
run:
  concurrency: 4
  timeout: 1m

linters-settings:
  revive:
    ignore-generated-header: true
    severity: warning
    rules:
      - name: exported
        arguments: [ "checkPrivateReceivers", "sayRepetitiveInsteadOfStutters" ]

linters:
  disable-all: true
  enable:
    - revive

Go environment

$ go version && go env
go version go1.17.5 darwin/arm64

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/vigo/Library/Caches/go-build"
GOENV="/Users/vigo/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/vigo/go-packages/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/vigo/go-packages"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.17.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.17.5/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.17.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/tmp/foo/go.mod"
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/cn/fscqb0ln3zx01lpksypkv_8m0000gn/T/go-build380538200=/tmp/go-build -gno-record-gcc-switches -fno-common"

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /tmp/foo /tmp / /Users/vigo] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 1 linters: [revive]       
INFO [loader] Go packages loading at mode 7 (name|files|compiled_files) took 164.089792ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 425.292µs 
INFO [linters context/goanalysis] analyzers took 3.730334ms with top 10 stages: the_only_name: 3.730334ms 
INFO [runner] Issues before processing: 2, after processing: 0 
INFO [runner] Processors filtering stat (out/in): filename_unadjuster: 2/2, path_prettifier: 2/2, cgo: 2/2, exclude: 2/2, exclude-rules: 0/2, skip_files: 2/2, skip_dirs: 2/2, identifier_marker: 2/2, autogenerated_exclude: 2/2 
INFO [runner] processing took 436.957µs with stages: path_prettifier: 134µs, identifier_marker: 102.875µs, autogenerated_exclude: 88.249µs, exclude-rules: 72.376µs, skip_dirs: 26.416µs, cgo: 2.875µs, nolint: 2.166µs, uniq_by_line: 1.292µs, filename_unadjuster: 1.126µs, max_same_issues: 1.125µs, exclude: 791ns, max_per_file_from_linter: 751ns, source_code: 708ns, max_from_linter: 500ns, severity-rules: 499ns, path_shortener: 417ns, skip_files: 417ns, diff: 166ns, sort_results: 125ns, path_prefixer: 83ns 
INFO [runner] linters took 446.495208ms with stages: revive: 445.9515ms 
INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 8 samples, avg is 45.2MB, max is 45.3MB 
INFO Execution took 625.02375ms                   

Code example or link to a public repository

package main

import "fmt"

type Foo struct{}

func main() {
	f := &Foo{}
	fmt.Println(f)
}
@vigo vigo added the bug Something isn't working label Dec 30, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Dec 30, 2021

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

@butuzov
Copy link
Member

butuzov commented Dec 30, 2021

let me check this, it should be something with a confidence level.

update: it has nothing to do with a confidience.

@butuzov
Copy link
Member

butuzov commented Dec 30, 2021

The isses are suppressed by default excludeRules filtering (see https://github.com/golangci/golangci-lint/blob/master/pkg/config/issues.go#L80-L103), you can turn them off with the next config.

run:
  concurrency: 4
  timeout: 1m

linters-settings:
  revive:
    ignore-generated-header: true
    severity: warning
    rules:
      - name: exported
        arguments: [ "checkPrivateReceivers", "sayRepetitiveInsteadOfStutters" ]

linters:
  disable-all: true
  enable:
    - revive

issues: 
  exclude-use-default: false

@butuzov butuzov closed this as completed Dec 30, 2021
@butuzov butuzov added area: config Related to .golangci.yml and/or cli options question Further information is requested and removed bug Something isn't working labels Dec 30, 2021
@vigo
Copy link
Author

vigo commented Dec 30, 2021

thank you sooooooooooooooooooo much

@jsf5
Copy link

jsf5 commented Jan 22, 2022

Thank you, @butuzov. You saved me from filing a bug. :)

@dkegel-fastly
Copy link

Ran into this myself, the workaround is to add two lines to .golangci-lint:

issues:
  exclude-use-default: false

Why was this bug closed? This feels like a serious usability problem; it took me hours to figure out why this golint warning wasn't being emulated... it takes me about an hour to recover every time this warning does not fire.

@ldez
Copy link
Member

ldez commented Mar 7, 2022

Why was this bug closed?

Because the answer is here:
#2439 (comment)

We have another issue to remove the excludes by default: #456

@dkegel-fastly
Copy link

Thank you for linking to #456.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: config Related to .golangci.yml and/or cli options question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants