linter
linter copied to clipboard
Exclude {Key? key} from `always_put_required_named_parameters_first`
Since Flutter source code full of {Key? key, required ...}
constructors, it would be better excluding this specific case.
![Screen Shot 2021-08-31 at 10 22 36](https://user-images.githubusercontent.com/43244505/131460891-c7721c21-49a5-4ae4-9864-771fdc3d3cb7.png)
Flutter example:
const Padding({
Key? key,
required this.padding,
Widget? child,
}) : assert(padding != null),
super(key: key, child: child);
/fyi @goderbauer
I am not sure if it's worth making an exception for this. The always_put_required_named_parameters_first
lint doesn't seem particularly useful for flutter code...
maybe the lint rule could instead allow grouping super initializing parameters now that that feature has landed in dart, but still ensuring that required super parameters are sorted before other super parameters? i.e.
class A{
A({required this.a, this.b = 'default'});
final String a, b;
}
class B extends A{
B({required super.a, super.b, required this.c});
final String c;
}
currently, the lint rule would require to reorder the named parameters in B's constructor like this:
B({required super.a, required this.c, super.b});
which in this case inhibits grouping all super parameters together.
I'd argue it's nicer to read the constructor when the super parameters aren't mixed with other parameters, or is that just me? If more people share this opinion it might make sense also to add a linter rule that enforces super parameters to appear before other parameters