join_return_with_assignment
盡可能將 return 陳述式與賦值結合。
此規則自 Dart 2.0 起可用。
詳細資訊
#建議盡可能將 return 陳述式與賦值結合。
不佳
dart
class A {
B _lazyInstance;
static B get instance {
_lazyInstance ??= B(); // LINT
return _lazyInstance;
}
}
良好
dart
class A {
B _lazyInstance;
static B get instance => _lazyInstance ??= B();
}
用法
#若要啟用 join_return_with_assignment
規則,請在您的 analysis_options.yaml
檔案中的 linter > rules 下新增 join_return_with_assignment
analysis_options.yaml
yaml
linter:
rules:
- join_return_with_assignment
除非另有說明,否則此網站上的文件反映的是 Dart 3.6.0。頁面最後更新於 2024-07-03。檢視原始碼或回報問題。