-
Notifications
You must be signed in to change notification settings - Fork 278
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
blank-imports and constant-logical-error do not support cgo #635
Comments
Related I guess:
triggers |
Hi @veger thanks for filling the issue. And always keep in mind what Rob Pike says about Cgo :) |
Yes I am not a fan as well, but we have to use a proprietary, 3rd-party library that would take years to reproduce and we simply have not the time to do so unfortunately (because it would be a very nice project)... :) |
Hi @veger I'm not been successful in reproducing the problem. $ make build
$ ./revive -config defaults.toml deleteme/blank-import-cgo.go |
Edit: Sorry due to all tries, I confused some results and this one works fine as well (I'll continue figuring out a reproducible test) Yes I am using the aggregator golangci-lint, but unfortunately I cannot reproduce your example branch using golangci-lint with my config... So I guess I messed up my 'reproducible example' 😞 While trying to make it reproducible with your branch I found another cgo-related error. diff --git a/defaults.toml b/defaults.toml
index 8d298de..e60c086 100644
--- a/defaults.toml
+++ b/defaults.toml
@@ -5,4 +5,6 @@ errorCode = 0
warningCode = 0
[rule.blank-imports]
+[rule.file-header]
+ arguments =["This is the text that must appear at the top of source files."] when I run the build revive I get:
Needless to say the file is not there (I guess it is temporarily there), but I also asked to only lint the black-import-cgo.go file and not the one with the error. I'll continue trying to reproduce 'my' error |
Finally I figured it out... The example uses package I tried some more but was still not able to make an example. 😞 Using linters-settings:
revive:
ignore-generated-header: true
rules:
- name: blank-imports
disabled: false and the following code changes in 'deleteme' (basically it is only the import in a non-main/test package) diff --git a/deleteme/blank-import-cgo.go b/deleteme/blank-import-cgo.go
index 928b001..e2ff120 100644
--- a/deleteme/blank-import-cgo.go
+++ b/deleteme/blank-import-cgo.go
@@ -1,13 +1,5 @@
-// Package main ...
-package main
-
-import "unsafe"
+// Package deleteme ...
+package deleteme
// #include <stdlib.h>
import "C"
-
-func main() {
- cStr := C.CString("test")
-
- C.free(unsafe.Pointer(cStr))
-}
When running it gives:
As you can see it is only running revive as a linter and it shows the lint issue. Interestingly enough, with Running In case it is interesting:
Note that the constant-logical-error issue I could not (yet) reproduce... I guess there is something (else) in my code that triggers it... I can take another look later if needed. |
Hi @veger thanks for the investigations. I'll continue searching. |
It only shows up when using revive via golangci-lint, I was also not able to reproduce it directly with revive itself. Maybe golangci-lint does something 'behind the scene' causing revive to choke? 🤔 |
I really do not known |
This may be related to golangci/golangci-lint#2611. |
I grabbed and build golangci-lint with this commit and tried. Unfortunately I still have the same issue.
I'll open an issue at golangci-lint |
From the comments in golangci/golangci-lint#2612 it is clear that it is more a |
@veger because the actual file # When set to false, ignores files with "GENERATED" header, similar to golint
ignoreGeneratedHeader = false |
Yes I am fine with closing, it indeed seems to related to golangci-lint and how it processes the files. Shouldn't the We already set this to true, as we have no (direct) influence on any of our generated code and cannot fix any linting issues that are found. |
The config flag is somewhat difficult to understand :) |
Not a |
Thanks for the explaining 👍 |
Describe the bug
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:blank-imports: a blank import should be only in a main or test package, or have a comment justifying it (revive)
To Reproduce
Consider this main.go file:
Run
revive
for this file and the waring appears for theimport "C"
line.Expected behavior
There should not be a warning for this file.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: