Enable and fix prefer_conditional_assignment (dart-lang/glob#30) Migrate to `??=` for all cases where the assignment was the only behavior behind the condition. Refactor to `=>` for the pattern of memoized getters.
diff --git a/pkgs/glob/analysis_options.yaml b/pkgs/glob/analysis_options.yaml index 0711aca..aefc435 100644 --- a/pkgs/glob/analysis_options.yaml +++ b/pkgs/glob/analysis_options.yaml
@@ -28,6 +28,7 @@ - package_api_docs - package_names - package_prefixed_library_names + - prefer_conditional_assignment - prefer_equal_for_default_values - prefer_final_fields - prefer_generic_function_type_aliases
diff --git a/pkgs/glob/lib/glob.dart b/pkgs/glob/lib/glob.dart index c2f7f6f..c43c40f 100644 --- a/pkgs/glob/lib/glob.dart +++ b/pkgs/glob/lib/glob.dart
@@ -52,32 +52,20 @@ ListTree _listTree; /// Whether [context]'s current directory is absolute. - bool get _contextIsAbsolute { - if (_contextIsAbsoluteCache == null) { - _contextIsAbsoluteCache = context.isAbsolute(context.current); - } - return _contextIsAbsoluteCache; - } + bool get _contextIsAbsolute => + _contextIsAbsoluteCache ??= context.isAbsolute(context.current); bool _contextIsAbsoluteCache; /// Whether [pattern] could match absolute paths. - bool get _patternCanMatchAbsolute { - if (_patternCanMatchAbsoluteCache == null) { - _patternCanMatchAbsoluteCache = _ast.canMatchAbsolute; - } - return _patternCanMatchAbsoluteCache; - } + bool get _patternCanMatchAbsolute => + _patternCanMatchAbsoluteCache ??= _ast.canMatchAbsolute; bool _patternCanMatchAbsoluteCache; /// Whether [pattern] could match relative paths. - bool get _patternCanMatchRelative { - if (_patternCanMatchRelativeCache == null) { - _patternCanMatchRelativeCache = _ast.canMatchRelative; - } - return _patternCanMatchRelativeCache; - } + bool get _patternCanMatchRelative => + _patternCanMatchRelativeCache ??= _ast.canMatchRelative; bool _patternCanMatchRelativeCache; @@ -126,7 +114,7 @@ "${context.style} paths, but this platform uses ${p.style} paths."); } - if (_listTree == null) _listTree = ListTree(_ast); + _listTree ??= ListTree(_ast); return _listTree.list(root: root, followLinks: followLinks); } @@ -147,7 +135,7 @@ "${context.style} paths, but this platform uses ${p.style} paths."); } - if (_listTree == null) _listTree = ListTree(_ast); + _listTree ??= ListTree(_ast); return _listTree.listSync(root: root, followLinks: followLinks); }
diff --git a/pkgs/glob/lib/src/ast.dart b/pkgs/glob/lib/src/ast.dart index c8f4328..5620c56 100644 --- a/pkgs/glob/lib/src/ast.dart +++ b/pkgs/glob/lib/src/ast.dart
@@ -44,9 +44,7 @@ /// Returns whether this glob matches [string]. bool matches(String string) { - if (_regExp == null) { - _regExp = RegExp('^${_toRegExp()}\$', caseSensitive: caseSensitive); - } + _regExp ??= RegExp('^${_toRegExp()}\$', caseSensitive: caseSensitive); return _regExp.hasMatch(string); } @@ -122,7 +120,7 @@ List<AstNode> currentComponent; addNode(AstNode node) { - if (currentComponent == null) currentComponent = []; + currentComponent ??= []; currentComponent.add(node); }