SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

`unused-parameter` rule should not trigger on binding closure parameter

Open sindresorhus opened this issue 1 year ago • 1 comments

New Issue Checklist

Bug Description

The rule triggers on $historyItem, but the parameter is kinda used. $historyItem results in a binding, but it also makes it possible to access the normal variable with historyItem implicitly. So even though $historyItem is not directly used, it cannot be removed.

List($history) { $historyItem in
	Foo(
		url: historyItem.url
	)
}

In short, make it not trigger on $-prefixed parameters in a closure.

Environment

  • SwiftLint version: 0.56.0
  • Xcode version: Xcode 15.4, Build version 15F31d
  • Installation method used: Installer
  • Configuration file:
only_rules:
  - unused_parameter

sindresorhus avatar Aug 08 '24 13:08 sindresorhus

Since $_ is allowed as a parameter, the same rules used for normal parameters apply here as well. In the example, if any of $historyItem or historyItem is used in the closure block, $historyItem can be considered to be used. If there is no reference at all, it can be replaced with $_ (or $_historyItem once that's implemented).

However, silencing the rule completely for $-prefixed parameters might be too cautious.

SimplyDanny avatar Aug 21 '24 16:08 SimplyDanny