tighten_type_of_initializing_formals
Tighten type of initializing formal.
This rule is available as of Dart 2.12.
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:
dart
class A {
A.c1(this.p) : assert(p != null);
A.c2(this.p);
final String? p;
}
GOOD:
dart
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);
}
Usage
#To enable the tighten_type_of_initializing_formals
rule,
add tighten_type_of_initializing_formals
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- tighten_type_of_initializing_formals
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。