Rule Request: SwiftUI: Prefer scaledToFit()/scaledToFill() over aspectRatio(contentMode:) #5713
Open
2 tasks done
Labels
good first issue
Issue to be taken up by new contributors yet unfamiliar with the project.
rule-request
Requests for a new rules.
New Issue Checklist
New rule request
SwiftUI has
scaledToFit()
scaledToFill()
which are convenience methods for callingaspectRatio
with only a content mode.Since Apple considered it a common enough use case to have dedicated view modifiers for it, there should be a rule to prefer using them over the more general purpose view modifier.
Triggering cases
It just needs to be the versions where they're passed a constant.
Non-triggering cases
If a ratio is being passed or the content mode is not a constant, it should not trigger
Configuration
I don't think this needs any configuration.
It's always possible someone else would prefer the
aspectRatio
method over the convenience method. If that occurs the rule could be modified to controlling the preferred method, though it could also be a separate rule as well since it would be checking for the opposite case.Opt-in?
Based on the criteria in the readme, this could be enabled by default. Though it depends on what the general consensus is.
The text was updated successfully, but these errors were encountered: