-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 is not playing nice with cgo #2612
Comments
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors. |
Hello, I don't reproduce your problem: main.gopackage main
import "unsafe"
// #include <stdlib.h>
import "C"
func main() {
cStr := C.CString("test")
C.free(unsafe.Pointer(cStr))
} .golangci.ymllinters:
disable-all: true
enable:
- revive
- typecheck
linters-settings:
revive:
severity: warning
confidence: 0.1
ignore-generated-header: true
rules:
- name: blank-imports
disabled: false
$ golangci-lint version
golangci-lint has version 1.44.2 built from d58dbde5 on 2022-02-17T20:58:06Z
$ golangci-lint run |
oops I tested in the main package I will test it again. Edit: With another package, I can reproduce the problem. $ golangci-lint run
pkg/pkg.go:6:8: blank-imports: a blank import should be only in a main or test package, or have a comment justifying it (revive)
import "C"
^ |
The Also nlreturn and gocritic give me issues (similar to the ones provided by revive), but didn't yet try to reproduce them (depending on issue, might be solved as well hopefully). The other (cgo-related) issues:
all on code similar to the second line in the example main() function you used initially. But as said, this simple function was not able to reproduce, so something else is influencing it... |
seems related to #2449 |
Might be as there seems to be something weird with cgo going on. But in my case the issue arises with |
revive:
revive inside golangci-lint:
|
revive
revive inside golangci-lint
So the problem seems related to the "cache". |
golangci-lint + revive processes the file through cgo and lints that file, whereas revive is not invoking cgo and processes the original. This (cgo processing) might also cause the other linter issues I mentioned..? 🤔 |
golangci-lint + cgo => because of the cgo processing, all linters that aren't really an Analyzer can be impacted (revive, go-critic, ...) and the other linters also (depending on the Analyzer implementation) |
Welcome
Description of the problem
When using cgo an
import "C"
is required to active cgo (and import/define C code). The blank-imports check does not accept this and throws the following warning:When running with
revive
by itself the issue is gone: See mgechev/revive#635 for more details on report on the revive issue tracker.Version of golangci-lint
Configuration file
Go environment
Verbose output of running
Code example or link to a public repository
The text was updated successfully, but these errors were encountered: