deprecated_member_use_from_same_package
Avoid using deprecated elements from within the package in which they are declared.
此规则自 Dart 3.0 版本起可用。
此规则提供 快速修复 。
详情
#Elements that are annotated with @Deprecated
should not be referenced from within the package in which they are declared.
AVOID using deprecated elements.
...
BAD:
dart
// Declared in one library:
class Foo {
@Deprecated("Use 'm2' instead")
void m1() {}
void m2({
@Deprecated('This is an old parameter') int? p,
})
}
@Deprecated('Do not use')
int x = 0;
// In the same or another library, but within the same package:
void m(Foo foo) {
foo.m1();
foo.m2(p: 7);
x = 1;
}
Deprecated elements can be used from within other deprecated elements, in order to allow for the deprecation of a collection of APIs together as one unit.
GOOD:
dart
// Declared in one library:
class Foo {
@Deprecated("Use 'm2' instead")
void m1() {}
void m2({
@Deprecated('This is an old parameter') int? p,
})
}
@Deprecated('Do not use')
int x = 0;
// In the same or another library, but within the same package:
@Deprecated('Do not use')
void m(Foo foo) {
foo.m1();
foo.m2(p: 7);
x = 1;
}
使用方法
#要启用 deprecated_member_use_from_same_package
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 deprecated_member_use_from_same_package
:
analysis_options.yaml
yaml
linter:
rules:
- deprecated_member_use_from_same_package
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.