Skip to content

Commit

Permalink
fix(cli): support orion properties with no declared default (#7539)
Browse files Browse the repository at this point in the history
Plugin properties should not require explicit defaults.

---

### Changes are visible to end-users: yes

- Searched for relevant documentation and updated as needed: yes
- Breaking change (forces users to change their own code or config): no
- Suggested release notes appear below: yes

Orion plugin property declarations no longer require a default.

### Test plan

- Covered by existing test cases
- New test cases added

GitOrigin-RevId: 463a7bd63fb13ea265eb4fc923fc0f3f617d0865
  • Loading branch information
jbedard committed Dec 13, 2024
1 parent c720cef commit 8943eaa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
14 changes: 4 additions & 10 deletions gazelle/common/starlark/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,12 @@ func Write(v interface{}) starlark.Value {
return starlark.MakeInt64(v)
case float64:
return starlark.Float(v)
case []string:
return WriteList(v, WriteString)
case []interface{}:
l := make([]starlark.Value, 0, len(v))
for _, lv := range v {
l = append(l, Write(lv))
}
return starlark.NewList(l)
return WriteList(v, Write)
case map[string]interface{}:
d := starlark.NewDict(len(v))
for k, lv := range v {
d.SetKey(starlark.String(k), Write(lv))
}
return d
return WriteMap(v, Write)
}

log.Panicf("Failed to write value %v of type %q", v, reflect.TypeOf(v))
Expand Down
19 changes: 19 additions & 0 deletions gazelle/common/starlark/utils/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ func TestReadWrite(t *testing.T) {
}
})

t.Run("[]string => List", func(t *testing.T) {
a := []string{"a", "b"}
l := Write(a).(*starlark.List)

if len(a) != l.Len() {
t.Errorf("Expected equal length")
}

l0, isString := l.Index(0).(starlark.String)
if !isString || a[0] != l0.GoString() {
t.Errorf("Expected %v to be String", l0)
}

l1, isString := l.Index(1).(starlark.String)
if !isString || a[1] != l1.GoString() {
t.Errorf("Expected %v to be String", l1)
}
})

t.Run("List <=> []interface{}", func(t *testing.T) {
l := starlark.NewList([]starlark.Value{starlark.MakeInt(1), starlark.String("hello"), starlark.Bool(true)})
a := Read(l).([]interface{})
Expand Down

0 comments on commit 8943eaa

Please sign in to comment.