Skip to content

Commit

Permalink
Condense switch fallthroughs into expr lists
Browse files Browse the repository at this point in the history
  • Loading branch information
sdboyer committed May 27, 2015
1 parent a363bd9 commit b82bd0c
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 75 deletions.
6 changes: 1 addition & 5 deletions builtin/provisioners/remote-exec/resource_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions config/import_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
}
Expand Down
4 changes: 1 addition & 3 deletions config/lang/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 2 additions & 10 deletions helper/schema/field_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
8 changes: 1 addition & 7 deletions helper/schema/field_reader_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions helper/schema/field_reader_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions helper/schema/field_reader_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions helper/schema/field_writer_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 3 additions & 17 deletions helper/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions terraform/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 1 addition & 3 deletions terraform/graph_config_node_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b82bd0c

Please sign in to comment.