Skip to content

Commit

Permalink
Merge pull request #46 from spzala/deepcopylintifelse
Browse files Browse the repository at this point in the history
Fix if loop related lint failures in the deepcopy-gen
  • Loading branch information
thockin authored Apr 27, 2017
2 parents 7e5c445 + a438c28 commit af11bb5
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions examples/deepcopy-gen/generators/deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,12 @@ func (g *genDeepCopy) doMap(t *types.Type, sw *generator.SnippetWriter) {
sw.Do("}\n", nil)
sw.Do("(*out)[key] = *newVal\n", nil)
} else {
sw.Do("if newVal, err := c.DeepCopy(&val); err != nil {\n", nil)
sw.Do("newVal, err := c.DeepCopy(&val)\n", nil)
sw.Do("if err != nil {\n", nil)
sw.Do("return err\n", nil)
sw.Do("} else {\n", nil)
sw.Do("(*out)[key] = *newVal.(*$.|raw$)\n", t.Elem)
sw.Do("}\n", nil)
sw.Do("(*out)[key] = *newVal.(*$.|raw$)\n", t.Elem)
sw.Do("\n", nil)
}
sw.Do("}\n", nil)
}
Expand Down Expand Up @@ -564,11 +565,12 @@ func (g *genDeepCopy) doSlice(t *types.Type, sw *generator.SnippetWriter) {
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
} else {
sw.Do("if newVal, err := c.DeepCopy(&(*in)[i]); err != nil {\n", nil)
sw.Do("newVal, err := c.DeepCopy(&(*in)[i])\n", nil)
sw.Do("if err != nil {\n", nil)
sw.Do("return err\n", nil)
sw.Do("} else {\n", nil)
sw.Do("(*out)[i] = *newVal.(*$.|raw$)\n", t.Elem)
sw.Do("}\n", nil)
sw.Do("(*out)[i] = *newVal.(*$.|raw$)\n", t.Elem)
sw.Do("\n", nil)
}
sw.Do("}\n", nil)
}
Expand Down Expand Up @@ -628,11 +630,12 @@ func (g *genDeepCopy) doStruct(t *types.Type, sw *generator.SnippetWriter) {
} else {
// Fall back on the slow-path and hope it works.
// TODO: don't depend on kubernetes code for this
sw.Do("if newVal, err := c.DeepCopy(&in.$.name$); err != nil {\n", args)
sw.Do("newVal, err := c.DeepCopy(&in.$.name$)\n", args)
sw.Do("if err != nil {\n", nil)
sw.Do("return err\n", nil)
sw.Do("} else {\n", nil)
sw.Do("out.$.name$ = *newVal.(*$.type|raw$)\n", args)
sw.Do("}\n", nil)
sw.Do("out.$.name$ = *newVal.(*$.type|raw$)\n", args)
sw.Do("\n", nil)
}
default:
// Interfaces, Arrays, and other Kinds we don't understand.
Expand All @@ -644,11 +647,12 @@ func (g *genDeepCopy) doStruct(t *types.Type, sw *generator.SnippetWriter) {
} else {
// TODO: don't depend on kubernetes code for this
sw.Do("if in.$.name$ != nil {\n", args)
sw.Do("if newVal, err := c.DeepCopy(&in.$.name$); err != nil {\n", args)
sw.Do("newVal, err := c.DeepCopy(&in.$.name$)\n", args)
sw.Do("if err != nil {\n", nil)
sw.Do("return err\n", nil)
sw.Do("} else {\n", nil)
sw.Do("out.$.name$ = *newVal.(*$.type|raw$)\n", args)
sw.Do("}\n", nil)
sw.Do("out.$.name$ = *newVal.(*$.type|raw$)\n", args)
sw.Do("\n", nil)
sw.Do("}\n", nil)
}
}
Expand All @@ -673,11 +677,12 @@ func (g *genDeepCopy) doPointer(t *types.Type, sw *generator.SnippetWriter) {
sw.Do("return err\n", nil)
sw.Do("}\n", nil)
} else {
sw.Do("if newVal, err := c.DeepCopy(*in); err != nil {\n", nil)
sw.Do("newVal, err := c.DeepCopy(*in)\n", nil)
sw.Do("if err != nil {\n", nil)
sw.Do("return err\n", nil)
sw.Do("} else {\n", nil)
sw.Do("*out = newVal.(*$.|raw$)\n", t.Elem)
sw.Do("}\n", nil)
sw.Do("*out = newVal.(*$.|raw$)\n", t.Elem)
sw.Do("\n", nil)
}
}

Expand Down

0 comments on commit af11bb5

Please # to comment.