From b82bd0c28061b5a4e779a4adf0ffa461b16b82fd Mon Sep 17 00:00:00 2001 From: Sam Boyer Date: Tue, 26 May 2015 21:52:36 -0400 Subject: [PATCH] Condense switch fallthroughs into expr lists --- .../remote-exec/resource_provisioner.go | 6 +----- config/import_tree.go | 4 +--- config/lang/lex.go | 4 +--- helper/schema/field_reader.go | 12 ++--------- helper/schema/field_reader_config.go | 8 +------- helper/schema/field_reader_diff.go | 8 +------- helper/schema/field_reader_map.go | 8 +------- helper/schema/field_writer_map.go | 8 +------- helper/schema/schema.go | 20 +++---------------- terraform/diff.go | 8 ++------ terraform/graph_config_node_resource.go | 4 +--- 11 files changed, 15 insertions(+), 75 deletions(-) diff --git a/builtin/provisioners/remote-exec/resource_provisioner.go b/builtin/provisioners/remote-exec/resource_provisioner.go index f0905b4ef..39e5f9583 100644 --- a/builtin/provisioners/remote-exec/resource_provisioner.go +++ b/builtin/provisioners/remote-exec/resource_provisioner.go @@ -51,11 +51,7 @@ func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) (ws []string num := 0 for name := range c.Raw { switch name { - case "scripts": - fallthrough - case "script": - fallthrough - case "inline": + case "scripts", "script", "inline": num++ default: es = append(es, fmt.Errorf("Unknown configuration '%s'", name)) diff --git a/config/import_tree.go b/config/import_tree.go index 829046c49..37ec11a15 100644 --- a/config/import_tree.go +++ b/config/import_tree.go @@ -33,9 +33,7 @@ type fileLoaderFunc func(path string) (configurable, []string, error) func loadTree(root string) (*importTree, error) { var f fileLoaderFunc switch ext(root) { - case ".tf": - fallthrough - case ".tf.json": + case ".tf", ".tf.json": f = loadFileHcl default: } diff --git a/config/lang/lex.go b/config/lang/lex.go index 6e70acfbc..428631788 100644 --- a/config/lang/lex.go +++ b/config/lang/lex.go @@ -299,9 +299,7 @@ func (x *parserLex) lexString(yylval *parserSymType, quoted bool) (int, bool) { // Let's check to see if we're escaping anything. if c == '\\' { switch n := x.next(); n { - case '\\': - fallthrough - case '"': + case '\\', '"': c = n case 'n': c = '\n' diff --git a/helper/schema/field_reader.go b/helper/schema/field_reader.go index cc4a1d186..fc2a1e090 100644 --- a/helper/schema/field_reader.go +++ b/helper/schema/field_reader.go @@ -78,19 +78,11 @@ func addrToSchema(addr []string, schemaMap map[string]*Schema) []*Schema { } switch t := current.Type; t { - case TypeBool: - fallthrough - case TypeInt: - fallthrough - case TypeFloat: - fallthrough - case TypeString: + case TypeBool, TypeInt, TypeFloat, TypeString: if len(addr) > 0 { return nil } - case TypeList: - fallthrough - case TypeSet: + case TypeList, TypeSet: switch v := current.Elem.(type) { case *Resource: current = &Schema{ diff --git a/helper/schema/field_reader_config.go b/helper/schema/field_reader_config.go index a6edef099..69b63eac7 100644 --- a/helper/schema/field_reader_config.go +++ b/helper/schema/field_reader_config.go @@ -80,13 +80,7 @@ func (r *ConfigFieldReader) readField( k := strings.Join(address, ".") schema := schemaList[len(schemaList)-1] switch schema.Type { - case TypeBool: - fallthrough - case TypeFloat: - fallthrough - case TypeInt: - fallthrough - case TypeString: + case TypeBool, TypeFloat, TypeInt, TypeString: return r.readPrimitive(k, schema) case TypeList: return readListField(&nestedConfigFieldReader{r}, address, schema) diff --git a/helper/schema/field_reader_diff.go b/helper/schema/field_reader_diff.go index bfac2a0b0..aac053502 100644 --- a/helper/schema/field_reader_diff.go +++ b/helper/schema/field_reader_diff.go @@ -39,13 +39,7 @@ func (r *DiffFieldReader) ReadField(address []string) (FieldReadResult, error) { schema := schemaList[len(schemaList)-1] switch schema.Type { - case TypeBool: - fallthrough - case TypeInt: - fallthrough - case TypeFloat: - fallthrough - case TypeString: + case TypeBool, TypeInt, TypeFloat, TypeString: return r.readPrimitive(address, schema) case TypeList: return readListField(r, address, schema) diff --git a/helper/schema/field_reader_map.go b/helper/schema/field_reader_map.go index a4345cbcd..6dc76c474 100644 --- a/helper/schema/field_reader_map.go +++ b/helper/schema/field_reader_map.go @@ -21,13 +21,7 @@ func (r *MapFieldReader) ReadField(address []string) (FieldReadResult, error) { schema := schemaList[len(schemaList)-1] switch schema.Type { - case TypeBool: - fallthrough - case TypeInt: - fallthrough - case TypeFloat: - fallthrough - case TypeString: + case TypeBool, TypeInt, TypeFloat, TypeString: return r.readPrimitive(address, schema) case TypeList: return readListField(r, address, schema) diff --git a/helper/schema/field_writer_map.go b/helper/schema/field_writer_map.go index 53e467650..3e9b04719 100644 --- a/helper/schema/field_writer_map.go +++ b/helper/schema/field_writer_map.go @@ -74,13 +74,7 @@ func (w *MapFieldWriter) set(addr []string, value interface{}) error { schema := schemaList[len(schemaList)-1] switch schema.Type { - case TypeBool: - fallthrough - case TypeInt: - fallthrough - case TypeFloat: - fallthrough - case TypeString: + case TypeBool, TypeInt, TypeFloat, TypeString: return w.setPrimitive(addr, value, schema) case TypeList: return w.setList(addr, value, schema) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 67b7ba78b..729fb0980 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -378,13 +378,7 @@ func (m schemaMap) Input( var value interface{} switch v.Type { - case TypeBool: - fallthrough - case TypeInt: - fallthrough - case TypeFloat: - fallthrough - case TypeSet: + case TypeBool, TypeInt, TypeFloat, TypeSet: continue case TypeString: value, err = m.inputString(input, k, v) @@ -522,13 +516,7 @@ func (m schemaMap) diff( all bool) error { var err error switch schema.Type { - case TypeBool: - fallthrough - case TypeInt: - fallthrough - case TypeFloat: - fallthrough - case TypeString: + case TypeBool, TypeInt, TypeFloat, TypeString: err = m.diffString(k, schema, diff, d, all) case TypeList: err = m.diffList(k, schema, diff, d, all) @@ -1170,9 +1158,7 @@ func (m schemaMap) validateType( var ws []string var es []error switch schema.Type { - case TypeSet: - fallthrough - case TypeList: + case TypeSet, TypeList: ws, es = m.validateList(k, raw, schema, c) case TypeMap: ws, es = m.validateMap(k, raw, schema, c) diff --git a/terraform/diff.go b/terraform/diff.go index 7cd907422..d77cd77d3 100644 --- a/terraform/diff.go +++ b/terraform/diff.go @@ -149,15 +149,11 @@ func (d *ModuleDiff) ChangeType() DiffChangeType { for _, r := range d.Resources { change := r.ChangeType() switch change { - case DiffCreate: - fallthrough - case DiffDestroy: + case DiffCreate, DiffDestroy: if result == DiffNone { result = change } - case DiffDestroyCreate: - fallthrough - case DiffUpdate: + case DiffDestroyCreate, DiffUpdate: result = DiffUpdate } } diff --git a/terraform/graph_config_node_resource.go b/terraform/graph_config_node_resource.go index bf1803b00..936398d2a 100644 --- a/terraform/graph_config_node_resource.go +++ b/terraform/graph_config_node_resource.go @@ -148,9 +148,7 @@ func (n *GraphNodeConfigResource) DynamicExpand(ctx EvalContext) (*Graph, error) // Primary and non-destroy modes are responsible for creating/destroying // all the nodes, expanding counts. switch n.DestroyMode { - case DestroyNone: - fallthrough - case DestroyPrimary: + case DestroyNone, DestroyPrimary: steps = append(steps, &ResourceCountTransformer{ Resource: n.Resource, Destroy: n.DestroyMode != DestroyNone,