Skip to content

Golangci-lint does not show revive exported lints when using import "C" #2449

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

Closed
4 tasks done
polyscone opened this issue Jan 2, 2022 · 3 comments · Fixed by #3025
Closed
4 tasks done

Golangci-lint does not show revive exported lints when using import "C" #2449

polyscone opened this issue Jan 2, 2022 · 3 comments · Fixed by #3025
Labels
area: cgo Related to CGO or line directives bug Something isn't working feedback required Requires additional feedback

Comments

@polyscone
Copy link

polyscone commented Jan 2, 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

When I enable the revive linter along with setting the include configuration to include exported lints the linter output fails when import "C" is used.

I've been using cgo to call into SDL2 and I noticed today that in files where I import "C" and #include a .h file, the exported class of lints (doc comments on exported function etc.) don't show up.

These lints work prefectly fine if I don't import "C".

The lints also work fine if I enable the now deprecated golint linter even without removing import "C", so this is just a problem with revive, for some reason.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.43.0 built from 861262b7 on 2021-11-03T11:57:46Z

Configuration file

$ cat .golangci.json
{
    "linters": {
        "disable-all": true,
        "enable": [
            "revive"
        ]
    },
    "issues": {
        "include": [
            "EXC0012",
            "EXC0013",
            "EXC0014",
            "EXC0015"
        ]
    }
}

Go environment

$ go version && go env
go version go1.17.1 windows/amd64
set GO111MODULE=
set GOARCH=amd64
set GOBIN=D:\projects\go\bin
set GOCACHE=D:\devenv\go\1.17.1\..\cache
set GOENV=C:\Users\Polyscone\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\projects\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\projects\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=D:\devenv\go\1.17.1
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\devenv\go\1.17.1\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.1
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\Polyscone\Desktop\bug\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\POLYSC~1\AppData\Local\Temp\go-build1279465700=/tmp/go-build -gno-record-gcc-switches

Verbose output of running

Without import "C":

$ golangci-lint cache clean
$ golangci-lint run -v
level=info msg="[config_reader] Config search paths: [./ C:\\Users\\Polyscone\\Desktop\\bug C:\\Users\\Polyscone\\Desktop C:\\Users\\Polyscone C:\\Users C:\\ D:\\devenv]"
level=info msg="[config_reader] Used config file .golangci.json"
level=info msg="[lintersdb] Active 1 linters: [revive]"
level=info msg="[loader] Go packages loading at mode 7 (name|compiled_files|files) took 508.7361ms"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 0s"
level=info msg="[linters context/goanalysis] analyzers took 0s with top 10 stages: the_only_name: 0s"
level=info msg="[runner] Processors filtering stat (out/in): skip_dirs: 1/1, cgo: 1/1, path_prettifier: 1/1, exclude: 1/1, nolint: 1/1, max_per_file_from_linter: 1/1, max_same_issues: 1/1, path_prefixer: 1/1, filename_unadjuster: 1/1, diff: 1/1, max_from_linter: 1/1, path_shortener: 1/1, sort_results: 1/1, skip_files: 1/1, autogenerated_exclude: 1/1, identifier_marker: 1/1, exclude-rules: 1/1, uniq_by_line: 1/1, source_code: 1/1, severity-rules: 1/1"
level=info msg="[runner] processing took 0s with stages: autogenerated_exclude: 0s, identifier_marker: 0s, exclude: 0s, nolint: 0s, max_per_file_from_linter: 0s, cgo: 0s, path_prettifier: 0s, exclude-rules: 0s, max_from_linter: 0s, path_shortener: 0s, severity-rules: 0s, skip_files: 0s, skip_dirs: 0s, source_code: 0s, filename_unadjuster: 0s, uniq_by_line: 0s, diff: 0s, max_same_issues: 0s, path_prefixer: 0s, sort_results: 0s"
level=info msg="[runner] linters took 3.9982ms with stages: revive: 3.0007ms"
sdl\sdl.go:3:1: exported: exported function Foo should have comment or be unexported (revive)
func Foo() {}
^
level=info msg="File cache stats: 1 entries of total size 27B"
level=info msg="Memory: 8 samples, avg is 44.1MB, max is 44.4MB"
level=info msg="Execution took 629.5749ms"

With import "C":

