Skip to content

[Cleanup] Unused cancel channel field in StatusSpinner #4745

@e-gineer

Description

@e-gineer

Severity: LOW (Code Quality Issue)

Bug Summary

The cancel channel field in StatusSpinner is never initialized or used. It exists but serves no purpose, representing dead code that should be removed.

Location

  • File: pkg/statushooks/spinner.go
  • Field: StatusSpinner.cancel (line 28)
  • Usage: Only referenced in Hide() (lines 96-98) but always nil

Evidence

type StatusSpinner struct {
    spinner *spinner.Spinner
    cancel  chan struct{}  // Never initialized - always nil
    delay   time.Duration
    visible bool
}

func (s *StatusSpinner) Hide() {
    s.visible = false
    if s.cancel != nil {  // This is always false
        close(s.cancel)
    }
    s.closeSpinner()
}

The cancel channel is:

  1. Declared but never initialized (always nil)
  2. Never created with make(chan struct{})
  3. Never read from or used for cancellation
  4. The check if s.cancel != nil is always false

Reproduction

func TestSpinnerCancelChannelNeverInitialized(t *testing.T) {
    spinner := NewStatusSpinnerHook()
    
    if spinner.cancel != nil {
        t.Error("Cancel channel should be nil (it's never initialized)")
    }
    
    spinner.Show()
    spinner.Hide()
    // cancel is still nil - never used
}

Impact

  • Code Quality: Dead code adds confusion
  • Maintenance: Developers may think cancel is used for something
  • No Runtime Impact: Since it's never used, no functional impact

Proposed Fix

Remove the unused field and related code:

type StatusSpinner struct {
    spinner *spinner.Spinner
    // Remove: cancel  chan struct{}
    delay   time.Duration
    visible bool
}

func (s *StatusSpinner) Hide() {
    s.visible = false
    // Remove: if s.cancel != nil { close(s.cancel) }
    s.closeSpinner()
}

Found by: Wave 3 Task 1 (Statushooks)
Test: TestSpinnerCancelChannelNeverInitialized in pkg/statushooks/statushooks_test.go

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleNo recent activity has been detected on this issue/PR and it will be closed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions