Description
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.