join_return_with_assignment
盡可能將 return 陳述式與賦值結合。
詳細資訊
#應該 盡可能將 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
如果您改為使用 YAML map 語法來設定 linter 規則,請在 linter > rules 下新增 join_return_with_assignment: true
analysis_options.yaml
yaml
linter:
rules:
join_return_with_assignment: true
除非另有說明,否則本網站文件反映的是 Dart 3.7.1 版本。頁面最後更新於 2025-03-07。 檢視原始碼 或回報問題。