From 9792c2c082a2da71aaf04f2e18670ddf13c0fe89 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 10 Nov 2022 13:53:47 -0800 Subject: [PATCH 1/4] Update to latest lints, require Dart 2.17, fix deprecation --- .github/workflows/dart.yml | 2 +- CHANGELOG.md | 1 + analysis_options.yaml | 134 +------------------ lib/pattern.dart | 6 +- lib/src/async/concat.dart | 4 +- lib/src/async/countdown_timer.dart | 11 +- lib/src/async/future_stream.dart | 4 +- lib/src/async/metronome.dart | 4 +- lib/src/async/stream_buffer.dart | 2 +- lib/src/async/stream_router.dart | 2 +- lib/src/collection/bimap.dart | 15 ++- lib/src/collection/delegates/iterable.dart | 29 ++-- lib/src/collection/delegates/list.dart | 10 +- lib/src/collection/delegates/map.dart | 13 +- lib/src/collection/delegates/queue.dart | 4 +- lib/src/collection/delegates/set.dart | 4 +- lib/src/collection/lru_map.dart | 18 +-- lib/src/collection/multimap.dart | 98 +++++++------- lib/src/collection/treeset.dart | 59 ++++---- lib/src/collection/utils.dart | 2 +- lib/src/core/optional.dart | 17 +-- lib/src/iterables/cycle.dart | 6 +- lib/src/iterables/generating_iterable.dart | 19 +-- lib/src/iterables/infinite_iterable.dart | 15 ++- lib/src/iterables/min_max.dart | 14 +- lib/testing/src/async/fake_async.dart | 10 +- lib/testing/src/time/time.dart | 2 +- pubspec.yaml | 3 +- test/collection/delegates/iterable_test.dart | 3 +- test/collection/delegates/set_test.dart | 19 +-- test/collection/multimap_test.dart | 8 +- test/collection/treeset_test.dart | 2 +- test/collection/utils_test.dart | 12 +- test/core/optional_test.dart | 12 +- test/pattern/glob_test.dart | 2 +- test/testing/equality/equality_test.dart | 36 ++--- 36 files changed, 243 insertions(+), 359 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 97b1e9c2..b9d509c9 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -47,7 +47,7 @@ jobs: matrix: # Test against the SDK lower-bound defined in pubspec.yaml and dev. os: [ubuntu-latest] - sdk: [2.12.0, dev] + sdk: [2.17.0, dev] steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v1.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a4ca589..3de6f7bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Expose `TreeIterator` for iterating `TreeSet` instead of using `BidirectionalIterator`. + * Require Dart 2.17 #### 3.1.0 - 2022-05-03 diff --git a/analysis_options.yaml b/analysis_options.yaml index 055571f5..2dc1dc35 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,163 +1,35 @@ -analyzer: - errors: - # treat missing required parameters as a warning (not a hint) - missing_required_param: warning - # treat missing returns as a warning (not a hint) - missing_return: warning - # allow having TODOs in the code - todo: ignore - # Ignore analyzer hints for updating pubspecs when using Future or - # Stream and not importing dart:async - # Please see https://github.com/flutter/flutter/pull/24528 for details. - sdk_version_async_exported_from_core: ignore +# https://dart.dev/guides/language/analysis-options +include: package:lints/recommended.yaml linter: rules: - # these rules are documented on and in the same order as - # the Dart Lint rules page to make maintenance easier - # https://github.com/dart-lang/linter/blob/master/example/all.yaml - always_declare_return_types - # ENABLE - always_put_control_body_on_new_line - always_put_required_named_parameters_first - - always_require_non_null_named_parameters - # ENABLE - always_specify_types - - annotate_overrides - # - avoid_annotating_with_dynamic # conflicts with always_specify_types - # - avoid_as # conflicts with NNBD - avoid_bool_literals_in_conditional_expressions - # - avoid_catches_without_on_clauses # we do this commonly - # - avoid_catching_errors # we do this commonly - avoid_classes_with_only_static_members - # - avoid_double_and_int_checks # only useful when targeting JS runtime - - avoid_empty_else - avoid_field_initializers_in_const_classes - - avoid_function_literals_in_foreach_calls - # - avoid_implementing_value_types # not yet tested - - avoid_init_to_null - # - avoid_js_rounded_ints # only useful when targeting JS runtime - - avoid_null_checks_in_equality_operators - # - avoid_positional_boolean_parameters # not yet tested - # - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356) - - avoid_relative_lib_imports - - avoid_renaming_method_parameters - - avoid_return_types_on_setters - # - avoid_returning_null # there are plenty of valid reasons to return null - # - avoid_returning_null_for_future # not yet tested - - avoid_returning_null_for_void - # - avoid_returning_this # there are plenty of valid reasons to return this - # - avoid_setters_without_getters # not yet tested - # - avoid_shadowing_type_parameters # not yet tested - # - avoid_single_cascade_in_expression_statements # not yet tested - avoid_slow_async_io - - avoid_types_as_parameter_names - # - avoid_types_on_closure_parameters # conflicts with always_specify_types - avoid_unused_constructor_parameters - avoid_void_async - - await_only_futures - - camel_case_types - cancel_subscriptions - # - cascade_invocations # not yet tested - # - close_sinks # not reliable enough - # - comment_references # blocked on https://github.com/flutter/flutter/issues/20765 - # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204 - - control_flow_in_finally - - curly_braces_in_flow_control_structures - # - diagnostic_describe_all_properties # not yet tested - directives_ordering - - empty_catches - - empty_constructor_bodies - - empty_statements - # - file_names # not yet tested - flutter_style_todos - - hash_and_equals - - implementation_imports - - iterable_contains_unrelated_type - # - join_return_with_assignment # not yet tested - - library_names - - library_prefixes - # - lines_longer_than_80_chars # not yet tested - - list_remove_unrelated_type - # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181 - no_adjacent_strings_in_list - - no_duplicate_case_values - - non_constant_identifier_names - # - null_closures # not yet tested - # - omit_local_variable_types # opposite of always_specify_types - # - one_member_abstracts # too many false positives - # - only_throw_errors # https://github.com/flutter/flutter/issues/5792 - - overridden_fields - package_api_docs - - package_names - - package_prefixed_library_names - # - parameter_assignments # we do this commonly - - prefer_adjacent_string_concatenation - prefer_asserts_in_initializer_lists - # - prefer_asserts_with_message # not yet tested - # ENABLE - prefer_collection_literals - - prefer_conditional_assignment - prefer_const_constructors - prefer_const_constructors_in_immutables - prefer_const_declarations - prefer_const_literals_to_create_immutables - # - prefer_constructors_over_static_methods # not yet tested - - prefer_contains - # - prefer_double_quotes # opposite of prefer_single_quotes - - prefer_equal_for_default_values - # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods - - prefer_final_fields - prefer_final_in_for_each - # ENABLE - prefer_final_locals - # - prefer_for_elements_to_map_fromIterable # not yet tested - prefer_foreach - # - prefer_function_declarations_over_variables # not yet tested - - prefer_generic_function_type_aliases - prefer_if_elements_to_conditional_expressions - - prefer_if_null_operators - - prefer_initializing_formals - - prefer_inlined_adds - # - prefer_int_literals # not yet tested - # - prefer_interpolation_to_compose_strings # not yet tested - - prefer_is_empty - - prefer_is_not_empty - - prefer_iterable_whereType - # - prefer_mixin # https://github.com/dart-lang/language/issues/32 - # - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932 - prefer_single_quotes - - prefer_spread_collections - - prefer_typing_uninitialized_variables - # ENABLE - prefer_void_to_null - - provide_deprecation_message - # - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml - - recursive_getters - - slash_for_doc_comments - # - sort_child_properties_last # not yet tested - sort_constructors_first - sort_pub_dependencies - sort_unnamed_constructors_first - test_types_in_equals - throw_in_finally - # - type_annotate_public_apis # subset of always_specify_types - - type_init_formals - # - unawaited_futures # too many false positives - # - unnecessary_await_in_return # not yet tested - - unnecessary_brace_in_string_interps - - unnecessary_const - - unnecessary_getters_setters - # - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498 - - unnecessary_new - - unnecessary_null_aware_assignments - - unnecessary_null_in_if_null_operators - - unnecessary_overrides - unnecessary_parenthesis - unnecessary_statements - - unnecessary_this - - unrelated_type_equality_checks - # - unsafe_html # not yet tested - - use_full_hex_values_for_flutter_colors - # - use_function_type_syntax_for_parameters # not yet tested - - use_rethrow_when_possible - # - use_setters_to_change_properties # not yet tested - # - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182 - # - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review - - valid_regexps - # - void_checks # not yet tested + - use_super_parameters diff --git a/lib/pattern.dart b/lib/pattern.dart index 3503eaed..2c9cab1a 100644 --- a/lib/pattern.dart +++ b/lib/pattern.dart @@ -42,7 +42,7 @@ class _MultiPattern extends Pattern { @override Iterable allMatches(String str, [int start = 0]) { - final _allMatches = []; + final allMatches = []; for (final pattern in include) { var matches = pattern.allMatches(str, start); if (_hasMatch(matches)) { @@ -53,10 +53,10 @@ class _MultiPattern extends Pattern { } } } - _allMatches.addAll(matches); + allMatches.addAll(matches); } } - return _allMatches; + return allMatches; } @override diff --git a/lib/src/async/concat.dart b/lib/src/async/concat.dart index ed9267be..e6863132 100644 --- a/lib/src/async/concat.dart +++ b/lib/src/async/concat.dart @@ -40,8 +40,8 @@ class _ConcatStream extends Stream { final Iterable> _streams; @override - StreamSubscription listen(void onData(T data)?, - {Function? onError, void onDone()?, bool? cancelOnError}) { + StreamSubscription listen(void Function(T data)? onData, + {Function? onError, void Function()? onDone, bool? cancelOnError}) { cancelOnError = true == cancelOnError; StreamSubscription? currentSubscription; StreamController? controller; diff --git a/lib/src/async/countdown_timer.dart b/lib/src/async/countdown_timer.dart index b7f52a9a..2f354a68 100644 --- a/lib/src/async/countdown_timer.dart +++ b/lib/src/async/countdown_timer.dart @@ -35,7 +35,7 @@ class CountdownTimer extends Stream { _stopwatch.start(); } - static const _THRESHOLD_MS = 4; + static const _thresholdMS = 4; final Duration _duration; final Stopwatch _stopwatch; @@ -46,8 +46,11 @@ class CountdownTimer extends Stream { late final Timer _timer; @override - StreamSubscription listen(void onData(CountdownTimer event)?, - {Function? onError, void onDone()?, bool? cancelOnError}) => + StreamSubscription listen( + void Function(CountdownTimer event)? onData, + {Function? onError, + void Function()? onDone, + bool? cancelOnError}) => _controller.stream.listen(onData, onError: onError, onDone: onDone); Duration get elapsed => _stopwatch.elapsed; @@ -66,7 +69,7 @@ class CountdownTimer extends Stream { var t = remaining; _controller.add(this); // timers may have a 4ms resolution - if (t.inMilliseconds < _THRESHOLD_MS) { + if (t.inMilliseconds < _thresholdMS) { cancel(); } } diff --git a/lib/src/async/future_stream.dart b/lib/src/async/future_stream.dart index e461e008..70b08ddf 100644 --- a/lib/src/async/future_stream.dart +++ b/lib/src/async/future_stream.dart @@ -71,8 +71,8 @@ class FutureStream extends Stream { } @override - StreamSubscription listen(void onData(T event)?, - {Function? onError, void onDone()?, bool? cancelOnError}) { + StreamSubscription listen(void Function(T event)? onData, + {Function? onError, void Function()? onDone, bool? cancelOnError}) { return _controller!.stream.listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError); } diff --git a/lib/src/async/metronome.dart b/lib/src/async/metronome.dart index d56942a8..5a1b79c4 100644 --- a/lib/src/async/metronome.dart +++ b/lib/src/async/metronome.dart @@ -85,8 +85,8 @@ class Metronome extends Stream { bool get isBroadcast => true; @override - StreamSubscription listen(void onData(DateTime event)?, - {Function? onError, void onDone()?, bool? cancelOnError}) => + StreamSubscription listen(void Function(DateTime event)? onData, + {Function? onError, void Function()? onDone, bool? cancelOnError}) => _controller.stream.listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError); diff --git a/lib/src/async/stream_buffer.dart b/lib/src/async/stream_buffer.dart index 130849a2..400d8b58 100644 --- a/lib/src/async/stream_buffer.dart +++ b/lib/src/async/stream_buffer.dart @@ -135,7 +135,7 @@ class StreamBuffer implements StreamConsumer> { _sub?.cancel(); _currentStream = stream; - final streamDone = Completer(); + final streamDone = Completer(); _sub = stream.listen((items) { _chunks.addAll(items); _counter += items.length; diff --git a/lib/src/async/stream_router.dart b/lib/src/async/stream_router.dart index 89aef0ca..9abf98ee 100644 --- a/lib/src/async/stream_router.dart +++ b/lib/src/async/stream_router.dart @@ -46,7 +46,7 @@ class StreamRouter { /// Events that match [predicate] are sent to the stream created by this /// method, and not sent to any other router streams. - Stream route(bool predicate(T event)) { + Stream route(bool Function(T event) predicate) { var controller = StreamController.broadcast(); _routes.add(_Route(predicate, controller)); return controller.stream; diff --git a/lib/src/collection/bimap.dart b/lib/src/collection/bimap.dart index 47e06ce7..6dd45a3e 100644 --- a/lib/src/collection/bimap.dart +++ b/lib/src/collection/bimap.dart @@ -74,7 +74,7 @@ class HashBiMap implements BiMap { bool containsValue(Object? value) => _inverse.containsKey(value); @override - void forEach(void f(K key, V value)) => _map.forEach(f); + void forEach(void Function(K key, V value) f) => _map.forEach(f); @override bool get isEmpty => _map.isEmpty; @@ -111,11 +111,12 @@ class HashBiMap implements BiMap { Iterable> get entries => _map.entries; @override - Map map(MapEntry transform(K key, V value)) => + Map map( + MapEntry Function(K key, V value) transform) => _map.map(transform); @override - V putIfAbsent(K key, V ifAbsent()) { + V putIfAbsent(K key, V Function() ifAbsent) { if (containsKey(key)) { return _map[key]!; } @@ -129,13 +130,13 @@ class HashBiMap implements BiMap { } @override - void removeWhere(bool test(K key, V value)) { + void removeWhere(bool Function(K key, V value) test) { _inverse.removeWhere((v, k) => test(k, v)); _map.removeWhere(test); } @override - V update(K key, V update(V value), {V ifAbsent()?}) { + V update(K key, V Function(V value) update, {V Function()? ifAbsent}) { var value = _map[key]; if (value != null) { return _add(key, update(value), true); @@ -148,9 +149,9 @@ class HashBiMap implements BiMap { } @override - void updateAll(V update(K key, V value)) { + void updateAll(V Function(K key, V value) update) { for (final key in keys) { - _add(key, update(key, _map[key]!), true); + _add(key, update(key, _map[key] as V), true); } } diff --git a/lib/src/collection/delegates/iterable.dart b/lib/src/collection/delegates/iterable.dart index 530c6b98..964a43b7 100644 --- a/lib/src/collection/delegates/iterable.dart +++ b/lib/src/collection/delegates/iterable.dart @@ -26,7 +26,7 @@ abstract class DelegatingIterable implements Iterable { Iterable get delegate; @override - bool any(bool test(E element)) => delegate.any(test); + bool any(bool Function(E element) test) => delegate.any(test); @override Iterable cast() { @@ -41,27 +41,28 @@ abstract class DelegatingIterable implements Iterable { E elementAt(int index) => delegate.elementAt(index); @override - bool every(bool test(E element)) => delegate.every(test); + bool every(bool Function(E element) test) => delegate.every(test); @override - Iterable expand(Iterable f(E element)) => delegate.expand(f); + Iterable expand(Iterable Function(E element) f) => + delegate.expand(f); @override E get first => delegate.first; @override - E firstWhere(bool test(E element), {E orElse()?}) => + E firstWhere(bool Function(E element) test, {E Function()? orElse}) => delegate.firstWhere(test, orElse: orElse); @override - T fold(T initialValue, T combine(T previousValue, E element)) => + T fold(T initialValue, T Function(T previousValue, E element) combine) => delegate.fold(initialValue, combine); @override Iterable followedBy(Iterable other) => delegate.followedBy(other); @override - void forEach(void f(E element)) => delegate.forEach(f); + void forEach(void Function(E element) f) => delegate.forEach(f); @override bool get isEmpty => delegate.isEmpty; @@ -79,36 +80,38 @@ abstract class DelegatingIterable implements Iterable { E get last => delegate.last; @override - E lastWhere(bool test(E element), {E orElse()?}) => + E lastWhere(bool Function(E element) test, {E Function()? orElse}) => delegate.lastWhere(test, orElse: orElse); @override int get length => delegate.length; @override - Iterable map(T f(E e)) => delegate.map(f); + Iterable map(T Function(E e) f) => delegate.map(f); @override - E reduce(E combine(E value, E element)) => delegate.reduce(combine); + E reduce(E Function(E value, E element) combine) => delegate.reduce(combine); @override E get single => delegate.single; @override - E singleWhere(bool test(E element), {E orElse()?}) => + E singleWhere(bool Function(E element) test, {E Function()? orElse}) => delegate.singleWhere(test, orElse: orElse); @override Iterable skip(int n) => delegate.skip(n); @override - Iterable skipWhile(bool test(E value)) => delegate.skipWhile(test); + Iterable skipWhile(bool Function(E value) test) => + delegate.skipWhile(test); @override Iterable take(int n) => delegate.take(n); @override - Iterable takeWhile(bool test(E value)) => delegate.takeWhile(test); + Iterable takeWhile(bool Function(E value) test) => + delegate.takeWhile(test); @override List toList({bool growable = true}) => delegate.toList(growable: growable); @@ -117,7 +120,7 @@ abstract class DelegatingIterable implements Iterable { Set toSet() => delegate.toSet(); @override - Iterable where(bool test(E element)) => delegate.where(test); + Iterable where(bool Function(E element) test) => delegate.where(test); @override Iterable whereType() { diff --git a/lib/src/collection/delegates/list.dart b/lib/src/collection/delegates/list.dart index 2c19a4c0..f6934743 100644 --- a/lib/src/collection/delegates/list.dart +++ b/lib/src/collection/delegates/list.dart @@ -77,7 +77,7 @@ abstract class DelegatingList extends DelegatingIterable int indexOf(E element, [int start = 0]) => delegate.indexOf(element, start); @override - int indexWhere(bool test(E element), [int start = 0]) => + int indexWhere(bool Function(E element) test, [int start = 0]) => delegate.indexWhere(test, start); @override @@ -98,7 +98,7 @@ abstract class DelegatingList extends DelegatingIterable delegate.lastIndexOf(element, start); @override - int lastIndexWhere(bool test(E element), [int? start]) => + int lastIndexWhere(bool Function(E element) test, [int? start]) => delegate.lastIndexWhere(test, start); @override @@ -119,14 +119,14 @@ abstract class DelegatingList extends DelegatingIterable void removeRange(int start, int end) => delegate.removeRange(start, end); @override - void removeWhere(bool test(E element)) => delegate.removeWhere(test); + void removeWhere(bool Function(E element) test) => delegate.removeWhere(test); @override void replaceRange(int start, int end, Iterable iterable) => delegate.replaceRange(start, end, iterable); @override - void retainWhere(bool test(E element)) => delegate.retainWhere(test); + void retainWhere(bool Function(E element) test) => delegate.retainWhere(test); @override Iterable get reversed => delegate.reversed; @@ -144,7 +144,7 @@ abstract class DelegatingList extends DelegatingIterable void shuffle([Random? random]) => delegate.shuffle(random); @override - void sort([int compare(E a, E b)?]) => delegate.sort(compare); + void sort([int Function(E a, E b)? compare]) => delegate.sort(compare); @override List sublist(int start, [int? end]) => delegate.sublist(start, end); diff --git a/lib/src/collection/delegates/map.dart b/lib/src/collection/delegates/map.dart index 8ea9870f..1f2dbcba 100644 --- a/lib/src/collection/delegates/map.dart +++ b/lib/src/collection/delegates/map.dart @@ -68,7 +68,7 @@ abstract class DelegatingMap implements Map { } @override - void forEach(void f(K key, V value)) => delegate.forEach(f); + void forEach(void Function(K key, V value) f) => delegate.forEach(f); @override bool get isEmpty => delegate.isEmpty; @@ -83,7 +83,7 @@ abstract class DelegatingMap implements Map { int get length => delegate.length; @override - Map map(Object transform(K key, V value)) { + Map map(Object Function(K key, V value) transform) { // TODO(cbracken): Dart 2.0 requires this method to be implemented. // Change Object to MapEntry when // the MapEntry class has been added. @@ -91,25 +91,26 @@ abstract class DelegatingMap implements Map { } @override - V putIfAbsent(K key, V ifAbsent()) => delegate.putIfAbsent(key, ifAbsent); + V putIfAbsent(K key, V Function() ifAbsent) => + delegate.putIfAbsent(key, ifAbsent); @override V? remove(Object? key) => delegate.remove(key); @override - void removeWhere(bool test(K key, V value)) { + void removeWhere(bool Function(K key, V value) test) { // TODO(cbracken): Dart 2.0 requires this method to be implemented. throw UnimplementedError('removeWhere'); } @override - V update(K key, V update(V value), {V ifAbsent()?}) { + V update(K key, V Function(V value) update, {V Function()? ifAbsent}) { // TODO(cbracken): Dart 2.0 requires this method to be implemented. throw UnimplementedError('update'); } @override - void updateAll(V update(K key, V value)) { + void updateAll(V Function(K key, V value) update) { // TODO(cbracken): Dart 2.0 requires this method to be implemented. throw UnimplementedError('updateAll'); } diff --git a/lib/src/collection/delegates/queue.dart b/lib/src/collection/delegates/queue.dart index 7c72b67d..8f1da6a3 100644 --- a/lib/src/collection/delegates/queue.dart +++ b/lib/src/collection/delegates/queue.dart @@ -62,8 +62,8 @@ abstract class DelegatingQueue extends DelegatingIterable E removeLast() => delegate.removeLast(); @override - void removeWhere(bool test(E element)) => delegate.removeWhere(test); + void removeWhere(bool Function(E element) test) => delegate.removeWhere(test); @override - void retainWhere(bool test(E element)) => delegate.retainWhere(test); + void retainWhere(bool Function(E element) test) => delegate.retainWhere(test); } diff --git a/lib/src/collection/delegates/set.dart b/lib/src/collection/delegates/set.dart index a8a2cf3c..daf7d435 100644 --- a/lib/src/collection/delegates/set.dart +++ b/lib/src/collection/delegates/set.dart @@ -63,13 +63,13 @@ abstract class DelegatingSet extends DelegatingIterable void removeAll(Iterable elements) => delegate.removeAll(elements); @override - void removeWhere(bool test(E element)) => delegate.removeWhere(test); + void removeWhere(bool Function(E element) test) => delegate.removeWhere(test); @override void retainAll(Iterable elements) => delegate.retainAll(elements); @override - void retainWhere(bool test(E element)) => delegate.retainWhere(test); + void retainWhere(bool Function(E element) test) => delegate.retainWhere(test); @override Set union(Set other) => delegate.union(other); diff --git a/lib/src/collection/lru_map.dart b/lib/src/collection/lru_map.dart index e11b99b9..b0a927eb 100644 --- a/lib/src/collection/lru_map.dart +++ b/lib/src/collection/lru_map.dart @@ -58,9 +58,9 @@ class LinkedLruHashMap implements LruMap { LinkedLruHashMap._fromMap(this._entries, {int? maximumSize}) // This pattern is used instead of a default value because we want to // be able to respect null values coming in from MapCache.lru. - : _maximumSize = maximumSize ?? _DEFAULT_MAXIMUM_SIZE; + : _maximumSize = maximumSize ?? _defaultMaximumSize; - static const _DEFAULT_MAXIMUM_SIZE = 100; + static const _defaultMaximumSize = 100; final Map> _entries; @@ -116,7 +116,7 @@ class LinkedLruHashMap implements LruMap { /// /// Calling `action` must not add or remove keys from the map. @override - void forEach(void action(K key, V value)) { + void forEach(void Function(K key, V value) action) { var head = _head; while (head != null) { action(head.key, head.value); @@ -154,7 +154,7 @@ class LinkedLruHashMap implements LruMap { Iterable get values => _iterable().map((e) => e.value); @override - Map map(Object transform(K key, V value)) { + Map map(Object Function(K key, V value) transform) { // TODO(cbracken): Dart 2.0 requires this method to be implemented. // Change Object to MapEntry when // the MapEntry class has been added. @@ -182,7 +182,7 @@ class LinkedLruHashMap implements LruMap { /// MRU position. If this causes [length] to exceed [maximumSize], then the /// LRU position is removed. @override - V putIfAbsent(K key, V ifAbsent()) { + V putIfAbsent(K key, V Function() ifAbsent) { final entry = _entries.putIfAbsent(key, () => _createEntry(key, ifAbsent())); if (length > maximumSize) { @@ -248,7 +248,7 @@ class LinkedLruHashMap implements LruMap { } @override - void removeWhere(bool test(K key, V value)) { + void removeWhere(bool Function(K key, V value) test) { var keysToRemove = []; _entries.forEach((key, entry) { if (test(key, entry.value)) keysToRemove.add(key); @@ -287,10 +287,10 @@ class LinkedLruHashMap implements LruMap { } @override - V update(K key, V update(V value), {V ifAbsent()?}) { + V update(K key, V Function(V value) update, {V Function()? ifAbsent}) { V newValue; if (containsKey(key)) { - newValue = update(this[key]!); + newValue = update(this[key] as V); } else { if (ifAbsent == null) { throw ArgumentError.value(key, 'key', 'Key not in map'); @@ -310,7 +310,7 @@ class LinkedLruHashMap implements LruMap { } @override - void updateAll(V update(K key, V value)) { + void updateAll(V Function(K key, V value) update) { _entries.forEach((key, entry) { var newValue = _createEntry(key, update(key, entry.value)); _entries[key] = newValue; diff --git a/lib/src/collection/multimap.dart b/lib/src/collection/multimap.dart index dc496e25..87ce1d21 100644 --- a/lib/src/collection/multimap.dart +++ b/lib/src/collection/multimap.dart @@ -27,7 +27,8 @@ abstract class Multimap { /// adds an association from [key](e) to [value](e). [key] and [value] each /// default to the identity function. factory Multimap.fromIterable(Iterable iterable, - {K key(element), V value(element)}) = ListMultimap.fromIterable; + {K Function(dynamic)? key, + V Function(dynamic)? value}) = ListMultimap.fromIterable; /// Returns whether this multimap contains the given [value]. bool containsValue(Object? value); @@ -67,7 +68,7 @@ abstract class Multimap { Iterable removeAll(Object? key); /// Removes all entries of this multimap that satisfy the given [predicate]. - void removeWhere(bool predicate(K key, V value)); + void removeWhere(bool Function(K key, V value) predicate); /// Removes all data from the multimap. void clear(); @@ -75,12 +76,12 @@ abstract class Multimap { /// Applies [f] to each {key, `Iterable`} pair of the multimap. /// /// It is an error to add or remove keys from the map during iteration. - void forEachKey(void f(K key, Iterable value)); + void forEachKey(void Function(K key, Iterable value) f); /// Applies [f] to each {key, value} pair of the multimap. /// /// It is an error to add or remove keys from the map during iteration. - void forEach(void f(K key, V value)); + void forEach(void Function(K key, V value) f); /// The keys of [this]. Iterable get keys; @@ -110,7 +111,7 @@ abstract class _BaseMultimap> /// association from [key](e) to [value](e). [key] and [value] each default /// to the identity function. _BaseMultimap.fromIterable(Iterable iterable, - {K key(element)?, V value(element)?}) { + {K Function(dynamic)? key, V Function(dynamic)? value}) { key ??= _id; value ??= _id; for (final element in iterable) { @@ -127,7 +128,7 @@ abstract class _BaseMultimap> void _addAll(C iterable, Iterable value); void _clear(C iterable); bool _remove(C iterable, V? value); - void _removeWhere(C iterable, K key, bool predicate(K key, V value)); + void _removeWhere(C iterable, K key, bool Function(K key, V value) predicate); Iterable _wrap(Object? key, C iterable); @override @@ -187,8 +188,8 @@ abstract class _BaseMultimap> } @override - void removeWhere(bool predicate(K key, V value)) { - final emptyKeys = Set(); + void removeWhere(bool Function(K key, V value) predicate) { + final emptyKeys = {}; // TODO(cbracken): iterate over entries _map.forEach((K key, C values) { _removeWhere(values, key, predicate); @@ -204,10 +205,10 @@ abstract class _BaseMultimap> } @override - void forEachKey(void f(K key, C value)) => _map.forEach(f); + void forEachKey(void Function(K key, C value) f) => _map.forEach(f); @override - void forEach(void f(K key, V value)) { + void forEach(void Function(K key, V value) f) { _map.forEach((K key, Iterable values) { for (final V value in values) { f(key, value); @@ -236,9 +237,8 @@ class ListMultimap extends _BaseMultimap> { /// Constructs a new list-backed multimap. For each element e of [iterable], /// adds an association from [key](e) to [value](e). [key] and [value] each /// default to the identity function. - ListMultimap.fromIterable(Iterable iterable, - {K key(element)?, V value(element)?}) - : super.fromIterable(iterable, key: key, value: value); + ListMultimap.fromIterable(super.iterable, {super.key, super.value}) + : super.fromIterable(); @override List _create() => []; @@ -254,7 +254,8 @@ class ListMultimap extends _BaseMultimap> { @override bool _remove(List iterable, V? value) => iterable.remove(value); @override - void _removeWhere(List iterable, K key, bool predicate(K key, V value)) => + void _removeWhere( + List iterable, K key, bool Function(K key, V value) predicate) => iterable.removeWhere((value) => predicate(key, value)); @override List _wrap(Object? key, List iterable) => @@ -275,12 +276,11 @@ class SetMultimap extends _BaseMultimap> { /// Constructs a new set-backed multimap. For each element e of [iterable], /// adds an association from [key](e) to [value](e). [key] and [value] each /// default to the identity function. - SetMultimap.fromIterable(Iterable iterable, - {K key(element)?, V value(element)?}) - : super.fromIterable(iterable, key: key, value: value); + SetMultimap.fromIterable(super.iterable, {super.key, super.value}) + : super.fromIterable(); @override - Set _create() => Set(); + Set _create() => {}; @override void _add(Set iterable, V value) { iterable.add(value); @@ -293,7 +293,8 @@ class SetMultimap extends _BaseMultimap> { @override bool _remove(Set iterable, V? value) => iterable.remove(value); @override - void _removeWhere(Set iterable, K key, bool predicate(K key, V value)) => + void _removeWhere( + Set iterable, K key, bool Function(K key, V value) predicate) => iterable.removeWhere((value) => predicate(key, value)); @override Set _wrap(Object? key, Set iterable) => @@ -326,7 +327,7 @@ class _WrappedMap> implements Map { } @override - C putIfAbsent(K key, C ifAbsent()) { + C putIfAbsent(K key, C Function() ifAbsent) { throw UnsupportedError('Insert unsupported on map view'); } @@ -337,7 +338,7 @@ class _WrappedMap> implements Map { @override bool containsValue(Object? value) => _multimap.containsValue(value); @override - void forEach(void f(K key, C value)) => _multimap.forEachKey(f); + void forEach(void Function(K key, C value) f) => _multimap.forEachKey(f); @override bool get isEmpty => _multimap.isEmpty; @override @@ -366,21 +367,22 @@ class _WrappedMap> implements Map { } @override - Map map(MapEntry transform(K key, C value)) => + Map map( + MapEntry Function(K key, C value) transform) => _multimap._map.map(transform); @override - C update(K key, C update(C value), {C ifAbsent()?}) { + C update(K key, C Function(C value) update, {C Function()? ifAbsent}) { throw UnsupportedError('Update unsupported on map view'); } @override - void updateAll(C update(K key, C value)) { + void updateAll(C Function(K key, C value) update) { throw UnsupportedError('Update unsupported on map view'); } @override - void removeWhere(bool test(K key, C value)) { + void removeWhere(bool Function(K key, C value) test) { var keysToRemove = []; // TODO(cbracken): iterate over entries. for (final key in keys) { @@ -416,7 +418,7 @@ class _WrappedIterable> implements Iterable { } @override - bool any(bool test(V element)) { + bool any(bool Function(V element) test) { _syncDelegate(); return _delegate.any(test); } @@ -440,13 +442,13 @@ class _WrappedIterable> implements Iterable { } @override - bool every(bool test(V element)) { + bool every(bool Function(V element) test) { _syncDelegate(); return _delegate.every(test); } @override - Iterable expand(Iterable f(V element)) { + Iterable expand(Iterable Function(V element) f) { _syncDelegate(); return _delegate.expand(f); } @@ -458,13 +460,13 @@ class _WrappedIterable> implements Iterable { } @override - V firstWhere(bool test(V element), {V orElse()?}) { + V firstWhere(bool Function(V element) test, {V Function()? orElse}) { _syncDelegate(); return _delegate.firstWhere(test, orElse: orElse); } @override - T fold(T initialValue, T combine(T previousValue, V element)) { + T fold(T initialValue, T Function(T previousValue, V element) combine) { _syncDelegate(); return _delegate.fold(initialValue, combine); } @@ -476,7 +478,7 @@ class _WrappedIterable> implements Iterable { } @override - void forEach(void f(V element)) { + void forEach(void Function(V element) f) { _syncDelegate(); _delegate.forEach(f); } @@ -512,7 +514,7 @@ class _WrappedIterable> implements Iterable { } @override - V lastWhere(bool test(V element), {V orElse()?}) { + V lastWhere(bool Function(V element) test, {V Function()? orElse}) { _syncDelegate(); return _delegate.lastWhere(test, orElse: orElse); } @@ -524,13 +526,13 @@ class _WrappedIterable> implements Iterable { } @override - Iterable map(T f(V element)) { + Iterable map(T Function(V element) f) { _syncDelegate(); return _delegate.map(f); } @override - V reduce(V combine(V value, V element)) { + V reduce(V Function(V value, V element) combine) { _syncDelegate(); return _delegate.reduce(combine); } @@ -542,7 +544,7 @@ class _WrappedIterable> implements Iterable { } @override - V singleWhere(bool test(V element), {V orElse()?}) { + V singleWhere(bool Function(V element) test, {V Function()? orElse}) { _syncDelegate(); return _delegate.singleWhere(test, orElse: orElse); } @@ -554,7 +556,7 @@ class _WrappedIterable> implements Iterable { } @override - Iterable skipWhile(bool test(V value)) { + Iterable skipWhile(bool Function(V value) test) { _syncDelegate(); return _delegate.skipWhile(test); } @@ -566,7 +568,7 @@ class _WrappedIterable> implements Iterable { } @override - Iterable takeWhile(bool test(V value)) { + Iterable takeWhile(bool Function(V value) test) { _syncDelegate(); return _delegate.takeWhile(test); } @@ -590,7 +592,7 @@ class _WrappedIterable> implements Iterable { } @override - Iterable where(bool test(V element)) { + Iterable where(bool Function(V element) test) { _syncDelegate(); return _delegate.where(test); } @@ -604,8 +606,7 @@ class _WrappedIterable> implements Iterable { class _WrappedList extends _WrappedIterable> implements List { - _WrappedList(Map> map, K key, List delegate) - : super(map, key, delegate); + _WrappedList(super.map, super.key, super.delegate); @override V operator [](int index) => elementAt(index); @@ -682,7 +683,7 @@ class _WrappedList extends _WrappedIterable> } @override - int indexWhere(bool test(V element), [int start = 0]) { + int indexWhere(bool Function(V element) test, [int start = 0]) { _syncDelegate(); return _delegate.indexWhere(test, start); } @@ -716,7 +717,7 @@ class _WrappedList extends _WrappedIterable> } @override - int lastIndexWhere(bool test(V element), [int? start]) { + int lastIndexWhere(bool Function(V element) test, [int? start]) { _syncDelegate(); return _delegate.lastIndexWhere(test, start); } @@ -761,7 +762,7 @@ class _WrappedList extends _WrappedIterable> } @override - void removeWhere(bool test(V element)) { + void removeWhere(bool Function(V element) test) { _syncDelegate(); _delegate.removeWhere(test); if (_delegate.isEmpty) _map.remove(_key); @@ -775,7 +776,7 @@ class _WrappedList extends _WrappedIterable> } @override - void retainWhere(bool test(V element)) { + void retainWhere(bool Function(V element) test) { _syncDelegate(); _delegate.retainWhere(test); if (_delegate.isEmpty) _map.remove(_key); @@ -805,7 +806,7 @@ class _WrappedList extends _WrappedIterable> } @override - void sort([int compare(V a, V b)?]) { + void sort([int Function(V a, V b)? compare]) { _syncDelegate(); _delegate.sort(compare); } @@ -819,8 +820,7 @@ class _WrappedList extends _WrappedIterable> class _WrappedSet extends _WrappedIterable> implements Set { - _WrappedSet(Map> map, K key, Set delegate) - : super(map, key, delegate); + _WrappedSet(super.map, super.key, super.delegate); @override bool add(V value) { @@ -892,7 +892,7 @@ class _WrappedSet extends _WrappedIterable> } @override - void removeWhere(bool test(V element)) { + void removeWhere(bool Function(V element) test) { _syncDelegate(); _delegate.removeWhere(test); if (_delegate.isEmpty) _map.remove(_key); @@ -906,7 +906,7 @@ class _WrappedSet extends _WrappedIterable> } @override - void retainWhere(bool test(V element)) { + void retainWhere(bool Function(V element) test) { _syncDelegate(); _delegate.retainWhere(test); if (_delegate.isEmpty) _map.remove(_key); diff --git a/lib/src/collection/treeset.dart b/lib/src/collection/treeset.dart index 50bc24c2..881218a3 100644 --- a/lib/src/collection/treeset.dart +++ b/lib/src/collection/treeset.dart @@ -71,12 +71,15 @@ abstract class TreeSet extends IterableBase implements Set { /// Controls the results for [TreeSet.searchNearest]() enum TreeSearch { /// If result not found, always chose the smaller element + // ignore: constant_identifier_names LESS_THAN, /// If result not found, chose the nearest based on comparison + // ignore: constant_identifier_names NEAREST, /// If result not found, always chose the greater element + // ignore: constant_identifier_names GREATER_THAN } @@ -619,7 +622,7 @@ class AvlTreeSet extends TreeSet { /// See [Set.retainWhere] @override - void retainWhere(bool test(V element)) { + void retainWhere(bool Function(V element) test) { List chosen = []; for (final target in this) { if (test(target)) { @@ -632,7 +635,7 @@ class AvlTreeSet extends TreeSet { /// See [Set.removeWhere] @override - void removeWhere(bool test(V element)) { + void removeWhere(bool Function(V element) test) { List damned = []; for (final target in this) { if (test(target)) { @@ -891,8 +894,8 @@ typedef _IteratorMove = bool Function(); /// is included in the first movement (either [moveNext] or [movePrevious]) but /// can optionally be excluded in the constructor. class TreeIterator - // ignore: deprecated_member_use implements + // ignore: deprecated_member_use BidirectionalIterator { TreeIterator._(this.tree, {this.reversed = false, this.inclusive = true, V? anchorObject}) @@ -900,13 +903,13 @@ class TreeIterator _modCountGuard = tree._modCount { if (_anchorObject == null || tree.isEmpty) { // If the anchor is far left or right, we're just a normal iterator. - _state = reversed ? _RIGHT : _LEFT; + _state = reversed ? _right : _left; _moveNext = reversed ? _movePreviousNormal : _moveNextNormal; _movePrevious = reversed ? _moveNextNormal : _movePreviousNormal; return; } - _state = _WALK; + _state = _walk; // Else we've got an anchor we have to worry about initializing from. // This isn't known till the caller actually performs a previous/next. _moveNext = () { @@ -915,12 +918,12 @@ class TreeIterator _moveNext = reversed ? _movePreviousNormal : _moveNextNormal; _movePrevious = reversed ? _moveNextNormal : _movePreviousNormal; if (_current == null) { - _state = reversed ? _LEFT : _RIGHT; - } else if (tree.comparator(_current!.object, _anchorObject!) == 0 && + _state = reversed ? _left : _right; + } else if (tree.comparator(_current!.object, _anchorObject as V) == 0 && !inclusive) { _moveNext(); } - return _state == _WALK; + return _state == _walk; }; _movePrevious = () { @@ -929,18 +932,18 @@ class TreeIterator _moveNext = reversed ? _movePreviousNormal : _moveNextNormal; _movePrevious = reversed ? _moveNextNormal : _movePreviousNormal; if (_current == null) { - _state = reversed ? _RIGHT : _LEFT; - } else if (tree.comparator(_current!.object, _anchorObject!) == 0 && + _state = reversed ? _right : _left; + } else if (tree.comparator(_current!.object, _anchorObject as V) == 0 && !inclusive) { _movePrevious(); } - return _state == _WALK; + return _state == _walk; }; } - static const _LEFT = -1; - static const _WALK = 0; - static const _RIGHT = 1; + static const _left = -1; + static const _walk = 0; + static const _right = 1; final bool reversed; final AvlTreeSet tree; @@ -960,7 +963,7 @@ class TreeIterator // to avoid a hard breaking change, we return "null as V" in that case so // that if strong checking is not enabled or V is nullable, the existing // behavior is preserved. - if (_state == _WALK && _current != null) { + if (_state == _walk && _current != null) { return _current?.object as V; } return null as V; @@ -976,19 +979,19 @@ class TreeIterator if (_modCountGuard != tree._modCount) { throw ConcurrentModificationError(tree); } - if (_state == _RIGHT || tree.isEmpty) return false; + if (_state == _right || tree.isEmpty) return false; switch (_state) { - case _LEFT: + case _left: _current = tree._root!.minimumNode; - _state = _WALK; + _state = _walk; return true; - case _WALK: + case _walk: default: _current = _current!.successor; if (_current == null) { - _state = _RIGHT; + _state = _right; } - return _state == _WALK; + return _state == _walk; } } @@ -996,26 +999,26 @@ class TreeIterator if (_modCountGuard != tree._modCount) { throw ConcurrentModificationError(tree); } - if (_state == _LEFT || tree.isEmpty) return false; + if (_state == _left || tree.isEmpty) return false; switch (_state) { - case _RIGHT: + case _right: _current = tree._root!.maximumNode; - _state = _WALK; + _state = _walk; return true; - case _WALK: + case _walk: default: _current = _current!.predecessor; if (_current == null) { - _state = _LEFT; + _state = _left; } - return _state == _WALK; + return _state == _walk; } } } /// Private class used to track element insertions in the [TreeSet]. class AvlNode extends _TreeNode { - AvlNode({required V object}) : super(object: object); + AvlNode({required super.object}); AvlNode? _left; AvlNode? _right; diff --git a/lib/src/collection/utils.dart b/lib/src/collection/utils.dart index 14451860..9ae62c82 100644 --- a/lib/src/collection/utils.dart +++ b/lib/src/collection/utils.dart @@ -63,7 +63,7 @@ bool setsEqual(Set? a, Set? b) { /// evaluates to true. /// /// Returns -1 if there are no items where [predicate] evaluates to true. -int indexOf(Iterable elements, bool predicate(T element)) { +int indexOf(Iterable elements, bool Function(T element) predicate) { if (elements is List) { for (int i = 0; i < elements.length; i++) { if (predicate(elements[i])) return i; diff --git a/lib/src/core/optional.dart b/lib/src/core/optional.dart index 1e51bdec..f2129545 100644 --- a/lib/src/core/optional.dart +++ b/lib/src/core/optional.dart @@ -60,14 +60,14 @@ class Optional extends IterableBase { } /// Executes a function if the Optional value is present. - void ifPresent(void ifPresent(T value)) { + void ifPresent(void Function(T value) ifPresent) { if (isPresent) { - ifPresent(_value!); + ifPresent(_value as T); } } /// Execution a function if the Optional value is absent. - void ifAbsent(void ifAbsent()) { + void ifAbsent(void Function() ifAbsent) { if (!isPresent) { ifAbsent(); } @@ -90,10 +90,10 @@ class Optional extends IterableBase { /// If the Optional is [absent()], returns [absent()] without applying the transformer. /// /// The transformer must not return [null]. If it does, an [ArgumentError] is thrown. - Optional transform(S transformer(T value)) { + Optional transform(S Function(T value) transformer) { return _value == null ? Optional.absent() - : Optional.of(transformer(_value!)); + : Optional.of(transformer(_value as T)); } /// Transforms the Optional value. @@ -101,15 +101,16 @@ class Optional extends IterableBase { /// If the Optional is [absent()], returns [absent()] without applying the transformer. /// /// Returns [absent()] if the transformer returns [null]. - Optional transformNullable(S? transformer(T value)) { + Optional transformNullable( + S? Function(T value) transformer) { return _value == null ? Optional.absent() - : Optional.fromNullable(transformer(_value!)); + : Optional.fromNullable(transformer(_value as T)); } @override Iterator get iterator => - isPresent ? [_value!].iterator : Iterable.empty().iterator; + isPresent ? [_value as T].iterator : Iterable.empty().iterator; /// Delegates to the underlying [value] hashCode. @override diff --git a/lib/src/iterables/cycle.dart b/lib/src/iterables/cycle.dart index 37559903..6953fafa 100644 --- a/lib/src/iterables/cycle.dart +++ b/lib/src/iterables/cycle.dart @@ -36,9 +36,9 @@ class _Cycle extends InfiniteIterable { } class _CycleIterator implements Iterator { - _CycleIterator(Iterable _iterable) - : _iterable = _iterable, - _iterator = _iterable.iterator; + _CycleIterator(Iterable iterable) + : _iterable = iterable, + _iterator = iterable.iterator; final Iterable _iterable; Iterator _iterator; diff --git a/lib/src/iterables/generating_iterable.dart b/lib/src/iterables/generating_iterable.dart index 76348a54..992ad0c6 100644 --- a/lib/src/iterables/generating_iterable.dart +++ b/lib/src/iterables/generating_iterable.dart @@ -17,16 +17,17 @@ import 'dart:collection'; typedef _Initial = T Function(); typedef _Next = T? Function(T value); -Iterable generate(initial(), next(o)) => GeneratingIterable(initial, next); +Iterable generate(Function() initial, Function(dynamic) next) => + GeneratingIterable(initial, next); -/// An Iterable whose first value is the result of [initial] and whose -/// subsequent values are generated by passing the current value to the [next] +/// An Iterable whose first value is the result of [_initial] and whose +/// subsequent values are generated by passing the current value to the [_next] /// function. /// /// The class is useful for creating lazy iterables from object hierarchies and /// graphs. /// -/// The initial value and [next] function are required to generate a sequence +/// The initial value and [_next] function are required to generate a sequence /// that eventually terminates, otherwise calling methods that expect a finite /// sequence, like `length` or `last`, will cause an infinite loop. /// @@ -45,13 +46,13 @@ Iterable generate(initial(), next(o)) => GeneratingIterable(initial, next); /// } /// class GeneratingIterable extends IterableBase { - GeneratingIterable(this.initial, this.next); + GeneratingIterable(this._initial, this._next); - final _Initial initial; - final _Next next; + final _Initial _initial; + final _Next _next; @override - Iterator get iterator => _GeneratingIterator(initial(), next); + Iterator get iterator => _GeneratingIterator(_initial(), _next); } class _GeneratingIterator implements Iterator { @@ -71,7 +72,7 @@ class _GeneratingIterator implements Iterator { bool moveNext() { if (object == null) return false; if (started) { - object = next(object!); + object = next(object as T); } else { started = true; } diff --git a/lib/src/iterables/infinite_iterable.dart b/lib/src/iterables/infinite_iterable.dart index 746d4e0d..a5518870 100644 --- a/lib/src/iterables/infinite_iterable.dart +++ b/lib/src/iterables/infinite_iterable.dart @@ -34,27 +34,30 @@ abstract class InfiniteIterable extends IterableBase { T get single => throw StateError('single'); @override - bool every(bool test(T element)) => throw UnsupportedError('every'); + bool every(bool Function(T element) test) => throw UnsupportedError('every'); @override - T1 fold(T1 initialValue, T1 combine(T1 previousValue, T element)) => + T1 fold( + T1 initialValue, T1 Function(T1 previousValue, T element) combine) => throw UnsupportedError('fold'); @override - void forEach(void action(T element)) => throw UnsupportedError('forEach'); + void forEach(void Function(T element) action) => + throw UnsupportedError('forEach'); @override String join([String separator = '']) => throw UnsupportedError('join'); @override - T lastWhere(bool test(T value), {T orElse()?}) => + T lastWhere(bool Function(T value) test, {T Function()? orElse}) => throw UnsupportedError('lastWhere'); @override - T reduce(T combine(T value, T element)) => throw UnsupportedError('reduce'); + T reduce(T Function(T value, T element) combine) => + throw UnsupportedError('reduce'); @override - T singleWhere(bool test(T value), {T orElse()?}) => + T singleWhere(bool Function(T value) test, {T Function()? orElse}) => throw UnsupportedError('singleWhere'); @override diff --git a/lib/src/iterables/min_max.dart b/lib/src/iterables/min_max.dart index f4121016..8830decf 100644 --- a/lib/src/iterables/min_max.dart +++ b/lib/src/iterables/min_max.dart @@ -20,8 +20,8 @@ /// will be thrown. T? max(Iterable i, [Comparator? compare]) { if (i.isEmpty) return null; - final Comparator _compare = compare ?? _compareAny; - return i.reduce((a, b) => _compare(a, b) > 0 ? a : b); + final Comparator compare0 = compare ?? _compareAny; + return i.reduce((a, b) => compare0(a, b) > 0 ? a : b); } /// Returns the minimum value in [i], according to the order specified by the @@ -32,8 +32,8 @@ T? max(Iterable i, [Comparator? compare]) { /// will be thrown. T? min(Iterable i, [Comparator? compare]) { if (i.isEmpty) return null; - final Comparator _compare = compare ?? _compareAny; - return i.reduce((a, b) => _compare(a, b) < 0 ? a : b); + final Comparator compare0 = compare ?? _compareAny; + return i.reduce((a, b) => compare0(a, b) < 0 ? a : b); } /// Returns the minimum and maximum values in [i], according to the order @@ -49,15 +49,15 @@ T? min(Iterable i, [Comparator? compare]) { /// and [:max:], since there are no valid values for them. Extent extent(Iterable i, [Comparator? compare]) { if (i.isEmpty) return Extent(null, null); - final Comparator _compare = compare ?? _compareAny; + final Comparator compare0 = compare ?? _compareAny; var iterator = i.iterator; var hasNext = iterator.moveNext(); if (!hasNext) return Extent(null, null); var max = iterator.current; var min = iterator.current; while (iterator.moveNext()) { - if (_compare(max, iterator.current) < 0) max = iterator.current; - if (_compare(min, iterator.current) > 0) min = iterator.current; + if (compare0(max, iterator.current) < 0) max = iterator.current; + if (compare0(min, iterator.current) > 0) min = iterator.current; } return Extent(min, max); } diff --git a/lib/testing/src/async/fake_async.dart b/lib/testing/src/async/fake_async.dart index 8e59d774..aaeceedc 100644 --- a/lib/testing/src/async/fake_async.dart +++ b/lib/testing/src/async/fake_async.dart @@ -92,7 +92,7 @@ abstract class FakeAsync { /// /// Calls [callback] with `this` as argument and returns the result returned /// by [callback]. - dynamic run(callback(FakeAsync self)); + dynamic run(Function(FakeAsync self) callback); /// Runs all remaining microtasks, including those scheduled as a result of /// running them, until there are no more microtasks scheduled. @@ -131,7 +131,7 @@ class _FakeAsync implements FakeAsync { Duration _elapsed = Duration.zero; Duration? _elapsingTo; final Queue _microtasks = Queue(); - final Set<_FakeTimer> _timers = Set<_FakeTimer>(); + final Set<_FakeTimer> _timers = <_FakeTimer>{}; @override Clock getClock(DateTime initialTime) => @@ -189,10 +189,10 @@ class _FakeAsync implements FakeAsync { @override List get pendingTimersDebugInfo => - _timers.map((timer) => '${timer.debugInfo}').toList(growable: false); + _timers.map((timer) => timer.debugInfo).toList(growable: false); @override - dynamic run(callback(FakeAsync self)) { + dynamic run(Function(FakeAsync self) callback) { _zone ??= Zone.current.fork(specification: _zoneSpec); dynamic result; _zone!.runGuarded(() { @@ -224,7 +224,7 @@ class _FakeAsync implements FakeAsync { _microtasks.add(microtask); }); - void _drainTimersWhile(bool predicate(_FakeTimer timer)) { + void _drainTimersWhile(bool Function(_FakeTimer timer) predicate) { _drainMicrotasks(); _FakeTimer? next; while ((next = _getNextTimer()) != null && predicate(next!)) { diff --git a/lib/testing/src/time/time.dart b/lib/testing/src/time/time.dart index d89bdd74..6156ab55 100644 --- a/lib/testing/src/time/time.dart +++ b/lib/testing/src/time/time.dart @@ -18,7 +18,7 @@ typedef Now = int Function(); /// A [Stopwatch] implementation that gets the current time in microseconds /// via a user-supplied function. class FakeStopwatch implements Stopwatch { - FakeStopwatch(int now(), this.frequency) + FakeStopwatch(int Function() now, this.frequency) : _now = now, _start = null, _stop = null; diff --git a/pubspec.yaml b/pubspec.yaml index 45b9e164..0e47155e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,12 +8,13 @@ version: 3.2.0-dev # When updating SDK lower bound, also update .github/workflows/dart.yml to test # against the new lower bound. environment: - sdk: '>=2.12.0-0 <3.0.0' + sdk: '>=2.17.0 <3.0.0' dependencies: matcher: ^0.12.10 dev_dependencies: + lints: ^2.0.0 path: ^1.8.0 test: ^1.16.0 #DDC_TEST: build_runner: ^1.3.1 diff --git a/test/collection/delegates/iterable_test.dart b/test/collection/delegates/iterable_test.dart index 76990d63..6492ed03 100644 --- a/test/collection/delegates/iterable_test.dart +++ b/test/collection/delegates/iterable_test.dart @@ -171,8 +171,7 @@ void main() { }); test('toSet', () { - expect(delegatingIterable.toSet(), - equals(Set.from(['a', 'b', 'cc']))); + expect(delegatingIterable.toSet(), equals({'a', 'b', 'cc'})); }); test('where', () { diff --git a/test/collection/delegates/set_test.dart b/test/collection/delegates/set_test.dart index c94087a7..204f0ab0 100644 --- a/test/collection/delegates/set_test.dart +++ b/test/collection/delegates/set_test.dart @@ -14,8 +14,6 @@ library quiver.collection.delegates.set_test; -import 'dart:collection' show LinkedHashSet; - import 'package:quiver/src/collection/delegates/set.dart'; import 'package:test/test.dart'; @@ -33,7 +31,7 @@ void main() { late DelegatingSet delegatingSet; setUp(() { - delegatingSet = MySet(LinkedHashSet.from(['a', 'b', 'cc'])); + delegatingSet = MySet({'a', 'b', 'cc'}); }); test('add', () { @@ -59,16 +57,13 @@ void main() { }); test('difference', () { - expect(delegatingSet.difference(Set.from(['a', 'cc'])), - equals(['b'])); - expect(delegatingSet.difference(Set.from(['cc'])), - equals(['a', 'b'])); + expect(delegatingSet.difference({'a', 'cc'}), equals(['b'])); + expect(delegatingSet.difference({'cc'}), equals(['a', 'b'])); }); test('intersection', () { - expect(delegatingSet.intersection(Set.from(['a', 'dd'])), - equals(['a'])); - expect(delegatingSet.intersection(Set.from(['e'])), equals([])); + expect(delegatingSet.intersection({'a', 'dd'}), equals(['a'])); + expect(delegatingSet.intersection({'e'}), equals([])); }); test('remove', () { @@ -97,8 +92,8 @@ void main() { }); test('union', () { - expect(delegatingSet.union(LinkedHashSet.from(['a', 'cc', 'd'])), - equals(['a', 'b', 'cc', 'd'])); + expect( + delegatingSet.union({'a', 'cc', 'd'}), equals(['a', 'b', 'cc', 'd'])); }); }); } diff --git a/test/collection/multimap_test.dart b/test/collection/multimap_test.dart index 5b1e6e5b..dfcc91f2 100644 --- a/test/collection/multimap_test.dart +++ b/test/collection/multimap_test.dart @@ -436,7 +436,7 @@ void main() { }); test('should call removeWhere with all {key, value} pairs', () { - Set s = Set(); + Set s = {}; ListMultimap() ..add('k1', 'v1') ..add('k1', 'v2') @@ -572,7 +572,7 @@ void main() { }); test('should support iteration over all {key, value} pairs', () { - Set s = Set(); + Set s = {}; ListMultimap() ..add('k1', 'v1') ..add('k1', 'v2') @@ -872,7 +872,7 @@ void main() { }); test('should call removeWhere with all {key, value} pairs', () { - Set s = Set(); + Set s = {}; SetMultimap() ..add('k1', 'v1') ..add('k1', 'v2') @@ -1035,7 +1035,7 @@ void main() { }); test('should support iteration over all {key, value} pairs', () { - Set s = Set(); + Set s = {}; SetMultimap() ..add('k1', 'v1') ..add('k1', 'v2') diff --git a/test/collection/treeset_test.dart b/test/collection/treeset_test.dart index a1a08de1..66accf44 100644 --- a/test/collection/treeset_test.dart +++ b/test/collection/treeset_test.dart @@ -410,7 +410,7 @@ void main() { expectedUnion = [10, 15, 18, 20, 21, 22, 30]; expectedIntersection = [10, 15]; expectedDifference = [20, 21, 30]; - nonSortedTestSet = Set.from([10, 18, 22, 15]); + nonSortedTestSet = {10, 18, 22, 15}; sortedTestSet = TreeSet()..addAll(nonSortedTestSet); }); diff --git a/test/collection/utils_test.dart b/test/collection/utils_test.dart index 568959ae..97b2254d 100644 --- a/test/collection/utils_test.dart +++ b/test/collection/utils_test.dart @@ -51,15 +51,15 @@ void main() { group('setsEqual', () { test('return true for equal sets', () { - expect(setsEqual(Set(), Set()), isTrue); - expect(setsEqual(Set.from([1]), Set.from([1])), isTrue); - expect(setsEqual(Set.from(['a', 'b']), Set.from(['a', 'b'])), isTrue); + expect(setsEqual({}, {}), isTrue); + expect(setsEqual({1}, {1}), isTrue); + expect(setsEqual({'a', 'b'}, {'a', 'b'}), isTrue); }); test('return false for unequal sets', () { - expect(setsEqual(Set.from([1]), Set.from([2])), isFalse); - expect(setsEqual(Set.from([1]), Set()), isFalse); - expect(setsEqual(Set(), Set.from([1])), isFalse); + expect(setsEqual({1}, {2}), isFalse); + expect(setsEqual({1}, {}), isFalse); + expect(setsEqual({}, {1}), isFalse); }); }); diff --git a/test/core/optional_test.dart b/test/core/optional_test.dart index 95640d93..93e69f48 100644 --- a/test/core/optional_test.dart +++ b/test/core/optional_test.dart @@ -103,18 +103,18 @@ void main() { test('hashCode should allow optionals to be in hash sets', () { expect( - Set.from([ + { Optional.of(7), Optional.of(8), const Optional.absent() - ]), - equals(Set.from([ + }, + equals({ Optional.of(7), Optional.of(8), const Optional.absent() - ]))); - expect(Set.from([Optional.of(7), Optional.of(8)]), - isNot(equals(Set.from([Optional.of(7), Optional.of(9)])))); + })); + expect({Optional.of(7), Optional.of(8)}, + isNot(equals({Optional.of(7), Optional.of(9)}))); }); test('== should compare by value', () { diff --git a/test/pattern/glob_test.dart b/test/pattern/glob_test.dart index c28739d7..e63320a3 100644 --- a/test/pattern/glob_test.dart +++ b/test/pattern/glob_test.dart @@ -22,7 +22,7 @@ void main() { test('should match "*" against sequences of word chars', () { expectGlob('*.html', matches: [ 'a.html', - '_-\a.html', + '_-a.html', r'^$*?.html', '()[]{}.html', '↭.html', diff --git a/test/testing/equality/equality_test.dart b/test/testing/equality/equality_test.dart index 8641fd51..b45644df 100644 --- a/test/testing/equality/equality_test.dart +++ b/test/testing/equality/equality_test.dart @@ -191,8 +191,8 @@ void main() { try { expect({ 'broken symmetry': [ - named('foo')..addPeers(['bar']), - named('bar') + _named('foo')..addPeers(['bar']), + _named('bar') ] }, areEqualityGroups); fail('should fail because symmetry is broken'); @@ -208,9 +208,9 @@ void main() { try { expect({ 'transitivity broken': [ - named('foo')..addPeers(['bar', 'baz']), - named('bar')..addPeers(['foo']), - named('baz')..addPeers(['foo']) + _named('foo')..addPeers(['bar', 'baz']), + _named('bar')..addPeers(['foo']), + _named('baz')..addPeers(['foo']) ] }, areEqualityGroups); fail('should fail because transitivity is broken'); @@ -226,7 +226,7 @@ void main() { test('Unequal Objects In EqualityGroup', () { try { expect({ - 'unequal objects': [named('foo'), named('bar')] + 'unequal objects': [_named('foo'), _named('bar')] }, areEqualityGroups); fail('should fail because of unequal objects in the same equality ' 'group'); @@ -242,12 +242,12 @@ void main() { try { expect({ 'transitivity one': [ - named('foo')..addPeers(['bar']), - named('bar')..addPeers(['foo', 'x']) + _named('foo')..addPeers(['bar']), + _named('bar')..addPeers(['foo', 'x']) ], 'transitivity two': [ - named('baz')..addPeers(['x']), - named('x')..addPeers(['baz', 'bar']) + _named('baz')..addPeers(['x']), + _named('x')..addPeers(['baz', 'bar']) ] }, areEqualityGroups); fail('should fail because transitivity is broken'); @@ -263,10 +263,10 @@ void main() { test('EqualityGroups', () { expect({ 'valid groups one': [ - named('foo')..addPeers(['bar']), - named('bar')..addPeers(['foo']) + _named('foo')..addPeers(['bar']), + _named('bar')..addPeers(['foo']) ], - 'valid groups two': [named('baz'), named('baz')] + 'valid groups two': [_named('baz'), _named('baz')] }, areEqualityGroups); }); }); @@ -291,7 +291,7 @@ class _ValidTestObject { @override bool operator ==(Object o) { - if (!(o is _ValidTestObject)) { + if (o is! _ValidTestObject) { return false; } final _ValidTestObject other = o; @@ -337,7 +337,7 @@ class _InconsistentHashCodeObject { @override bool operator ==(Object o) { - if (!(o is _InconsistentHashCodeObject)) { + if (o is! _InconsistentHashCodeObject) { return false; } final _InconsistentHashCodeObject other = o; @@ -361,7 +361,7 @@ class _InvalidHashCodeObject { @override bool operator ==(Object o) { - if (!(o is _InvalidHashCodeObject)) { + if (o is! _InvalidHashCodeObject) { return false; } final _InvalidHashCodeObject other = o; @@ -371,12 +371,12 @@ class _InvalidHashCodeObject { } } -_NamedObject named(String name) => _NamedObject(name); +_NamedObject _named(String name) => _NamedObject(name); class _NamedObject { _NamedObject(this.name); - final Set peerNames = Set(); + final Set peerNames = {}; final String name; void addPeers(List names) { From 0123de71bb3bde74822c15b536c03c608f294a7b Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 14 Nov 2022 11:14:20 -0800 Subject: [PATCH 2/4] oops --- analysis_options.yaml | 5 +++++ lib/src/collection/bimap.dart | 2 +- lib/src/collection/lru_map.dart | 2 +- lib/src/collection/treeset.dart | 4 ++-- lib/src/core/optional.dart | 8 ++++---- lib/src/iterables/generating_iterable.dart | 4 ++-- lib/src/iterables/merge.dart | 2 +- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 2dc1dc35..329edad5 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,6 +1,11 @@ # https://dart.dev/guides/language/analysis-options include: package:lints/recommended.yaml +analyzer: + errors: + # TODO(kevmoo): file an issue on list for this? + null_check_on_nullable_type_parameter: ignore + linter: rules: - always_declare_return_types diff --git a/lib/src/collection/bimap.dart b/lib/src/collection/bimap.dart index 6dd45a3e..cc41456d 100644 --- a/lib/src/collection/bimap.dart +++ b/lib/src/collection/bimap.dart @@ -151,7 +151,7 @@ class HashBiMap implements BiMap { @override void updateAll(V Function(K key, V value) update) { for (final key in keys) { - _add(key, update(key, _map[key] as V), true); + _add(key, update(key, _map[key]!), true); } } diff --git a/lib/src/collection/lru_map.dart b/lib/src/collection/lru_map.dart index b0a927eb..fabbcf72 100644 --- a/lib/src/collection/lru_map.dart +++ b/lib/src/collection/lru_map.dart @@ -290,7 +290,7 @@ class LinkedLruHashMap implements LruMap { V update(K key, V Function(V value) update, {V Function()? ifAbsent}) { V newValue; if (containsKey(key)) { - newValue = update(this[key] as V); + newValue = update(this[key]!); } else { if (ifAbsent == null) { throw ArgumentError.value(key, 'key', 'Key not in map'); diff --git a/lib/src/collection/treeset.dart b/lib/src/collection/treeset.dart index 881218a3..1fde033d 100644 --- a/lib/src/collection/treeset.dart +++ b/lib/src/collection/treeset.dart @@ -919,7 +919,7 @@ class TreeIterator _movePrevious = reversed ? _moveNextNormal : _movePreviousNormal; if (_current == null) { _state = reversed ? _left : _right; - } else if (tree.comparator(_current!.object, _anchorObject as V) == 0 && + } else if (tree.comparator(_current!.object, _anchorObject!) == 0 && !inclusive) { _moveNext(); } @@ -933,7 +933,7 @@ class TreeIterator _movePrevious = reversed ? _moveNextNormal : _movePreviousNormal; if (_current == null) { _state = reversed ? _right : _left; - } else if (tree.comparator(_current!.object, _anchorObject as V) == 0 && + } else if (tree.comparator(_current!.object, _anchorObject!) == 0 && !inclusive) { _movePrevious(); } diff --git a/lib/src/core/optional.dart b/lib/src/core/optional.dart index f2129545..ed8ec894 100644 --- a/lib/src/core/optional.dart +++ b/lib/src/core/optional.dart @@ -62,7 +62,7 @@ class Optional extends IterableBase { /// Executes a function if the Optional value is present. void ifPresent(void Function(T value) ifPresent) { if (isPresent) { - ifPresent(_value as T); + ifPresent(_value!); } } @@ -93,7 +93,7 @@ class Optional extends IterableBase { Optional transform(S Function(T value) transformer) { return _value == null ? Optional.absent() - : Optional.of(transformer(_value as T)); + : Optional.of(transformer(_value!)); } /// Transforms the Optional value. @@ -105,12 +105,12 @@ class Optional extends IterableBase { S? Function(T value) transformer) { return _value == null ? Optional.absent() - : Optional.fromNullable(transformer(_value as T)); + : Optional.fromNullable(transformer(_value!)); } @override Iterator get iterator => - isPresent ? [_value as T].iterator : Iterable.empty().iterator; + isPresent ? [_value!].iterator : Iterable.empty().iterator; /// Delegates to the underlying [value] hashCode. @override diff --git a/lib/src/iterables/generating_iterable.dart b/lib/src/iterables/generating_iterable.dart index 992ad0c6..2a03d4eb 100644 --- a/lib/src/iterables/generating_iterable.dart +++ b/lib/src/iterables/generating_iterable.dart @@ -65,14 +65,14 @@ class _GeneratingIterator implements Iterator { @override T get current { final cur = started ? object : null; - return cur as T; + return cur!; } @override bool moveNext() { if (object == null) return false; if (started) { - object = next(object as T); + object = next(object!); } else { started = true; } diff --git a/lib/src/iterables/merge.dart b/lib/src/iterables/merge.dart index 8385ca05..3390df5a 100644 --- a/lib/src/iterables/merge.dart +++ b/lib/src/iterables/merge.dart @@ -95,6 +95,6 @@ class _MergeIterator implements Iterator { @override T get current { - return _current as T; + return _current!; } } From 5cb84fa299468279efa8ca13c9d96b1bf3ec6e77 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 14 Nov 2022 14:50:57 -0800 Subject: [PATCH 3/4] update ignore item Also drop private typedefs --- analysis_options.yaml | 2 +- lib/src/async/stream_router.dart | 4 +--- lib/src/collection/treeset.dart | 6 ++---- lib/src/iterables/generating_iterable.dart | 9 +++------ lib/weird_lint.dart | 13 +++++++++++++ 5 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 lib/weird_lint.dart diff --git a/analysis_options.yaml b/analysis_options.yaml index 329edad5..deee90df 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -3,7 +3,7 @@ include: package:lints/recommended.yaml analyzer: errors: - # TODO(kevmoo): file an issue on list for this? + # TODO(kevmoo): see https://github.com/dart-lang/linter/issues/3844 null_check_on_nullable_type_parameter: ignore linter: diff --git a/lib/src/async/stream_router.dart b/lib/src/async/stream_router.dart index 9abf98ee..d7a9deae 100644 --- a/lib/src/async/stream_router.dart +++ b/lib/src/async/stream_router.dart @@ -72,11 +72,9 @@ class StreamRouter { } } -typedef _Predicate = bool Function(T event); - class _Route { _Route(this.predicate, this.controller); - final _Predicate predicate; + final bool Function(T event) predicate; final StreamController controller; } diff --git a/lib/src/collection/treeset.dart b/lib/src/collection/treeset.dart index 1fde033d..c42cc704 100644 --- a/lib/src/collection/treeset.dart +++ b/lib/src/collection/treeset.dart @@ -886,8 +886,6 @@ AvlNode? debugGetNode(AvlTreeSet treeset, V object) { return treeset._getNode(object); } -typedef _IteratorMove = bool Function(); - /// This iterator either starts at the beginning or end (see [TreeSet.iterator] /// and [TreeSet.reverseIterator]) or from an anchor point in the set (see /// [TreeSet.fromIterator]). When using fromIterator, the initial anchor point @@ -951,8 +949,8 @@ class TreeIterator final V? _anchorObject; final bool inclusive; - late _IteratorMove _moveNext; - late _IteratorMove _movePrevious; + late bool Function() _moveNext; + late bool Function() _movePrevious; late int _state; _TreeNode? _current; diff --git a/lib/src/iterables/generating_iterable.dart b/lib/src/iterables/generating_iterable.dart index 2a03d4eb..8facce80 100644 --- a/lib/src/iterables/generating_iterable.dart +++ b/lib/src/iterables/generating_iterable.dart @@ -14,9 +14,6 @@ import 'dart:collection'; -typedef _Initial = T Function(); -typedef _Next = T? Function(T value); - Iterable generate(Function() initial, Function(dynamic) next) => GeneratingIterable(initial, next); @@ -48,8 +45,8 @@ Iterable generate(Function() initial, Function(dynamic) next) => class GeneratingIterable extends IterableBase { GeneratingIterable(this._initial, this._next); - final _Initial _initial; - final _Next _next; + final T Function() _initial; + final T? Function(T value) _next; @override Iterator get iterator => _GeneratingIterator(_initial(), _next); @@ -58,7 +55,7 @@ class GeneratingIterable extends IterableBase { class _GeneratingIterator implements Iterator { _GeneratingIterator(this.object, this.next); - final _Next next; + final T? Function(T value) next; T? object; bool started = false; diff --git a/lib/weird_lint.dart b/lib/weird_lint.dart new file mode 100644 index 00000000..0f0a9b7c --- /dev/null +++ b/lib/weird_lint.dart @@ -0,0 +1,13 @@ +class Monkey { + Monkey(this._value); + final T? _value; + + /// Transforms the Optional value. + /// + /// If the Optional is [absent()], returns [absent()] without applying the transformer. + /// + /// Returns [absent()] if the transformer returns [null]. + bool transformNullable(bool Function(T value) transformer) { + return _value == null || transformer(_value!); + } +} From 367edb2b75e0bdfd25b30fbf77f6b7df0caf9c87 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 14 Nov 2022 16:08:17 -0800 Subject: [PATCH 4/4] ooops --- lib/weird_lint.dart | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 lib/weird_lint.dart diff --git a/lib/weird_lint.dart b/lib/weird_lint.dart deleted file mode 100644 index 0f0a9b7c..00000000 --- a/lib/weird_lint.dart +++ /dev/null @@ -1,13 +0,0 @@ -class Monkey { - Monkey(this._value); - final T? _value; - - /// Transforms the Optional value. - /// - /// If the Optional is [absent()], returns [absent()] without applying the transformer. - /// - /// Returns [absent()] if the transformer returns [null]. - bool transformNullable(bool Function(T value) transformer) { - return _value == null || transformer(_value!); - } -}