deprecated_member_use_from_same_package
避免在宣告已棄用元素的套件內使用它們。
此規則自 Dart 3.0 起提供。
此規則有可用的快速修復。
詳細資訊
#以 @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
規則,請在您的 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。頁面最後更新於 2024-07-03。 檢視來源 或 回報問題。