realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.67k stars 2.22k forks source link

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

Open sindresorhus opened 3 months ago

sindresorhus commented 3 months ago

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

only_rules:
  - unused_parameter
SimplyDanny commented 2 months ago

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.