From 39c3e7112fefd8ae3adc48e68d56d00556feb785 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 30 Nov 2018 18:38:19 -0800 Subject: [PATCH] configs/configupgrade: Use break to cancel default function rendering We're using break elsewhere in here so it was weird to have a small set of situations that return instead, which could then cause confusion for future maintenance if a reader doesn't notice that control doesn't always leave the outer switch statement. --- configs/configupgrade/upgrade_expr.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/configs/configupgrade/upgrade_expr.go b/configs/configupgrade/upgrade_expr.go index 2a0ed37aa..c25245fef 100644 --- a/configs/configupgrade/upgrade_expr.go +++ b/configs/configupgrade/upgrade_expr.go @@ -26,6 +26,7 @@ func upgradeExpr(val interface{}, filename string, interp bool, an *analysis) ([ // of these correspond to expressions in HCL2. Therefore we need to // comprehensively handle every possible HCL1 *and* HIL AST node type // and, at minimum, print it out as-is in HCL2 syntax. +Value: switch tv := val.(type) { case *hcl1ast.LiteralType: @@ -214,14 +215,14 @@ func upgradeExpr(val interface{}, filename string, interp bool, an *analysis) ([ } } buf.WriteByte(']') - return buf.Bytes(), diags + break Value case "map": // Should now use object constructor syntax, but we can only // achieve that if the call is valid, which requires an even // number of arguments. if len(argExprs) == 0 { buf.WriteString("{}") - return buf.Bytes(), diags + break Value } else if len(argExprs)%2 == 0 { buf.WriteString("{\n") for i := 0; i < len(argExprs); i += 2 { @@ -234,7 +235,7 @@ func upgradeExpr(val interface{}, filename string, interp bool, an *analysis) ([ buf.WriteByte('\n') } buf.WriteByte('}') - return buf.Bytes(), diags + break Value } case "lookup": // A lookup call with only two arguments is equivalent to native @@ -247,7 +248,7 @@ func upgradeExpr(val interface{}, filename string, interp bool, an *analysis) ([ buf.WriteByte('[') buf.Write(argExprs[1]) buf.WriteByte(']') - return buf.Bytes(), diags + break Value } }