Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
sindresorhus opened this issue Aug 8, 2024 · 1 comment
Open
2 tasks done
Labels
bug Unexpected and reproducible misbehavior.

Comments

@sindresorhus
Copy link

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
@SimplyDanny SimplyDanny added bug Unexpected and reproducible misbehavior. good first issue Issue to be taken up by new contributors yet unfamiliar with the project. labels Aug 8, 2024
@SimplyDanny
Copy link
Collaborator

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 SimplyDanny removed the good first issue Issue to be taken up by new contributors yet unfamiliar with the project. label Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

No branches or pull requests

2 participants