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 のコレクション全体を 1 つのユニットとして非推奨にするために、*他の*非推奨要素内から使用できます。
良い例
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.5.3 を反映しています。ページの最終更新日は 2024-07-03 です。 ソースを表示 または 問題を報告。