From b5c350734136c608bf6ab05f2db12ef92e0e45b4 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Wed, 21 Aug 2024 14:11:02 -0700 Subject: [PATCH] refactor: add nil assignments to verify interface implementations --- cmd/gazelle/fix-update.go | 2 ++ cmd/gazelle/metaresolver.go | 2 +- cmd/gazelle/update-repos.go | 2 ++ config/config.go | 2 ++ internal/gazellebinarytest/xlang.go | 2 ++ resolve/config.go | 2 ++ rule/rule.go | 6 +++--- rule/value.go | 14 +++++++------- walk/config.go | 2 ++ walk/walk_test.go | 2 ++ 10 files changed, 25 insertions(+), 11 deletions(-) diff --git a/cmd/gazelle/fix-update.go b/cmd/gazelle/fix-update.go index 644203f51..c0c8a72ff 100644 --- a/cmd/gazelle/fix-update.go +++ b/cmd/gazelle/fix-update.go @@ -71,6 +71,8 @@ func getUpdateConfig(c *config.Config) *updateConfig { return c.Exts[updateName].(*updateConfig) } +var _ config.Configurer = (*updateConfigurer)(nil) + type updateConfigurer struct { mode string recursive bool diff --git a/cmd/gazelle/metaresolver.go b/cmd/gazelle/metaresolver.go index 31329b553..99c6b4061 100644 --- a/cmd/gazelle/metaresolver.go +++ b/cmd/gazelle/metaresolver.go @@ -77,7 +77,7 @@ type inverseMapKindResolver struct { delegate resolve.Resolver } -var _ resolve.Resolver = inverseMapKindResolver{} +var _ resolve.Resolver = (*inverseMapKindResolver)(nil) func (imkr inverseMapKindResolver) Name() string { return imkr.delegate.Name() diff --git a/cmd/gazelle/update-repos.go b/cmd/gazelle/update-repos.go index 9d33977a1..8c4a168da 100644 --- a/cmd/gazelle/update-repos.go +++ b/cmd/gazelle/update-repos.go @@ -50,6 +50,8 @@ func getUpdateReposConfig(c *config.Config) *updateReposConfig { return c.Exts[updateReposName].(*updateReposConfig) } +var _ config.Configurer = (*updateReposConfigurer)(nil) + type updateReposConfigurer struct{} type macroFlag struct { diff --git a/config/config.go b/config/config.go index 57c3d4481..fed885db3 100644 --- a/config/config.go +++ b/config/config.go @@ -195,6 +195,8 @@ type Configurer interface { Configure(c *Config, rel string, f *rule.File) } +var _ Configurer = (*CommonConfigurer)(nil) + // CommonConfigurer handles language-agnostic command-line flags and directives, // i.e., those that apply to Config itself and not to Config.Exts. type CommonConfigurer struct { diff --git a/internal/gazellebinarytest/xlang.go b/internal/gazellebinarytest/xlang.go index ac5eaab30..9ba91b5b5 100644 --- a/internal/gazellebinarytest/xlang.go +++ b/internal/gazellebinarytest/xlang.go @@ -29,6 +29,8 @@ import ( "github.com/bazelbuild/bazel-gazelle/rule" ) +var _ config.Configurer = (*xlang)(nil) + type xlang struct{} func NewLanguage() language.Language { diff --git a/resolve/config.go b/resolve/config.go index cc2b15d05..d88691991 100644 --- a/resolve/config.go +++ b/resolve/config.go @@ -114,6 +114,8 @@ func getResolveConfig(c *config.Config) *resolveConfig { return c.Exts[resolveName].(*resolveConfig) } +var _ config.Configurer = (*Configurer)(nil) + type Configurer struct{} func (*Configurer) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config) { diff --git a/rule/rule.go b/rule/rule.go index 0c79fa14d..49ce35a0e 100644 --- a/rule/rule.go +++ b/rule/rule.go @@ -514,7 +514,7 @@ type rulesByKindAndName struct { } // type checking -var _ sort.Interface = rulesByKindAndName{} +var _ sort.Interface = (*rulesByKindAndName)(nil) func (s rulesByKindAndName) Len() int { return len(s.rules) @@ -539,7 +539,7 @@ type loadsByName struct { } // type checking -var _ sort.Interface = loadsByName{} +var _ sort.Interface = (*loadsByName)(nil) func (s loadsByName) Len() int { return len(s.loads) @@ -1144,7 +1144,7 @@ func CheckInternalVisibility(rel, visibility string) string { type byAttrName []KeyValue -var _ sort.Interface = byAttrName{} +var _ sort.Interface = (*byAttrName)(nil) func (s byAttrName) Len() int { return len(s) diff --git a/rule/value.go b/rule/value.go index b0ea988df..cda5809bb 100644 --- a/rule/value.go +++ b/rule/value.go @@ -141,13 +141,13 @@ func (s SelectStringListValue) BzlExpr() bzl.Expr { // ExprFromValue converts a value into an expression that can be written into // a Bazel build file. The following types of values can be converted: // -// * bools, integers, floats, strings. -// * labels (converted to strings). -// * slices, arrays (converted to lists). -// * maps (converted to select expressions; keys must be rules in +// - bools, integers, floats, strings. +// - labels (converted to strings). +// - slices, arrays (converted to lists). +// - maps (converted to select expressions; keys must be rules in // @io_bazel_rules_go//go/platform). -// * GlobValue (converted to glob expressions). -// * PlatformStrings (converted to a concatenation of a list and selects). +// - GlobValue (converted to glob expressions). +// - PlatformStrings (converted to a concatenation of a list and selects). // // Converting unsupported types will cause a panic. func ExprFromValue(val interface{}) bzl.Expr { @@ -216,7 +216,7 @@ func mapKeyString(k reflect.Value) string { type byString []reflect.Value -var _ sort.Interface = byString{} +var _ sort.Interface = (*byString)(nil) func (s byString) Len() int { return len(s) diff --git a/walk/config.go b/walk/config.go index 8742f79b6..c7fc675c3 100644 --- a/walk/config.go +++ b/walk/config.go @@ -62,6 +62,8 @@ func (wc *walkConfig) shouldFollow(rel, base string) bool { return matchAnyGlob(wc.follow, path.Join(rel, base)) } +var _ config.Configurer = (*Configurer)(nil) + type Configurer struct{} func (*Configurer) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config) { diff --git a/walk/walk_test.go b/walk/walk_test.go index eedb4c13a..7c3906c20 100644 --- a/walk/walk_test.go +++ b/walk/walk_test.go @@ -329,6 +329,8 @@ func testConfig(t *testing.T, dir string) (*config.Config, []config.Configurer) return c, cexts } +var _ config.Configurer = (*testConfigurer)(nil) + type testConfigurer struct { configure func(c *config.Config, rel string, f *rule.File) }