Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add nil assignments to verify interface implementations #1883

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/gazelle/fix-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/gazelle/metaresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions cmd/gazelle/update-repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions internal/gazellebinarytest/xlang.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"github.com/bazelbuild/bazel-gazelle/rule"
)

var _ config.Configurer = (*xlang)(nil)

type xlang struct{}

func NewLanguage() language.Language {
Expand Down
2 changes: 2 additions & 0 deletions resolve/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions rule/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions rule/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions walk/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions walk/walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down