目錄

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