Skip to content

Commit 1c52b8d

Browse files
committed
refactor: remove redundant else branches
Simplified control flow by removing `else` blocks that followed early `return`/halt paths. This aligns with idiomatic Go style, reduces nesting, and keeps behavior unchanged, including test expectations and state updates. Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
1 parent 7910bed commit 1c52b8d

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

builder/vmware/common/driver_parser.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,21 +2326,21 @@ func readDhcpdLeaseEntry(in chan byte) (entry *dhcpLeaseEntry, err error) {
23262326
return &dhcpLeaseEntry{extra: []string{res}}, fmt.Errorf("unable to parse lease entry (%#v)", string(lease))
23272327
}
23282328

2329-
if by, ok := <-ch; ok && by == '{' {
2330-
// If we found a lease match, and we're definitely beginning a lease
2331-
// entry, then create our storage.
2332-
entry = &dhcpLeaseEntry{address: matches[1]}
2333-
2334-
} else if ok {
2329+
by, ok := <-ch
2330+
if !ok {
2331+
// If our channel is closed, so we bail "cleanly".
2332+
return nil, nil
2333+
}
2334+
if by != '{' {
23352335
// If we didn't see a starting brace, then this entry is mangled which
23362336
// means that we should probably bail.
23372337
return &dhcpLeaseEntry{address: matches[1]}, fmt.Errorf("missing parameters for lease entry %v", matches[1])
2338-
2339-
} else {
2340-
// If our channel is closed, so we bail "cleanly".
2341-
return nil, nil
23422338
}
23432339

2340+
// If we found a lease match, and we're definitely beginning a lease
2341+
// entry, then create our storage.
2342+
entry = &dhcpLeaseEntry{address: matches[1]}
2343+
23442344
// Now we can parse the inside of the block.
23452345
for insideBraces := true; insideBraces; {
23462346
item, ok := consumeUntilSentinel(';', ch)

builder/vmware/common/driver_workstation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ func generateNetmapConfig() (string, error) {
420420

421421
if pathNetmap != "" {
422422
return pathNetmap, nil
423-
} else {
424-
return "", fmt.Errorf("no valid path found for generating the network mapper configuration file")
425423
}
424+
425+
return "", fmt.Errorf("no valid path found for generating the network mapper configuration file")
426426
}

builder/vmware/common/step_configure_vmx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ func (s *StepConfigureVMX) Run(ctx context.Context, state multistep.StateBag) mu
115115
state.Put("error", err)
116116
ui.Error(err.Error())
117117
return multistep.ActionHalt
118-
} else {
119-
state.Put("display_name", displayName)
120118
}
119+
120+
state.Put("display_name", displayName)
121121
}
122122

123123
// Set the extendedConfigFile setting for the .vmxf filename to the VMName

0 commit comments

Comments
 (0)