-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: redirecting_factory
#4909
Comments
The language specification refers to that as a redirecting factory constructor. There is a similar structure known as a redirecting generative constructor that can be used for non-factory constructors. If this lint is approved we should consider whether to also catch cases where that construct could be used. |
assignable_factory
redirecting_factory
That's good to know, thanks! |
I don't think there'll be any cases for redirecting generative constructors. This only makes sense for an existing factory constructor which uses a body to call another constructor. |
redirecting_factory
Redirecting factories can clean things up nicely—you can rely on the other constructor to handle default arguments, and you can even have a
const factory
if you're redirecting to aconst
constructor.Description
Use a redirecting factory constructor instead of a function body.
Details
This rule applies to any factory that simply returns an instance of the class using another constructor with the same parameters.
Kind
This is a "prefer" guideline that would enforce style advice.
Example
Bad:
Good:
Discussion
As mentioned on Stack Overflow, right now there's barely any documentation for factory assignment, so updating the docs should probably happen before the implementation of this lint rule.
The text was updated successfully, but these errors were encountered: