deprecated_member_use_from_same_package
Avoid using deprecated elements from within the package in which they are declared.
This rule is available as of Dart 3.0.
This rule has a quick fix available.
Details
#Elements that are annotated with @Deprecated
should not be referenced from
within the package in which they are declared.
AVOID using deprecated elements.
...
BAD:
// 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:
// 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;
}
Usage
#To enable the deprecated_member_use_from_same_package
rule,
add deprecated_member_use_from_same_package
under linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- deprecated_member_use_from_same_package
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。