$ golangci-lint cache clean
$ golangci-lint run -v
level=info msg="[config_reader] Config search paths: [./ C:\\Users\\Polyscone\\Desktop\\bug C:\\Users\\Polyscone\\Desktop C:\\Users\\Polyscone C:\\Users C:\\ D:\\devenv]"
level=info msg="[config_reader] Used config file .golangci.json"
level=info msg="[lintersdb] Active 1 linters: [revive]"
level=info msg="[loader] Go packages loading at mode 7 (files|name|compiled_files) took 570.3007ms"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 971.9µs"
level=info msg="[linters context/goanalysis] analyzers took 2.0046ms with top 10 stages: the_only_name: 2.0046ms"
level=info msg="[runner] processing took 0s with stages: uniq_by_line: 0s, sort_results: 0s, autogenerated_exclude: 0s, skip_dirs: 0s, exclude-rules: 0s, diff: 0s, max_per_file_from_linter: 0s, max_same_issues: 0s, path_shortener: 0s, severity-rules: 0s, cgo: 0s, path_prettifier: 0s, identifier_marker: 0s, exclude: 0s, path_prefixer: 0s, filename_unadjuster: 0s, nolint: 0s, max_from_linter: 0s, source_code: 0s, skip_files: 0s"
level=info msg="[runner] linters took 551.2396ms with stages: revive: 551.2396ms"
level=info msg="File cache stats: 0 entries of total size 0B"
level=info msg="Memory: 14 samples, avg is 48.0MB, max is 48.0MB"
level=info msg="Execution took 1.2283984s"

Code example or link to a public repository

The minimum project I set up is a .golangci.json file with the above config, a go.mod file, a main.go file with an empty main function in it, and then an sdl package.

The sdl package contains a single sdl.go file with the following contents:

package sdl

// #include <SDL.h>
import "C"

func Foo() {}

As soon as I remove the import "C" golangci-lint correctly reports the missing doc comments.

@polyscone polyscone added the bug Something isn't working label Jan 2, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Jan 2, 2022

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

@ldez
Copy link
Member

ldez commented Jan 2, 2022

Hello,

I recommend adding typecheck (this linter is a requirement), and I think you will see the root cause of your problem.

@ldez ldez added the feedback required Requires additional feedback label Jan 2, 2022
@polyscone
Copy link
Author

polyscone commented Jan 2, 2022

Hello,

I recommend adding typecheck (this linter is a requirement), and I think you will see the root cause of your problem.

Thank you for the suggestion, but adding typecheck doesn't change the output.

Just in case I tried it anyway, so this is now my config:

{
    "linters": {
        "disable-all": true,
        "enable": [
            "typecheck",
            "revive"
        ]
    },
    "issues": {
        "include": [
            "EXC0012",
            "EXC0013",
            "EXC0014",
            "EXC0015"
        ]
    }
}

After running the following...

golangci-lint cache clean
golangci-lint run -v

...this is the output I get:

level=info msg="[config_reader] Config search paths: [./ C:\\Users\\Polyscone\\Desktop\\bug C:\\Users\\Polyscone\\Desktop C:\\Users\\Polyscone C:\\Users C:\\ D:\\devenv]"
level=info msg="[config_reader] Used config file .golangci.json"
level=info msg="[lintersdb] Active 2 linters: [revive typecheck]"
level=info msg="[loader] Go packages loading at mode 575 (deps|exports_file|files|types_sizes|compiled_files|imports|name) took 572.5549ms"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 0s"
level=info msg="[linters context/goanalysis] analyzers took 2.728ms with top 10 stages: the_only_name: 2.728ms, typecheck: 0s"
level=info msg="[runner] processing took 0s with stages: path_prettifier: 0s, skip_files: 0s, skip_dirs: 0s, uniq_by_line: 0s, sort_results: 0s, autogenerated_exclude: 0s, exclude: 0s, diff: 0s, path_shortener: 0s, severity-rules: 0s, filename_unadjuster: 0s, identifier_marker: 0s, max_per_file_from_linter: 0s, max_from_linter: 0s, source_code: 0s, cgo: 0s, exclude-rules: 0s, nolint: 0s, max_same_issues: 0s, path_prefixer: 0s"
level=info msg="[runner] linters took 84.2395ms with stages: goanalysis_metalinter: 84.2395ms"
level=info msg="File cache stats: 0 entries of total size 0B"
level=info msg="Memory: 9 samples, avg is 50.6MB, max is 69.0MB"
level=info msg="Execution took 774.9253ms"

So no new errors/warnings and the doc comment lints still aren't being shown.

I also tried running revive directly and the lints work just fine that way.

Edit:
I should also add that I just tried changing from #include <SDL.h> to #include "testing.h", which is an empty .h file in the same directory as sdl.go, but that also makes no difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cgo Related to CGO or line directives bug Something isn't working feedback required Requires additional feedback
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants