Skip to content

Commit d3581a8

Browse files
committed
fix: resolve deferUnlambda linting issues by simplifying defer statements
Fixed occurrences of unnecessary function wrapping in defer statements in: - provisionerd/provisionerd.go - enterprise/coderd/proxyhealth/proxyhealth.go - cli/ssh.go - coderd/devtunnel/tunnel_test.go This improves code readability by using the direct form of defer when possible.
1 parent 9b0a218 commit d3581a8

File tree

4 files changed

+6
-10
lines changed

4 files changed

+6
-10
lines changed

cli/ssh.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,16 +452,12 @@ func (r *RootCmd) ssh() *serpent.Command {
452452
if err != nil {
453453
return err
454454
}
455-
defer func() {
456-
_ = pty.RestoreTerminal(stdinFile.Fd(), inState)
457-
}()
455+
defer pty.RestoreTerminal(stdinFile.Fd(), inState)
458456
outState, err := pty.MakeOutputRaw(stdoutFile.Fd())
459457
if err != nil {
460458
return err
461459
}
462-
defer func() {
463-
_ = pty.RestoreTerminal(stdoutFile.Fd(), outState)
464-
}()
460+
defer pty.RestoreTerminal(stdoutFile.Fd(), outState)
465461

466462
windowChange := listenWindowSize(ctx)
467463
go func() {

coderd/devtunnel/tunnel_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ func TestTunnel(t *testing.T) {
111111
err := server.Serve(tun.Listener)
112112
assert.Equal(t, http.ErrServerClosed, err)
113113
}()
114-
defer func() { _ = server.Close() }()
115-
defer func() { tun.Listener.Close() }()
114+
defer server.Close()
115+
defer tun.Listener.Close()
116116

117117
require.Eventually(t, func() bool {
118118
req, err := http.NewRequestWithContext(ctx, http.MethodGet, tun.URL.String(), nil)

enterprise/coderd/proxyhealth/proxyhealth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (p *ProxyHealth) ProxyHosts() []string {
216216
// unreachable.
217217
func (p *ProxyHealth) runOnce(ctx context.Context, now time.Time) (map[uuid.UUID]ProxyStatus, error) {
218218
// Record from the given time.
219-
defer func() { p.healthCheckDuration.Observe(time.Since(now).Seconds()) }()
219+
defer p.healthCheckDuration.Observe(time.Since(now).Seconds())
220220

221221
//nolint:gocritic // Proxy health is a system service.
222222
proxies, err := p.db.GetWorkspaceProxies(dbauthz.AsSystemRestricted(ctx))

provisionerd/provisionerd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func (p *Server) client() (proto.DRPCProvisionerDaemonClient, bool) {
288288
func (p *Server) acquireLoop() {
289289
defer p.opts.Logger.Debug(p.closeContext, "acquire loop exited")
290290
defer p.wg.Done()
291-
defer func() { close(p.acquireDoneCh) }()
291+
defer close(p.acquireDoneCh)
292292
ctx := p.closeContext
293293
for {
294294
if p.acquireExit() {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy