tighten_ type_ of_ initializing_ formals
Tighten type of initializing formal.
Details
#Tighten the type of an initializing formal if a non-null assert exists. This allows the type system to catch problems rather than have them only be caught at run-time.
BAD:
class A {
A.c1(this.p) : assert(p != null);
A.c2(this.p);
final String? p;
}
GOOD:
class A {
A.c1(String this.p);
A.c2(this.p);
final String? p;
}
class B {
String? b;
B(this.b);
}
class C extends B {
B(String super.b);
}
Enable
#
To enable the
tighten_type_of_initializing_formals
rule, add
tighten_type_of_initializing_formals
under
linter > rules
in your
analysis_options.yaml
file:
linter:
rules:
- tighten_type_of_initializing_formals
If you're instead using the YAML map syntax to configure linter rules,
add
tighten_type_of_initializing_formals: true
under
linter > rules:
linter:
rules:
tighten_type_of_initializing_formals: true
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Report an issue.