deprecated_member_use_from_same_package
避免在声明了已弃用元素的同一个包中使用它们。
详情
#用 @Deprecated
注解的元素不应该在其声明所在的包内被引用。
避免使用已弃用元素。
...
错误
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;
}
已弃用元素可以在其他已弃用元素内部使用,以便将一组 API 作为单个单元一起弃用。
正确
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
规则,请将 deprecated_member_use_from_same_package
添加到您的 analysis_options.yaml
文件中 linter > rules 下。
analysis_options.yaml
yaml
linter:
rules:
- deprecated_member_use_from_same_package
如果您改为使用 YAML map 语法配置 linter 规则,请在 linter > rules 下添加 deprecated_member_use_from_same_package: true
。
analysis_options.yaml
yaml
linter:
rules:
deprecated_member_use_from_same_package: true