type_init_formals
Don't type annotate initializing formals.
此规则自 Dart 2.0 版本起可用。
_规则集:recommended , flutter _
此规则提供 快速修复 。
详情
#From Effective Dart:
DON'T type annotate initializing formals.
If a constructor parameter is using this.x
to initialize a field, then the type of the parameter is understood to be the same type as the field. If a a constructor parameter is using super.x
to forward to a super constructor, then the type of the parameter is understood to be the same as the super constructor parameter.
Type annotating an initializing formal with a different type than that of the field is OK.
BAD:
class Point {
int x, y;
Point(int this.x, int this.y);
}
GOOD:
class Point {
int x, y;
Point(this.x, this.y);
}
BAD:
class A {
int a;
A(this.a);
}
class B extends A {
B(int super.a);
}
GOOD:
class A {
int a;
A(this.a);
}
class B extends A {
B(super.a);
}
使用方法
#要启用 type_init_formals
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 type_init_formals
:
linter:
rules:
- type_init_formals
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.