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
// beforefactoryClass.constructor(int a, int b, {String? c, List d =const []}) =>Other.constructor(a, b, c: c, d: d);
// afterfactoryClass.constructor(int a, int b, {String? c, List d}) =Other.constructor;
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 a const 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.
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:
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.
nate-thegrate
changed the title
proposal: assignable_factory
proposal: redirecting_factoryMar 4, 2024
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.
Making it a non-factory constructor is a bigger change, and something that should be chosen deliberately.
(There can be a "quick fix" for changing a redirecting factory constructor to a redirecting generative constructor, or vice versa, but neither is better, just different.)
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: