-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Open
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.
kapitoshka438
Metadata
Metadata
Assignees
Labels
No labels