From 6c633efba73d6a45be4dd7cd73e40b05a681bed9 Mon Sep 17 00:00:00 2001 From: "Sean R. Abraham" Date: Fri, 9 Feb 2024 13:05:23 -0700 Subject: [PATCH] chore: demonstrate golangci-lint not working with deps I get an error like below when I run bazel lint src:hello_go as a result of the go_binary depending on another go target this is a demo of https://github.com/aspect-build/rules_lint/issues/129 INFO: Analyzed target //src:hello_go (0 packages loaded, 0 targets configured). INFO: From golangcilint src/golangcilint.hello_go.aspect_rules_lint.report: level=warning msg="[runner] Can't run linter goanalysis_metalinter: buildir: failed to load package : could not load export data: no export data for \"gopher\"" level=error msg="Running error: 1 error occurred:\n\t* can't run linter goanalysis_metalinter: buildir: failed to load package : could not load export data: no export data for \"gopher\"\n\n" --- example/.aspect/cli/config.yaml | 1 + example/src/BUILD.bazel | 1 + example/src/gopher/BUILD.bazel | 8 ++++++++ example/src/gopher/gopher.go | 5 +++++ example/src/hello.go | 17 +++++++++++++---- 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 example/src/gopher/BUILD.bazel create mode 100644 example/src/gopher/gopher.go diff --git a/example/.aspect/cli/config.yaml b/example/.aspect/cli/config.yaml index 50a0fdcf..9f913206 100644 --- a/example/.aspect/cli/config.yaml +++ b/example/.aspect/cli/config.yaml @@ -3,6 +3,7 @@ lint: - //tools/lint:linters.bzl%eslint - //tools/lint:linters.bzl%buf - //tools/lint:linters.bzl%flake8 + - //tools/lint:linters.bzl%golangci_lint - //tools/lint:linters.bzl%pmd - //tools/lint:linters.bzl%ruff - //tools/lint:linters.bzl%vale diff --git a/example/src/BUILD.bazel b/example/src/BUILD.bazel index 01d65db0..394e774e 100644 --- a/example/src/BUILD.bazel +++ b/example/src/BUILD.bazel @@ -46,6 +46,7 @@ sh_library( go_binary( name = "hello_go", srcs = ["hello.go"], + deps = ["//src/gopher"], ) cc_binary( diff --git a/example/src/gopher/BUILD.bazel b/example/src/gopher/BUILD.bazel new file mode 100644 index 00000000..a9ba4e0e --- /dev/null +++ b/example/src/gopher/BUILD.bazel @@ -0,0 +1,8 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "gopher", + srcs = ["gopher.go"], + importpath = "gopher", + visibility = ["//visibility:public"], +) diff --git a/example/src/gopher/gopher.go b/example/src/gopher/gopher.go new file mode 100644 index 00000000..dedce7cd --- /dev/null +++ b/example/src/gopher/gopher.go @@ -0,0 +1,5 @@ +package gopher + +func Name() string { + return "Gopher!" +} diff --git a/example/src/hello.go b/example/src/hello.go index f64c44f7..da816a85 100644 --- a/example/src/hello.go +++ b/example/src/hello.go @@ -2,13 +2,22 @@ package main import ( "fmt" + "gopher" + "log" ) -const ( - w = "world" -) +// staticcheck won't like this +var notUsed string func main() { - hello := fmt.Sprintf("Hello %s\n", w) + s := []string{"a"} + // staticcheck also won't like this + if s != nil { + for _, v := range s { + log.Println(v) + } + } + hello := fmt.Sprintf("Hello %s\n", gopher.Name()) fmt.Printf(hello) + _ = s }