Skip to content

Commit

Permalink
Address staticcheck errors
Browse files Browse the repository at this point in the history
  • Loading branch information
wozniakjan committed Jun 7, 2022
1 parent 1bf0270 commit 88b9a42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pkg/in_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func Print(pkg, boilerplate string, imports []Import, vars []RawVar, kubermatic
printLines(vars, &buf, kubermatic)
formatted, err := format.Source(buf.Bytes())
if err != nil {
fmt.Printf("%v", string(buf.Bytes()))
fmt.Printf("%v", buf.String())
checkFatal(err)
}
fmt.Printf("%v", string(formatted))
Expand All @@ -113,7 +113,7 @@ func readFile(path string) (all [][]byte) {
data, err := os.ReadFile(path)
checkFatal(err)
split := strings.Split(string(data), "---")
for i, _ := range split {
for i := range split {
if len(split[i]) != 0 {
all = append(all, []byte(split[i]))
}
Expand Down
17 changes: 7 additions & 10 deletions pkg/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ func processKubermatic(pc processingContext) {
last.lines = append(last.lines, fmt.Sprintf("return func() (string, reconciling.%vCreator) {", te.Name()))
last.lines = append(last.lines, fmt.Sprintf("t := %v.DeepCopy()", varName))
last.lines = append(last.lines, fmt.Sprintf("return t.Name, func(o *%v) (*%v, error) {", typeName, typeName))
last.lines = append(last.lines, fmt.Sprintf("return t, nil"))
last.lines = append(last.lines, fmt.Sprintf("}"))
last.lines = append(last.lines, fmt.Sprintf("}"))
last.lines = append(last.lines, fmt.Sprintf("}"))
last.lines = append(last.lines, "return t, nil")
last.lines = append(last.lines, "}")
last.lines = append(last.lines, "}")
last.lines = append(last.lines, "}")
}

func sortMapKeys(keys []reflect.Value) []reflect.Value {
Expand Down Expand Up @@ -258,7 +258,7 @@ func processUnstructured(pc processingContext, onlyMeta bool) {
case map[string]any:
last.lines[len(last.lines)-1] += "map[string]any{"
keys := make([]string, 0, len(o))
for k, _ := range o {
for k := range o {
pc2 := pc.new(pathElement{name: k}, "", o[k], reflect.Map)
if onlyMeta && !unstructuredMetaKeep(pc2, k) {
continue
Expand All @@ -273,14 +273,14 @@ func processUnstructured(pc processingContext, onlyMeta bool) {
processUnstructured(pc2, onlyMeta)
}
}
last.lines = append(last.lines, fmt.Sprintf("},"))
last.lines = append(last.lines, "},")
case []any:
last.lines[len(last.lines)-1] += "[]any{\n"
for _, e := range o {
pc2 := pc.new(pathElement{}, "", e, reflect.Slice)
processUnstructured(pc2, onlyMeta)
}
last.lines = append(last.lines, fmt.Sprintf("},"))
last.lines = append(last.lines, "},")
case string:
last.lines[len(last.lines)-1] += fmt.Sprintf("%q,", pc.o)
default:
Expand Down Expand Up @@ -358,7 +358,6 @@ func processKubernetes(pc processingContext) {
last.lines = append(last.lines, fmt.Sprintf("%v: map[%v%v]%v%v{", pc.name, keyNi, keyElem.Name(), valNi, valElem.Name()))
keys := sortMapKeys(ve.MapKeys())
for _, keyTyped := range keys {
last := &(*pc.rawVars)[len((*pc.rawVars))-1]
// convert back the sorted key to the underlying type
key := keyTyped.Convert(keyElem)
val := ve.MapIndex(key)
Expand Down Expand Up @@ -401,8 +400,6 @@ func processKubernetes(pc processingContext) {
}
last.lines = append(last.lines, fmt.Sprintf("%v%v%v,", ltype, ptrDeref, varName))
}

return
}

func helperLine(pc processingContext, typeName string, kind reflect.Kind, ifc any) (string, string) {
Expand Down

0 comments on commit 88b9a42

Please sign in to comment.