diff --git a/internal/bzlmod/default_gazelle_overrides.bzl b/internal/bzlmod/default_gazelle_overrides.bzl index 2283f5d33..3492a4f31 100644 --- a/internal/bzlmod/default_gazelle_overrides.bzl +++ b/internal/bzlmod/default_gazelle_overrides.bzl @@ -86,6 +86,9 @@ DEFAULT_DIRECTIVES_BY_PATH = { # in go files are generated by gogo proto. Resolving to the gogo proto target preserves the behavior of Go modules. "gazelle:resolve go github.com/mwitkow/go-proto-validators @com_github_mwitkow_go_proto_validators//:validators_gogo", ], + "github.com/stackb/rules_proto": [ + "gazelle:go_naming_convention import", + ], "google.golang.org/grpc": [ "gazelle:proto disable", ], diff --git a/language/go/config.go b/language/go/config.go index e23ed5437..d0a4007f6 100644 --- a/language/go/config.go +++ b/language/go/config.go @@ -534,17 +534,23 @@ Update io_bazel_rules_go to a newer version in your WORKSPACE file.` repoNamingConvention := map[string]namingConvention{} for _, repo := range c.Repos { if repo.Kind() == "go_repository" { + var name string + if apparentName := c.ModuleToApparentName(repo.AttrString("module_name")); apparentName != "" { + name = apparentName + } else { + name = repo.Name() + } if attr := repo.AttrString("build_naming_convention"); attr == "" { // No naming convention specified. // go_repsitory uses importAliasNamingConvention by default, so we // could use whichever name. // resolveExternal should take that as a signal to follow the current // naming convention to avoid churn. - repoNamingConvention[repo.Name()] = importAliasNamingConvention + repoNamingConvention[name] = importAliasNamingConvention } else if nc, err := namingConventionFromString(attr); err != nil { - log.Printf("in go_repository named %q: %v", repo.Name(), err) + log.Printf("in go_repository named %q: %v", name, err) } else { - repoNamingConvention[repo.Name()] = nc + repoNamingConvention[name] = nc } } }