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_enumerated rule should also check closure parameters #5470

Closed
SimplyDanny opened this issue Feb 22, 2024 · 1 comment
Closed

unused_enumerated rule should also check closure parameters #5470

SimplyDanny opened this issue Feb 22, 2024 · 1 comment
Labels
enhancement Ideas for improvements of existing features and rules.

Comments

@SimplyDanny
Copy link
Collaborator

The unused_enumerated rule triggers when either of the two values returned by .enumerated() isn't used (replaced by an underscore _). The rule currently checks only for loops. It could be extended to support closure parameters as well.

The rule would only check the immediate closure after the .enumerated() call. Otherwise, the number of parameters and their types could have changed.

Triggering:

list.enumerated().map { idx, _ in idx }

list.enumerated().map { _, elem in elem }

list.enumerated().forEach { print($0) }

list.enumerated().map { $1 }

Non-triggering:

list.enumerated().map { idx, elem in "\(idx): \(elem)" }

list.enumerated().map { $0 + $1 }

list.enumerated().something().map { _, elem in elem }

PS: This enhancement was motivated by this comment.

@SimplyDanny SimplyDanny added the enhancement Ideas for improvements of existing features and rules. label Feb 22, 2024
@mildm8nnered
Copy link
Collaborator

I am playing around with some fixes for this ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Ideas for improvements of existing features and rules.
Projects
None yet
Development

No branches or pull requests

2 participants