Redundant Discardable Let

ID

swift.redundant_discardable_let

Severity

info

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Swift

Tags

code-smell, style

Description

Reports a let _ = expr binding. The let adds nothing because the value is immediately discarded into the wildcard pattern. The idiomatic form is _ = expr.

let _ = sideEffect()        // FLAW
let _ = "ignored"           // FLAW

_ = sideEffect()            // OK
let x = sideEffect()        // OK — value bound to `x`
let (a, _) = (1, 2)         // OK — wildcard inside a tuple still has meaning

Rationale

let _ = expr declares no binding — the wildcard pattern discards the value. The let keyword survives only as a leftover from copy-pasted assignments, signalling to readers that something is being captured when nothing actually is. The plain _ = expr form makes the discard explicit.

Remediation

Drop the let:

_ = sideEffect()