@@ -82,7 +82,8 @@ func (b *View) Apply(f *File) ([]ScopedValues, error) {
8282
8383 found := make ([]ScopedValues , 0 , len (b .Scopes ))
8484 for _ , s := range b .Scopes {
85- values , err := selectStrings (value , s .Expr )
85+ var values []string
86+ values , err = selectStrings (value , s .Expr )
8687 if err != nil {
8788 return nil , fmt .Errorf ("processing scope %q: %w" , s .Name , err )
8889 }
@@ -102,21 +103,21 @@ func selectStrings(value DaselValue, expr string) ([]string, error) {
102103 return selectStringsV2 (value , expr )
103104 }
104105
105- outer , ok := selected .([]any )
106- if ! ok {
106+ outer , isSlice := selected .([]any )
107+ if ! isSlice {
107108 return nil , fmt .Errorf ("expected []any, got %T" , selected )
108109 }
109110
110111 // Unwrap single-element wrapper if present.
111112 if len (outer ) == 1 {
112- if inner , ok := outer [0 ].([]any ); ok {
113+ if inner , isInner := outer [0 ].([]any ); isInner {
113114 outer = inner
114115 }
115116 }
116117
117118 results := make ([]string , 0 , len (outer ))
118119 for _ , v := range outer {
119- if str , ok := v .(string ); ok {
120+ if str , isStr := v .(string ); isStr {
120121 results = append (results , str )
121122 }
122123 }
@@ -139,27 +140,27 @@ func selectStringsV2(value DaselValue, expr string) ([]string, error) {
139140// gopkg.in/yaml.v2) to map[string]any so that Dasel v3 can traverse the
140141// document without choking on interface{} map keys.
141142func normalize (v any ) any {
142- switch v := v .(type ) {
143+ switch val := v .(type ) {
143144 case map [interface {}]interface {}:
144- out := make (map [string ]any , len (v ))
145- for k , val := range v {
146- out [fmt .Sprintf ("%v" , k )] = normalize (val )
145+ out := make (map [string ]any , len (val ))
146+ for k , v := range val {
147+ out [fmt .Sprintf ("%v" , k )] = normalize (v )
147148 }
148149 return out
149150 case map [string ]any :
150- out := make (map [string ]any , len (v ))
151- for k , val := range v {
152- out [k ] = normalize (val )
151+ out := make (map [string ]any , len (val ))
152+ for k , v := range val {
153+ out [k ] = normalize (v )
153154 }
154155 return out
155156 case []any :
156- out := make ([]any , len (v ))
157- for i , val := range v {
158- out [i ] = normalize (val )
157+ out := make ([]any , len (val ))
158+ for i , v := range val {
159+ out [i ] = normalize (v )
159160 }
160161 return out
161162 default :
162- return v
163+ return val
163164 }
164165}
165166
@@ -195,8 +196,8 @@ func fileToValue(f *File) (DaselValue, error) {
195196 return nil , errors .New ("unsupported file type" )
196197 }
197198
198- value , ok := normalize (raw ).(map [string ]any )
199- if ! ok {
199+ value , isMap := normalize (raw ).(map [string ]any )
200+ if ! isMap {
200201 return nil , errors .New ("document root is not an object" )
201202 }
202203
0 commit comments