Skip to content
This repository has been archived by the owner on Mar 3, 2021. It is now read-only.

Golangci-lint on generated code #120

Open
parabolala opened this issue Nov 14, 2020 · 2 comments
Open

Golangci-lint on generated code #120

parabolala opened this issue Nov 14, 2020 · 2 comments

Comments

@parabolala
Copy link

Hi, I've hacked together a small patch that allows running golangci-lint on the generated go code. It relies on @rules_go/go_path to assemble a source tree of all the dependencies and uses that as GOPATH for the golangci-lint invocation.

I've got it to work on my small repo that uses generated code for protobuf libraries and it works. The minimal patch to accept a go_path() output and wire it through GOPATH is at parabolala@3fd012a

It can be used as:

load("@io_bazel_rules_go//go:def.bzl", "go_path")
load("@com_github_atlassian_bazel_tools//golangcilint:def.bzl", "golangcilint")

go_path(
    name = "go_root",
    deps = [
      # Code entry points (go_binary, go_library) to lint. 
      # All their transitive deps are pulled in and are filtered by "prefix" below.
      "//service/cmd/server",
    ],
    include_pkg = True,
)

golangcilint(
    name = "golangcilint",
    go_path = ":go_root",
    prefix = "<prefix matching the code>",
)

Am I missing something essential? Does this look feasible? If yes, I'll be happy to flesh it out into a PR.

@ash2k
Copy link
Contributor

ash2k commented Nov 15, 2020

GOPATH is going away within a year, so no point in supporting it. I think this rule just cannot be made to work the way it currently... works. It needs to be redone completely. See this issue for more details #118

@ash2k
Copy link
Contributor

ash2k commented Nov 15, 2020

On the other hand, if you use this rule and it would be convenient for you to have it with the patch, feel free to submit a PR. It will keep working while Go supports GOPATH and then it will stop. 🤷

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants