New `optional_map` rule
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
New Rule Request
Please add an optional_map rule.
It would change:
if let nonOptional = optional {a} else {b}tooptional.map {a} ?? bif let nonOptional = optional {a}tooptional.map {a}.if let optional {a} else {b}tooptional.map {a} ?? bif let optional {a}tooptional.map {a}.
(same for all variants of if var …)
If a can be nil, then flatMap (instead of map) would be used.
It could also apply to switches that are the equivalent of if-else, but I assume those are rare.
Maybe a rule already exists to convert from such a switch to an equivalent if-else
Maybe this rule could be limited to assignments / returns / etc., or have parameters to limit its scope.
I imagine that it should be opt-in, because maybe not everyone will agree with my preference for the concision of optional.map, but if there was a consensus that optional.map should be used (at least in certain circumstances), then it could be a default rule.
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
No files, tests, or entry points are named. Start by locating SwiftLint's existing rule implementations and tests, then resolve the scope and opt-in behavior for the listed if-let and if-var forms, including when to use map versus flatMap; done means the agreed forms are detected and covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100