lang/funcs: staticcheck

This commit is contained in:
James Bardin 2020-12-01 16:09:08 -05:00
parent a5f013830f
commit e08422511e
3 changed files with 0 additions and 49 deletions

View File

@ -196,30 +196,6 @@ var IndexFunc = function.New(&function.Spec{
}, },
}) })
// Flatten until it's not a cty.List, and return whether the value is known.
// We can flatten lists with unknown values, as long as they are not
// lists themselves.
func flattener(flattenList cty.Value) ([]cty.Value, bool) {
out := make([]cty.Value, 0)
for it := flattenList.ElementIterator(); it.Next(); {
_, val := it.Element()
if val.Type().IsListType() || val.Type().IsSetType() || val.Type().IsTupleType() {
if !val.IsKnown() {
return out, false
}
res, known := flattener(val)
if !known {
return res, known
}
out = append(out, res...)
} else {
out = append(out, val)
}
}
return out, true
}
// LookupFunc constructs a function that performs dynamic lookups of map types. // LookupFunc constructs a function that performs dynamic lookups of map types.
var LookupFunc = function.New(&function.Spec{ var LookupFunc = function.New(&function.Spec{
Params: []function.Parameter{ Params: []function.Parameter{
@ -537,20 +513,6 @@ var MapFunc = function.New(&function.Spec{
}, },
}) })
// helper function to add an element to a list, if it does not already exist
func appendIfMissing(slice []cty.Value, element cty.Value) ([]cty.Value, error) {
for _, ele := range slice {
eq, err := stdlib.Equal(ele, element)
if err != nil {
return slice, err
}
if eq.True() {
return slice, nil
}
}
return append(slice, element), nil
}
// Length returns the number of elements in the given collection or number of // Length returns the number of elements in the given collection or number of
// Unicode characters in the given string. // Unicode characters in the given string.
func Length(collection cty.Value) (cty.Value, error) { func Length(collection cty.Value) (cty.Value, error) {

View File

@ -68,8 +68,6 @@ var DefaultsFunc = function.New(&function.Spec{
}) })
func defaultsApply(input, fallback cty.Value) cty.Value { func defaultsApply(input, fallback cty.Value) cty.Value {
const fallbackArgIdx = 1
wantTy := input.Type() wantTy := input.Type()
if !(input.IsKnown() && fallback.IsKnown()) { if !(input.IsKnown() && fallback.IsKnown()) {
return cty.UnknownVal(wantTy) return cty.UnknownVal(wantTy)

View File

@ -162,15 +162,6 @@ func (s *Scope) Functions() map[string]function.Function {
return s.funcs return s.funcs
} }
var unimplFunc = function.New(&function.Spec{
Type: func([]cty.Value) (cty.Type, error) {
return cty.DynamicPseudoType, fmt.Errorf("function not yet implemented")
},
Impl: func([]cty.Value, cty.Type) (cty.Value, error) {
return cty.DynamicVal, fmt.Errorf("function not yet implemented")
},
})
// experimentalFunction checks whether the given experiment is enabled for // experimentalFunction checks whether the given experiment is enabled for
// the recieving scope. If so, it will return the given function verbatim. // the recieving scope. If so, it will return the given function verbatim.
// If not, it will return a placeholder function that just returns an // If not, it will return a placeholder function that just returns an