Skip to content

go-critic/ruleguard: load embedded ruleguard rules: rules/rules.go:13: can't load fmt #3107

Open
@ldez

Description

@ldez

The issue is a kind of documentation about this topic.

Description of the problem

  • Before v1.49.0, the load of the ruleguard (go-critic) rules happens in an init() function and through a panic if there is a problem (I will explain the problem after).
$ golangci-lint run
panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt

goroutine 1 [running]:
github.com/go-critic/go-critic/checkers.init.9()
    github.com/go-critic/[email protected]/checkers/checkers.go:58 +0x4b4
  • After v1.49.0, the load of the ruleguard (go-critic) rules happens only when go-critic is enabled, and it will produce a simple error. From my experience, the error should disappear with this release due to changes inside ruleguard and go-critic.
$ golangci-lint run
[ERROR] go-critic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt: setting an explicit GOROOT can fix this problem.

The problem

The error happens only when ruleguard (go-critic) is not able to load rules.

ruleguard (go-critic) uses GOROOT to load rules.

If the value of GOROOT is empty, ruleguard will fallback to the GOROOT from the Go context but this Go context can be wrong.

go-critic issues

Previous issues

The solution?

To avoid this problem you can define explicitly the GOROOT environment variable.

$ go env GOROOT                                            
/usr/local/go

$ export GOROOT=/usr/local/go
# or
export "GOROOT=$(go env GOROOT)"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdependenciesRelates to an upstream dependency

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions