Thanks to visit codestin.com
Credit goes to github.com

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

Golangci-lint on generated code #120

@parabolala

Description

@parabolala

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions