use_to_and_as_if_applicable
該当する場合は、メソッド名を `to___` または `as___` で開始してください。
詳細
#オブジェクトの状態を新しいオブジェクトにコピーする場合、メソッド名を to___() とすることを推奨します。
元のオブジェクトを基にした別の表現を返す場合、メソッド名を as___() とすることを推奨します。
悪い例
dart
class Bar {
Foo myMethod() {
return Foo.from(this);
}
}良い例
dart
class Bar {
Foo toFoo() {
return Foo.from(this);
}
}良い例
dart
class Bar {
Foo asFoo() {
return Foo.from(this);
}
}有効にする
#use_to_and_as_if_applicable ルールを有効にするには、analysis_options.yaml ファイルの linter > rules の下に use_to_and_as_if_applicable を追加してください。
analysis_options.yaml
yaml
linter:
rules:
- use_to_and_as_if_applicable代わりに YAML マップ構文を使用してリンタールールを設定している場合は、linter > rules の下に use_to_and_as_if_applicable: true を追加してください。
analysis_options.yaml
yaml
linter:
rules:
use_to_and_as_if_applicable: true