Skip to content

Commit

Permalink
refactor: add rule.* type assertions (#1961)
Browse files Browse the repository at this point in the history
**What type of PR is this?**

> Other

**What package or component does this PR mostly affect?**

> all
  • Loading branch information
jbedard authored Oct 23, 2024
1 parent 2a84bad commit 5254d18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rule/platform_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ type PlatformStrings struct {
Platform map[PlatformConstraint][]string
}

var _ BzlExprValue = (*PlatformStrings)(nil)

// HasExt returns whether this set contains a file with the given extension.
func (ps *PlatformStrings) HasExt(ext string) bool {
return ps.firstExtFile(ext) != ""
Expand Down
9 changes: 9 additions & 0 deletions rule/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type GlobValue struct {
Excludes []string
}

var _ BzlExprValue = (*GlobValue)(nil)

func (g GlobValue) BzlExpr() bzl.Expr {
patternsValue := ExprFromValue(g.Patterns)
globArgs := []bzl.Expr{patternsValue}
Expand Down Expand Up @@ -72,6 +74,9 @@ type Merger interface {

type SortedStrings []string

var _ BzlExprValue = SortedStrings(nil)
var _ Merger = SortedStrings(nil)

func (s SortedStrings) BzlExpr() bzl.Expr {
list := make([]bzl.Expr, len(s))
for i, v := range s {
Expand All @@ -93,6 +98,8 @@ func (s SortedStrings) Merge(other bzl.Expr) bzl.Expr {

type UnsortedStrings []string

var _ Merger = UnsortedStrings(nil)

func (s UnsortedStrings) Merge(other bzl.Expr) bzl.Expr {
if other == nil {
return ExprFromValue(s)
Expand All @@ -104,6 +111,8 @@ func (s UnsortedStrings) Merge(other bzl.Expr) bzl.Expr {
// select expression that picks a string list based on a string condition.
type SelectStringListValue map[string][]string

var _ BzlExprValue = SelectStringListValue(nil)

func (s SelectStringListValue) BzlExpr() bzl.Expr {
defaultKey := "//conditions:default"
keys := make([]string, 0, len(s))
Expand Down

0 comments on commit 5254d18

Please sign in to comment.