let only calls a member on its argument, which a plain or safe call does directly
What it finds
user?.let { it.save() } is user?.save(), and name.let { it.trim() } is name.trim(). The lambda adds a level of reading for nothing.
From the rule's source, unnecessary_let.rs.
fun save(user: User?, name: String) { user?.let { it.save() }tx0 reports: let only calls a member on its argument name.let { value -> value.trim() }tx0 reports: let only calls a member user?.let { store(it) } user?.let { it.copy(name = it.name) }} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:unnecessary-let" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:unnecessary-let] reason="..."tx0 explain tx0/kotlin:unnecessary-let shows the same in the terminal. Found a false positive? Report it.