Lint for placing super() last in constructor initializers (Style Guide) #57159
Labels
analyzer-linter
Issues with the analyzer's support for the linter package
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
type-enhancement
A request for a change that isn't a bug
From the style guide:
DO place the
super()
call last in a constructor initialization list.Field initializers are evaluated in the order that they appear in the constructor initialization list. If you place a
super()
call in the middle of an initializer list, the superclass’s initializers will be evaluated right then before evaluating the rest of the subclass’s initializers.What it doesn’t mean is that the superclass’s constructor body will be executed then. That always happens after all initializers are run regardless of where
super()
appears. It’s vanishingly rare that the order of initializers matters, so the placement ofsuper()
in the list almost never matters either.Getting in the habit of placing it last improves consistency, visually reinforces when the superclass’s constructor body is run, and may help performance.
GOOD:
BAD:
The text was updated successfully, but these errors were encountered: