revive: blank-imports and constant-logical-error do not support cgo

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:

package main

import "unsafe"

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

func main() {
	cStr := C.CString("test")

	C.free(unsafe.Pointer(cStr))
}

Run revive for this file and the waring appears for the import "C" line.

Expected behavior There should not be a warning for this file.

Desktop (please complete the following information):

  • OS: Arch Linux
  • go version go1.17.7 linux/amd64

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17

Commits related to this issue

Most upvoted comments

I grabbed and build golangci-lint with this commit and tried. Unfortunately I still have the same issue.

$ golangci-lint version                                                                                                                                                      [1]
golangci-lint has version v1.44.3-0.20220223082849-30c6166b0811 built from (unknown, mod sum: "h1:SrfFX8QEdN2/8lMuUn54ENLCLBM2aQguAia4q8G0q2E=") on (unknown)

I’ll open an issue at golangci-lint