Skip to content

revive is not playing nice with cgo #2612

Closed
@veger

Description

@veger

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 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)

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

$ golangci-lint --version
golangci-lint has version 1.44.2 built from d58dbde5 on 2022-02-17T20:58:06Z

Configuration file

$ cat .golangci.yml
linters-settings:
  revive:
    ignore-generated-header: true
    rules:
      - name: blank-imports
        disabled: false

Go environment

$ go version && go env
go version go1.17.7 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/some-user/.cache/go-build"
GOENV="/home/some-user/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/some-user/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/some-user/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.7"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build342790889=/tmp/go-build -gno-record-gcc-switches

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v --disable-all -E revive --config=golangci.yml ./pkg/...
INFO [config_reader] Used config file golangci.yml 
INFO [lintersdb] Active 1 linters: [revive]       
INFO [loader] Go packages loading at mode 7 (files|compiled_files|name) took 44.333638ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 133.973µs 
INFO [linters context/goanalysis] analyzers took 426.733µs with top 10 stages: the_only_name: 426.733µs 
INFO [runner] Issues before processing: 2, after processing: 1 
INFO [runner] Processors filtering stat (out/in): max_from_linter: 1/1, path_prefixer: 1/1, skip_dirs: 1/1, identifier_marker: 1/1, exclude: 1/1, max_per_file_from_linter: 1/1, path_prettifier: 1/1, exclude-rules: 1/1, diff: 1/1, severity-rules: 1/1, sort_results: 1/1, skip_files: 1/1, filename_unadjuster: 1/1, autogenerated_exclude: 1/1, nolint: 1/1, uniq_by_line: 1/1, max_same_issues: 1/1, source_code: 1/1, path_shortener: 1/1, cgo: 1/2 
INFO [runner] processing took 171.187µs with stages: exclude-rules: 62.068µs, identifier_marker: 32.43µs, path_prettifier: 18.586µs, autogenerated_exclude: 18.147µs, nolint: 16.529µs, source_code: 10.408µs, skip_dirs: 5.063µs, path_shortener: 1.799µs, uniq_by_line: 1.459µs, max_same_issues: 1.11µs, cgo: 738ns, max_from_linter: 726ns, filename_unadjuster: 714ns, max_per_file_from_linter: 359ns, severity-rules: 218ns, skip_files: 202ns, diff: 190ns, exclude: 190ns, sort_results: 147ns, path_prefixer: 104ns 
INFO [runner] linters took 6.615019ms with stages: revive: 6.390022ms 
pkg/blank-import-cgo.go:5:8: blank-imports: a blank import should be only in a main or test package, or have a comment justifying it (revive)
import "C"
       ^
INFO File cache stats: 1 entries of total size 76B 
INFO Memory: 2 samples, avg is 48.8MB, max is 48.8MB 
INFO Execution took 55.307828ms                   

Code example or link to a public repository

// Package pkg ...
package pkg

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: cgoRelated to CGO or line directivesbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions