Unnecessary Let

ID

kotlin.unnecessary_let

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Kotlin

Tags

let, scope_function

Description

Reports x.let { …​ } calls whose lambda either has no statements or never references the implicit it parameter (nor the renamed alias when the lambda uses name → body).

Rationale

let is meant to scope a temporary value or transform the receiver. When the lambda body neither reads nor writes the parameter, the scope function adds nothing — the receiver could be used directly. Spurious let calls slow readers down by introducing an unused indirection and an extra closure allocation at runtime.

// Bad — empty body
val a = x.let { }

// Bad — `it` never used
val b = x.let { other.work() }

// Good — uses `it`
val c = x.let { it.length }

// Good — uses renamed parameter
val d = x.let { v -> v.length }

Remediation

Drop the let call and use the receiver directly. Reserve let for the cases where the parameter is actually used in the body — for null-safe chaining or local-scope transformations.