You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
have generally always preferred computed variables over functions with 0 arguments, would be awesome to be able to enforce that:
don't prefer:
func foo()->Bar{...}
prefer:
varfoo:Bar{...}
The text was updated successfully, but these errors were encountered:
bobby-fi
changed the title
Enhancement idea: computed vars over functions with 0 arguments
Rule idea: computed vars over functions with 0 arguments
Mar 22, 2024
Unfortunately this isn't really feasible due to the need to change all the call sites. SwiftFormat only operates on a per-file basis, so it wouldn't know if a call to foo() in another file referred to the same function and needs to have the parens removed.
Also, even if it were possible, I'm not sure it's a good idea. If foo() is just retrieving a value then it should be a property, but what about something like this method:
func popLast()->Element?{…}
Here it's actually mutating the collection and returning the result. It wouldn't make sense to change that to a property.
I suppose SwiftFormat could try to detect if the method name is a verb or noun and infer from that. Might work better as a SwiftLint rule in that case though.
have generally always preferred computed variables over functions with 0 arguments, would be awesome to be able to enforce that:
don't prefer:
prefer:
The text was updated successfully, but these errors were encountered: