There are several lints related to the primary_constructors feature that the Developer Experience team has implemented or are considering implementing. The ones we have already implemented were requested in order to better test the feature by maximally converting existing code to use the new feature. All of the implemented lints have fixes associated with them.
We are now considering which of these lints we will ship with the feature. One of the signals we use is the likelihood that we would include the lint in either the core, recommended, or flutter lint sets. This issue is a request for feedback on the suitability of these lints for inclusion. This isn't the only factor we'll consider, but it is an important one. And if we do decide not to ship some of the lints, we might very well ship the existing fix as an assist.
(If you would rather have separate issues for each lint, let me know. I thought it might be useful to consider them together because they are related to the same language feature.)
When considering this question, keep in mind that these lints were designed for the maximal conversion use case. Feedback of the form "we would include this if the lint were changed in this way" would be at least as valuable as a simple 'yes' or 'no'.
The lints being considered are as follows:
Flags 'containers' (classes, mixins, etc.) whose body is empty (that is, where there is only non-comment whitespace between the curly braces). It recommends replacing the body with a semicolon.
- initializeInFieldDeclaration
Flags field initializers in a primary constructor body where the initializer could be removed and the right-hand side moved to the field's initializer. It recommends removing the initialization.
- unnecessaryConstInEnumConstructor
Flags primary and secondary constructors in an enum declaration that have the const modifier. Recommends removing the modifier.
- unnecessaryPrimaryConstructorBody
Flags primary constructor bodies with no initializers, an empty body, and no metadata or doc comment. It recommends removing the primary constructor body.
- unnecessaryTypeNameInConstructor
Flags secondary constructors that include the name of the enclosing container. It recommends removing the type name or replacing the type name with new, as appropriate.
Flags non-declaring parameters in a primary constructor declaration that could be replaced by a declaring parameter. Recommends converting to a declaring parameter and removing the field declaration.
Flags any situation in which a secondary constructor could be converted to be a primary constructor. This includes flagging default constructors. Recommends converting the flagged constructor into a primary constructor.
There are several lints related to the primary_constructors feature that the Developer Experience team has implemented or are considering implementing. The ones we have already implemented were requested in order to better test the feature by maximally converting existing code to use the new feature. All of the implemented lints have fixes associated with them.
We are now considering which of these lints we will ship with the feature. One of the signals we use is the likelihood that we would include the lint in either the core, recommended, or flutter lint sets. This issue is a request for feedback on the suitability of these lints for inclusion. This isn't the only factor we'll consider, but it is an important one. And if we do decide not to ship some of the lints, we might very well ship the existing fix as an assist.
(If you would rather have separate issues for each lint, let me know. I thought it might be useful to consider them together because they are related to the same language feature.)
When considering this question, keep in mind that these lints were designed for the maximal conversion use case. Feedback of the form "we would include this if the lint were changed in this way" would be at least as valuable as a simple 'yes' or 'no'.
The lints being considered are as follows:
Flags 'containers' (classes, mixins, etc.) whose body is empty (that is, where there is only non-comment whitespace between the curly braces). It recommends replacing the body with a semicolon.
Flags field initializers in a primary constructor body where the initializer could be removed and the right-hand side moved to the field's initializer. It recommends removing the initialization.
Flags primary and secondary constructors in an
enumdeclaration that have theconstmodifier. Recommends removing the modifier.Flags primary constructor bodies with no initializers, an empty body, and no metadata or doc comment. It recommends removing the primary constructor body.
Flags secondary constructors that include the name of the enclosing container. It recommends removing the type name or replacing the type name with
new, as appropriate.Flags non-declaring parameters in a primary constructor declaration that could be replaced by a declaring parameter. Recommends converting to a declaring parameter and removing the field declaration.
Flags any situation in which a secondary constructor could be converted to be a primary constructor. This includes flagging default constructors. Recommends converting the flagged constructor into a primary constructor.