Rule Request: Favor Key Path Expressions as Functions When Using Map & Filter
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
As of Swift 5.2 you can now use a key path expression as a function when calling map/filter/etc.
I am proposing a rule that would identify & flag classic function calls that could be expressed using the new key path style.
Good
users.map(\.email)
users.filter(\.isAdmin)
Bad
users.map { $0.email }
users.filter { $0.isAdmin }
users.filter { user in
return user.isAdmin
}
I am not sure if this should be opt-in or not, but I would suggest that this be enabled by default.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Swift Evolution proposal to understand key path expressions as functions, then inspect SwiftLint's existing rule entry points and tests for map/filter-style checks. Done means the rule identifies the shown closure forms, reports them with the intended key path style, and has coverage for the provided examples and configuration decision.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100