From a8045c1d0c98a3beda14e01665b3be8b82796508 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Thu, 23 Jul 2026 23:32:24 -0400 Subject: [PATCH] refactor: remove redundant else branches Removes unnecessary `else` clauses after terminating statements. Signed-off-by: Ryan Johnson --- acctest/pluginacc.go | 10 +++++----- acctest/provisioneracc/provisioners.go | 6 +++--- multistep/commonsteps/multistep_runner.go | 4 ++-- rpc/build_test.go | 4 ++-- sdk-internals/communicator/ssh/communicator.go | 18 +++++++++--------- template/config/custom_types.go | 4 ++-- template/interpolate/funcs.go | 4 ++-- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/acctest/pluginacc.go b/acctest/pluginacc.go index 30379dfb0..1184b1f55 100644 --- a/acctest/pluginacc.go +++ b/acctest/pluginacc.go @@ -116,9 +116,9 @@ func TestPlugin(t *testing.T, testCase *PluginTestCase) { "acceptance test template can be found at %s", err.Error(), filepath.Join(cwd, initLogfile), filepath.Join(cwd, templatePath)) - } else { - os.Remove(initLogfile) } + + os.Remove(initLogfile) } } @@ -156,8 +156,8 @@ func TestPlugin(t *testing.T, testCase *PluginTestCase) { "acceptance test template can be found at %s", checkErr.Error(), filepath.Join(cwd, logfile), filepath.Join(cwd, templatePath)) - } else { - os.Remove(templatePath) - os.Remove(logfile) } + + os.Remove(templatePath) + os.Remove(logfile) } diff --git a/acctest/provisioneracc/provisioners.go b/acctest/provisioneracc/provisioners.go index aacce40da..38d3bb7a0 100644 --- a/acctest/provisioneracc/provisioners.go +++ b/acctest/provisioneracc/provisioners.go @@ -248,10 +248,10 @@ func TestProvisionersAgainstBuilders(testCase *ProvisionerTestCase, t *testing.T "acceptance test template can be found at %s", checkErr.Error(), filepath.Join(cwd, logfile), filepath.Join(cwd, templatePath)) - } else { - os.Remove(templatePath) - os.Remove(logfile) } + + os.Remove(templatePath) + os.Remove(logfile) }) } } diff --git a/multistep/commonsteps/multistep_runner.go b/multistep/commonsteps/multistep_runner.go index 1a405eee0..a8d085b74 100644 --- a/multistep/commonsteps/multistep_runner.go +++ b/multistep/commonsteps/multistep_runner.go @@ -44,9 +44,9 @@ func newRunner(steps []multistep.Step, config common.PackerConfig, ui packersdk. if config.PackerDebug { pauseFn := MultistepDebugFn(ui) return &multistep.DebugRunner{Steps: steps, PauseFn: pauseFn}, pauseFn - } else { - return &multistep.BasicRunner{Steps: steps}, nil } + + return &multistep.BasicRunner{Steps: steps}, nil } // NewRunner returns a multistep.Runner that runs steps augmented with support diff --git a/rpc/build_test.go b/rpc/build_test.go index c23d03c9c..f29149bed 100644 --- a/rpc/build_test.go +++ b/rpc/build_test.go @@ -48,9 +48,9 @@ func (b *testBuild) Run(ctx context.Context, ui packersdk.Ui) ([]packersdk.Artif if b.errRunResult { return nil, errors.New("foo") - } else { - return []packersdk.Artifact{testBuildArtifact}, nil } + + return []packersdk.Artifact{testBuildArtifact}, nil } func (b *testBuild) SetDebug(bool) { diff --git a/sdk-internals/communicator/ssh/communicator.go b/sdk-internals/communicator/ssh/communicator.go index f4170cd97..64bfaeadd 100644 --- a/sdk-internals/communicator/ssh/communicator.go +++ b/sdk-internals/communicator/ssh/communicator.go @@ -179,18 +179,18 @@ func (c *comm) Start(ctx context.Context, cmd *packersdk.RemoteCmd) (err error) func (c *comm) Upload(path string, input io.Reader, fi *os.FileInfo) error { if c.config.UseSftp { return c.sftpUploadSession(path, input, fi) - } else { - return c.scpUploadSession(path, input, fi) } + + return c.scpUploadSession(path, input, fi) } func (c *comm) UploadDir(dst string, src string, excl []string) error { log.Printf("[DEBUG] Upload dir '%s' to '%s'", src, dst) if c.config.UseSftp { return c.sftpUploadDirSession(dst, src, excl) - } else { - return c.scpUploadDirSession(dst, src, excl) } + + return c.scpUploadDirSession(dst, src, excl) } func (c *comm) DownloadDir(src string, dst string, excl []string) error { @@ -288,9 +288,9 @@ func (c *comm) newSession() (session *ssh.Session, err error) { if c.client == nil { return nil, errors.New("client not available") - } else { - return c.client.NewSession() } + + return c.client.NewSession() } return session, nil @@ -695,10 +695,10 @@ func (c *comm) scpUploadDirSession(dst string, src string, excl []string) error return err } return scpUploadDirProtocol(srcBase, w, r, uploadEntries, fi) - } else { - // Trailing slash, so only upload the contents - return uploadEntries() } + + // Trailing slash, so only upload the contents + return uploadEntries() } return c.scpSession("scp -rvt "+dst, scpFunc) diff --git a/template/config/custom_types.go b/template/config/custom_types.go index 843545d63..a2219dc29 100644 --- a/template/config/custom_types.go +++ b/template/config/custom_types.go @@ -53,9 +53,9 @@ func TrileanFromString(s string) (Trilean, error) { return TriUnset, err } else if b { return TriTrue, nil - } else { - return TriFalse, nil } + + return TriFalse, nil } func TrileanFromBool(b bool) Trilean { diff --git a/template/interpolate/funcs.go b/template/interpolate/funcs.go index 41bf60f4d..97287a38a 100644 --- a/template/interpolate/funcs.go +++ b/template/interpolate/funcs.go @@ -174,9 +174,9 @@ func passthroughOrInterpolate(data map[interface{}]interface{}, s string) (strin // TODO match against an actual string constant if strings.Contains(hp, packerbuilderdata.PlaceholderMsg) { return fmt.Sprintf("{{.%s}}", s), nil - } else { - return hp, nil } + + return hp, nil } } return "", fmt.Errorf("loaded data, but couldnt find %s in it.", s)