Skip to content

Commit

Permalink
chore: demonstrate golangci-lint not working with deps
Browse files Browse the repository at this point in the history
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 #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"
  • Loading branch information
srabraham committed Feb 9, 2024
1 parent ebe8678 commit ecacb26
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions example/.aspect/cli/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ lint:
- //tools:lint.bzl%eslint
- //tools:lint.bzl%buf
- //tools:lint.bzl%flake8
- //tools:lint.bzl%golangci_lint
- //tools:lint.bzl%pmd
- //tools:lint.bzl%ruff
1 change: 1 addition & 0 deletions example/src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sh_library(
go_binary(
name = "hello_go",
srcs = ["hello.go"],
deps = ["//src/gopher"],
)

cc_binary(
Expand Down
8 changes: 8 additions & 0 deletions example/src/gopher/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
5 changes: 5 additions & 0 deletions example/src/gopher/gopher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package gopher

func Name() string {
return "Gopher!"
}
17 changes: 13 additions & 4 deletions example/src/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit ecacb26

Please sign in to comment.