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 rule.* type assertions #1961

Merged
merged 1 commit into from
Oct 23, 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 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