From 69a6423fd518ac11ff485ac8fea7608176c9b272 Mon Sep 17 00:00:00 2001 From: Gabriel Terwesten Date: Sat, 21 May 2022 00:01:33 +0200 Subject: [PATCH] refactor: enable more lint rules (#376) --- ...alysis_options.yaml => all_lint_rules.yaml | 56 ++++++++++--------- analysis_options.yaml | 15 +++++ .../cbl/lib/src/database/ffi_blob_store.dart | 8 +-- .../cbl/lib/src/database/ffi_database.dart | 2 +- packages/cbl/lib/src/document/common.dart | 6 +- .../cbl/lib/src/document/ffi_document.dart | 4 +- packages/cbl/lib/src/document/fragment.dart | 2 +- packages/cbl/lib/src/fleece/containers.dart | 20 +++---- packages/cbl/lib/src/fleece/decoder.dart | 6 +- packages/cbl/lib/src/fleece/dict_key.dart | 4 +- packages/cbl/lib/src/fleece/encoder.dart | 2 +- .../cbl/lib/src/fleece/integration/array.dart | 2 +- .../lib/src/fleece/integration/delegate.dart | 2 +- packages/cbl/lib/src/log/console_logger.dart | 2 +- packages/cbl/lib/src/log/file_logger.dart | 2 +- packages/cbl/lib/src/log/logger.dart | 2 +- packages/cbl/lib/src/query/ffi_query.dart | 4 +- .../lib/src/replication/ffi_replicator.dart | 2 +- .../cbl/lib/src/support/async_callback.dart | 2 +- packages/cbl/lib/src/support/ffi.dart | 2 +- packages/cbl/lib/src/support/streams.dart | 2 +- .../cbl/lib/src/typed_data/collection.dart | 1 + packages/cbl/lib/src/typed_data/registry.dart | 2 +- packages/cbl_e2e_tests/analysis_options.yaml | 2 +- .../lib/src/document/blob_test.dart | 24 ++++---- .../lib/src/fleece/coding_test.dart | 4 +- .../lib/src/fleece/integration_test.dart | 4 +- .../lib/src/query/query_builder_test.dart | 4 +- .../cbl_e2e_tests/lib/src/test_binding.dart | 4 +- .../lib/src/utils/database_utils.dart | 2 +- .../cbl_e2e_tests/lib/src/utils/matchers.dart | 2 +- .../lib/src/utils/time_bomb.dart | 2 +- packages/cbl_e2e_tests/pubspec.yaml | 3 + packages/cbl_e2e_tests_flutter/pubspec.yaml | 3 + .../pubspec.yaml | 3 + packages/cbl_ffi/analysis_options.yaml | 2 +- packages/cbl_ffi/lib/src/base.dart | 12 ++-- packages/cbl_ffi/lib/src/global.dart | 24 ++++---- packages/cbl_ffi/lib/src/libraries.dart | 12 ++-- packages/cbl_ffi/lib/src/slice.dart | 4 +- packages/cbl_flutter/example/lib/main.dart | 10 ++-- .../lib/src/sentry_tracing_delegate.dart | 4 +- 42 files changed, 154 insertions(+), 121 deletions(-) rename packages/analysis_options.yaml => all_lint_rules.yaml (85%) create mode 100644 analysis_options.yaml diff --git a/packages/analysis_options.yaml b/all_lint_rules.yaml similarity index 85% rename from packages/analysis_options.yaml rename to all_lint_rules.yaml index 65c7c379..f30e27a9 100644 --- a/packages/analysis_options.yaml +++ b/all_lint_rules.yaml @@ -1,14 +1,12 @@ -analyzer: - strong-mode: - implicit-dynamic: false - implicit-casts: false - +# Uncommented rules are to conflicting with another rule. linter: rules: - always_declare_return_types - always_put_control_body_on_new_line - # - always_put_required_named_parameters_first + - always_put_required_named_parameters_first - always_require_non_null_named_parameters + # - always_specify_types + - always_use_package_imports - annotate_overrides - avoid_annotating_with_dynamic - avoid_bool_literals_in_conditional_expressions @@ -21,6 +19,7 @@ linter: - avoid_equals_and_hash_code_on_mutable_classes - avoid_escaping_inner_quotes - avoid_field_initializers_in_const_classes + - avoid_final_parameters - avoid_function_literals_in_foreach_calls - avoid_implementing_value_types - avoid_init_to_null @@ -57,20 +56,19 @@ linter: - cast_nullable_to_non_nullable - close_sinks - comment_references + - conditional_uri_does_not_exist - constant_identifier_names - control_flow_in_finally - curly_braces_in_flow_control_structures - # Unreleased - # - depend_on_referenced_packages + - depend_on_referenced_packages - deprecated_consistency - # - diagnostic_describe_all_properties + - diagnostic_describe_all_properties - directives_ordering - do_not_use_environment - empty_catches - empty_constructor_bodies - empty_statements - # Unreleased - # - eol_at_end_of_file + - eol_at_end_of_file - exhaustive_cases - file_names - flutter_style_todos @@ -82,8 +80,7 @@ linter: - leading_newlines_in_multiline_strings - library_names - library_prefixes - # Unreleased - # - library_private_types_in_public_api + - library_private_types_in_public_api - lines_longer_than_80_chars - list_remove_unrelated_type - literal_only_boolean_expressions @@ -91,11 +88,12 @@ linter: - no_adjacent_strings_in_list - no_default_cases - no_duplicate_case_values + - no_leading_underscores_for_library_prefixes + - no_leading_underscores_for_local_identifiers - no_logic_in_create_state - no_runtimeType_toString - non_constant_identifier_names - # Unreleased - # - noop_primitive_operations + - noop_primitive_operations - null_check_on_nullable_type_parameter - null_closures - omit_local_variable_types @@ -108,6 +106,7 @@ linter: - parameter_assignments - prefer_adjacent_string_concatenation - prefer_asserts_in_initializer_lists + - prefer_asserts_with_message - prefer_collection_literals - prefer_conditional_assignment - prefer_const_constructors @@ -116,11 +115,13 @@ linter: - prefer_const_literals_to_create_immutables - prefer_constructors_over_static_methods - prefer_contains + # - prefer_double_quotes - prefer_equal_for_default_values - prefer_expression_function_bodies - prefer_final_fields - prefer_final_in_for_each - prefer_final_locals + # - prefer_final_parameters - prefer_for_elements_to_map_fromIterable - prefer_foreach - prefer_function_declarations_over_variables @@ -136,8 +137,7 @@ linter: - prefer_is_not_operator - prefer_iterable_whereType - prefer_mixin - # Unreleased - # - prefer_null_aware_method_calls + - prefer_null_aware_method_calls - prefer_null_aware_operators - prefer_relative_imports - prefer_single_quotes @@ -145,12 +145,12 @@ linter: - prefer_typing_uninitialized_variables - prefer_void_to_null - provide_deprecation_message - # Not all private types are documented - # - public_member_api_docs + - public_member_api_docs - recursive_getters - # Experimental - # - require_trailing_commas + - require_trailing_commas + - secure_pubspec_urls - sized_box_for_whitespace + - sized_box_shrink_expand - slash_for_doc_comments - sort_child_properties_last - sort_constructors_first @@ -165,8 +165,11 @@ linter: - unnecessary_await_in_return - unnecessary_brace_in_string_interps - unnecessary_const + - unnecessary_constructor_name + # - unnecessary_final - unnecessary_getters_setters - unnecessary_lambdas + - unnecessary_late - unnecessary_new - unnecessary_null_aware_assignments - unnecessary_null_checks @@ -182,10 +185,12 @@ linter: - unrelated_type_equality_checks - unsafe_html - use_build_context_synchronously + - use_colored_box + - use_decorated_box + - use_enums - use_full_hex_values_for_flutter_colors - use_function_type_syntax_for_parameters - # Unreleased - # - use_if_null_to_convert_nulls_to_bools + - use_if_null_to_convert_nulls_to_bools - use_is_even_rather_than_modulo - use_key_in_widget_constructors - use_late_for_private_fields_and_variables @@ -194,9 +199,8 @@ linter: - use_rethrow_when_possible - use_setters_to_change_properties - use_string_buffers - # Unreleased - # - use_test_throws_matchers + - use_super_parameters + - use_test_throws_matchers - use_to_and_as_if_applicable - valid_regexps - void_checks - - use_super_parameters diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 00000000..1d2edce3 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,15 @@ +include: all_lint_rules.yaml + +analyzer: + language: + strict-casts: true + strict-inference: true + strict-raw-types: false + +linter: + rules: + always_put_required_named_parameters_first: false + always_use_package_imports: false + prefer_asserts_with_message: false + public_member_api_docs: false + require_trailing_commas: false diff --git a/packages/cbl/lib/src/database/ffi_blob_store.dart b/packages/cbl/lib/src/database/ffi_blob_store.dart index 289a3722..fb65ab4f 100644 --- a/packages/cbl/lib/src/database/ffi_blob_store.dart +++ b/packages/cbl/lib/src/database/ffi_blob_store.dart @@ -16,8 +16,8 @@ import 'ffi_database.dart'; class FfiBlobStore implements BlobStore, SyncBlobStore { FfiBlobStore(this.database); - static late final _databaseBindings = cblBindings.database; - static late final _blobBindings = cblBindings.blobs.blob; + static final _databaseBindings = cblBindings.database; + static final _blobBindings = cblBindings.blobs.blob; final FfiDatabase database; @@ -111,7 +111,7 @@ class FfiBlobStore implements BlobStore, SyncBlobStore { } } -late final _writeStreamBindings = cblBindings.blobs.writeStream; +final _writeStreamBindings = cblBindings.blobs.writeStream; Future> _createBlobFromStream( FfiDatabase database, @@ -144,7 +144,7 @@ class _BlobReadStream extends Stream { /// Size of the chunks which a blob read stream emits. static const _readStreamChunkSize = 8 * 1024; - static late final _readStreamBindings = cblBindings.blobs.readStream; + static final _readStreamBindings = cblBindings.blobs.readStream; final ClosableResourceMixin parent; final CBLObject blob; diff --git a/packages/cbl/lib/src/database/ffi_database.dart b/packages/cbl/lib/src/database/ffi_database.dart index b96b60a2..d804c55a 100644 --- a/packages/cbl/lib/src/database/ffi_database.dart +++ b/packages/cbl/lib/src/database/ffi_database.dart @@ -33,7 +33,7 @@ import 'database_configuration.dart'; import 'document_change.dart'; import 'ffi_blob_store.dart'; -late final _bindings = cblBindings.database; +final _bindings = cblBindings.database; class FfiDatabase extends CBLDatabaseObject with DatabaseBase, ClosableResourceMixin diff --git a/packages/cbl/lib/src/document/common.dart b/packages/cbl/lib/src/document/common.dart index eece6c52..537e86b4 100644 --- a/packages/cbl/lib/src/document/common.dart +++ b/packages/cbl/lib/src/document/common.dart @@ -16,9 +16,9 @@ import 'array.dart'; import 'blob.dart'; import 'dictionary.dart'; -late final _blobBindings = cblBindings.blobs.blob; -late final _valueBinds = cblBindings.fleece.value; -late final _decoderBinds = cblBindings.fleece.decoder; +final _blobBindings = cblBindings.blobs.blob; +final _valueBinds = cblBindings.fleece.value; +final _decoderBinds = cblBindings.fleece.decoder; abstract class CblConversions { Object? toPlainObject(); diff --git a/packages/cbl/lib/src/document/ffi_document.dart b/packages/cbl/lib/src/document/ffi_document.dart index 2d03aa00..0e1a155a 100644 --- a/packages/cbl/lib/src/document/ffi_document.dart +++ b/packages/cbl/lib/src/document/ffi_document.dart @@ -11,8 +11,8 @@ import '../support/native_object.dart'; import '../support/resource.dart'; import 'document.dart'; -late final _documentBindings = cblBindings.document; -late final _mutableDocumentBindings = cblBindings.mutableDocument; +final _documentBindings = cblBindings.document; +final _mutableDocumentBindings = cblBindings.mutableDocument; class FfiDocumentDelegate extends DocumentDelegate implements NativeResource { diff --git a/packages/cbl/lib/src/document/fragment.dart b/packages/cbl/lib/src/document/fragment.dart index ee4b336c..b94ad772 100644 --- a/packages/cbl/lib/src/document/fragment.dart +++ b/packages/cbl/lib/src/document/fragment.dart @@ -447,7 +447,7 @@ class MutableFragmentImpl extends FragmentImpl implements MutableFragment { } @override - MutableFragment operator [](final Object indexOrKey) => + MutableFragment operator [](Object indexOrKey) => _updateSubscript(indexOrKey) ? this : _emptyInstance; void _checkHasParent() { diff --git a/packages/cbl/lib/src/fleece/containers.dart b/packages/cbl/lib/src/fleece/containers.dart index 2e3aabea..c8481f5a 100644 --- a/packages/cbl/lib/src/fleece/containers.dart +++ b/packages/cbl/lib/src/fleece/containers.dart @@ -42,7 +42,7 @@ class SharedKeys extends FleeceSharedKeysObject { /// Creates [SharedKeys] from an exiting native instance. SharedKeys.fromPointer(super.pointer, {super.adopt}); - static late final _bindings = cblBindings.fleece.sharedKeys; + static final _bindings = cblBindings.fleece.sharedKeys; /// The number of keys in the mapping. /// @@ -84,7 +84,7 @@ class Doc extends FleeceDocObject { /// Note: Does not retain the native doc. Doc.fromPointer(super.pointer); - static late final _bindings = cblBindings.fleece.doc; + static final _bindings = cblBindings.fleece.doc; /// Returns the data owned by the document, if any, else `null`. SliceResult? get allocedData { @@ -174,7 +174,7 @@ class Value extends FleeceValueObject { adopt: adopt, ); - static late final _bindings = cblBindings.fleece.value; + static final _bindings = cblBindings.fleece.value; /// Looks up the Doc containing the Value, or null if the Value was created /// without a Doc. @@ -379,7 +379,7 @@ class Array extends Value with ListMixin { adopt: adopt, ); - static late final _bindings = cblBindings.fleece.array; + static final _bindings = cblBindings.fleece.array; @override int get length { @@ -476,7 +476,7 @@ class MutableArray extends Array { return result; } - static late final _bindings = cblBindings.fleece.mutableArray; + static final _bindings = cblBindings.fleece.mutableArray; /// If the Array was created by [MutableArray.mutableCopy], returns the /// original source Array. @@ -596,7 +596,7 @@ class Dict extends Value with MapMixin { adopt: adopt, ); - static late final _bindings = cblBindings.fleece.dict; + static final _bindings = cblBindings.fleece.dict; /// Returns the number of items in a dictionary. @override @@ -747,7 +747,7 @@ class MutableDict extends Dict { return result; } - static late final _bindings = cblBindings.fleece.mutableDict; + static final _bindings = cblBindings.fleece.mutableDict; /// If the Dict was created by [MutableDict.mutableCopy], returns the original /// source Dict. @@ -787,11 +787,11 @@ class MutableDict extends Dict { @override Value? remove(Object? key) { - final _key = assertKey(key); + final stringKey = assertKey(key); - final value = this[_key]; + final value = this[stringKey]; - _bindings.remove(pointer.cast(), _key); + _bindings.remove(pointer.cast(), stringKey); cblReachabilityFence(this); return value; diff --git a/packages/cbl/lib/src/fleece/decoder.dart b/packages/cbl/lib/src/fleece/decoder.dart index c92a99c2..bf471bfd 100644 --- a/packages/cbl/lib/src/fleece/decoder.dart +++ b/packages/cbl/lib/src/fleece/decoder.dart @@ -8,7 +8,7 @@ import 'package:cbl_ffi/cbl_ffi.dart'; import '../support/ffi.dart'; import 'containers.dart'; -late final _decoderBinds = cblBindings.fleece.decoder; +final _decoderBinds = cblBindings.fleece.decoder; /// Returns a string which shows how values are encoded in the Fleece [data]. /// @@ -547,12 +547,12 @@ class _ArrayIndexLoader extends _FleeceValueLoader { class _DictIteratorLoader extends _FleeceValueLoader { _DictIteratorLoader( - Pointer _dict, + Pointer dict, this._listener, this._sharedKeysTable, this._sharedStringsTable, ) : _it = DictIterator( - _dict, + dict, sharedKeysTable: _sharedKeysTable, keyOut: globalLoadedDictKey, valueOut: globalLoadedFLValue, diff --git a/packages/cbl/lib/src/fleece/dict_key.dart b/packages/cbl/lib/src/fleece/dict_key.dart index 286da2f4..f399356a 100644 --- a/packages/cbl/lib/src/fleece/dict_key.dart +++ b/packages/cbl/lib/src/fleece/dict_key.dart @@ -7,8 +7,8 @@ import 'package:cbl_ffi/cbl_ffi.dart'; import '../support/ffi.dart'; import 'encoder.dart'; -late final _dictBinds = cblBindings.fleece.dict; -late final _dictKeyBinds = cblBindings.fleece.dictKey; +final _dictBinds = cblBindings.fleece.dict; +final _dictKeyBinds = cblBindings.fleece.dictKey; /// A Fleece dictionary key for efficient decoding and encoding of dictionaries. abstract class DictKey { diff --git a/packages/cbl/lib/src/fleece/encoder.dart b/packages/cbl/lib/src/fleece/encoder.dart index 9b9493a4..9bee6463 100644 --- a/packages/cbl/lib/src/fleece/encoder.dart +++ b/packages/cbl/lib/src/fleece/encoder.dart @@ -9,7 +9,7 @@ import '../support/ffi.dart'; import '../support/native_object.dart'; import 'containers.dart'; -late final _encoderBinds = cblBindings.fleece.encoder; +final _encoderBinds = cblBindings.fleece.encoder; /// An encoder, which generates encoded Fleece or JSON data. /// diff --git a/packages/cbl/lib/src/fleece/integration/array.dart b/packages/cbl/lib/src/fleece/integration/array.dart index 5adbb076..95b2df12 100644 --- a/packages/cbl/lib/src/fleece/integration/array.dart +++ b/packages/cbl/lib/src/fleece/integration/array.dart @@ -10,7 +10,7 @@ import '../encoder.dart'; import 'collection.dart'; import 'value.dart'; -late final _arrayBindings = cblBindings.fleece.array; +final _arrayBindings = cblBindings.fleece.array; class MArray extends MCollection { MArray() diff --git a/packages/cbl/lib/src/fleece/integration/delegate.dart b/packages/cbl/lib/src/fleece/integration/delegate.dart index fe902083..95f94846 100644 --- a/packages/cbl/lib/src/fleece/integration/delegate.dart +++ b/packages/cbl/lib/src/fleece/integration/delegate.dart @@ -12,7 +12,7 @@ import 'collection.dart'; import 'dict.dart'; import 'value.dart'; -late final _decoderBinds = cblBindings.fleece.decoder; +final _decoderBinds = cblBindings.fleece.decoder; abstract class MDelegate { static MDelegate? instance; diff --git a/packages/cbl/lib/src/log/console_logger.dart b/packages/cbl/lib/src/log/console_logger.dart index 85b65d92..9bb89b07 100644 --- a/packages/cbl/lib/src/log/console_logger.dart +++ b/packages/cbl/lib/src/log/console_logger.dart @@ -15,7 +15,7 @@ abstract class ConsoleLogger { set level(LogLevel value); } -late final _bindings = cblBindings.logging; +final _bindings = cblBindings.logging; class ConsoleLoggerImpl extends ConsoleLogger { ConsoleLoggerImpl() : super._(); diff --git a/packages/cbl/lib/src/log/file_logger.dart b/packages/cbl/lib/src/log/file_logger.dart index 0d28368b..456d14b4 100644 --- a/packages/cbl/lib/src/log/file_logger.dart +++ b/packages/cbl/lib/src/log/file_logger.dart @@ -126,7 +126,7 @@ abstract class FileLogger { // === Impl ==================================================================== -late final _bindings = cblBindings.logging; +final _bindings = cblBindings.logging; class FileLoggerImpl extends FileLogger { FileLoggerImpl() : super._(); diff --git a/packages/cbl/lib/src/log/logger.dart b/packages/cbl/lib/src/log/logger.dart index 21a7e3d1..6b43f58c 100644 --- a/packages/cbl/lib/src/log/logger.dart +++ b/packages/cbl/lib/src/log/logger.dart @@ -170,7 +170,7 @@ extension LogLevelExt on LogLevel { CBLLogLevel toCBLLogLevel() => CBLLogLevel.values[index]; } -late final _bindings = cblBindings.logging; +final _bindings = cblBindings.logging; Logger? _logger; void Function(List)? _loggerCallback; diff --git a/packages/cbl/lib/src/query/ffi_query.dart b/packages/cbl/lib/src/query/ffi_query.dart index 28c6f635..da5c2634 100644 --- a/packages/cbl/lib/src/query/ffi_query.dart +++ b/packages/cbl/lib/src/query/ffi_query.dart @@ -32,7 +32,7 @@ import 'result.dart'; import 'result_set.dart'; import 'select_result.dart'; -late final _bindings = cblBindings.query; +final _bindings = cblBindings.query; class FfiQuery extends QueryBase implements SyncQuery, NativeResource { @@ -273,7 +273,7 @@ class ResultSetIterator extends CBLObject required String debugCreator, }) : super(debugName: 'ResultSetIterator(creator: $debugCreator)'); - static late final _bindings = cblBindings.resultSet; + static final _bindings = cblBindings.resultSet; final bool encodeArray; var _isDone = false; diff --git a/packages/cbl/lib/src/replication/ffi_replicator.dart b/packages/cbl/lib/src/replication/ffi_replicator.dart index c6cf3eaa..69e83fa6 100644 --- a/packages/cbl/lib/src/replication/ffi_replicator.dart +++ b/packages/cbl/lib/src/replication/ffi_replicator.dart @@ -27,7 +27,7 @@ import 'endpoint.dart'; import 'replicator.dart'; import 'replicator_change.dart'; -late final _bindings = cblBindings.replicator; +final _bindings = cblBindings.replicator; class FfiReplicator with ClosableResourceMixin diff --git a/packages/cbl/lib/src/support/async_callback.dart b/packages/cbl/lib/src/support/async_callback.dart index 277efc66..ca2c6dcb 100644 --- a/packages/cbl/lib/src/support/async_callback.dart +++ b/packages/cbl/lib/src/support/async_callback.dart @@ -14,7 +14,7 @@ typedef AsyncCallbackHandler = FutureOr Function( List arguments, ); -late final _bindings = cblBindings.asyncCallback; +final _bindings = cblBindings.asyncCallback; var _nextId = 0; int _generateId() { diff --git a/packages/cbl/lib/src/support/ffi.dart b/packages/cbl/lib/src/support/ffi.dart index b4dcc005..b8ea87ed 100644 --- a/packages/cbl/lib/src/support/ffi.dart +++ b/packages/cbl/lib/src/support/ffi.dart @@ -6,7 +6,7 @@ import 'errors.dart'; /// Convenience accessor for `CBLBindings.instance`, which throws an informative /// error when used before the bindings are initialized. -late final ffi.CBLBindings cblBindings = () { +final ffi.CBLBindings cblBindings = () { final bindings = ffi.CBLBindings.maybeInstance; if (bindings == null) { throwNotInitializedError(); diff --git a/packages/cbl/lib/src/support/streams.dart b/packages/cbl/lib/src/support/streams.dart index 12e358d9..79345b7c 100644 --- a/packages/cbl/lib/src/support/streams.dart +++ b/packages/cbl/lib/src/support/streams.dart @@ -95,7 +95,7 @@ class ResourceStream extends Stream with ClosableResourceMixin { onData, // ignore: avoid_types_on_closure_parameters onError: (Object error, StackTrace stackTrace) { - if (cancelOnError == true) { + if (cancelOnError ?? false) { _makeDone(); } diff --git a/packages/cbl/lib/src/typed_data/collection.dart b/packages/cbl/lib/src/typed_data/collection.dart index 750b957c..29406972 100644 --- a/packages/cbl/lib/src/typed_data/collection.dart +++ b/packages/cbl/lib/src/typed_data/collection.dart @@ -301,6 +301,7 @@ class CachedTypedDataList extends ListMixin with _TypedDataListToString implements TypedDataList { CachedTypedDataList( + // ignore: library_private_types_in_public_api this._base, { required bool growable, }) : _cache = List.filled(_base.length, null, growable: growable); diff --git a/packages/cbl/lib/src/typed_data/registry.dart b/packages/cbl/lib/src/typed_data/registry.dart index f5093b6e..87f9d131 100644 --- a/packages/cbl/lib/src/typed_data/registry.dart +++ b/packages/cbl/lib/src/typed_data/registry.dart @@ -228,7 +228,7 @@ class TypedDataRegistry extends TypedDataAdapter { Document document, ) => _types.whereType().where( - (metadata) => metadata._typeMatcherImpl?.isMatch(document) == true, + (metadata) => metadata._typeMatcherImpl?.isMatch(document) ?? false, ); Factory? diff --git a/packages/cbl_e2e_tests/analysis_options.yaml b/packages/cbl_e2e_tests/analysis_options.yaml index 94e5a7bc..ed4f23a9 100644 --- a/packages/cbl_e2e_tests/analysis_options.yaml +++ b/packages/cbl_e2e_tests/analysis_options.yaml @@ -1,4 +1,4 @@ -include: ../analysis_options.yaml +include: ../../analysis_options.yaml linter: rules: diff --git a/packages/cbl_e2e_tests/lib/src/document/blob_test.dart b/packages/cbl_e2e_tests/lib/src/document/blob_test.dart index 9573ecae..b9693bd3 100644 --- a/packages/cbl_e2e_tests/lib/src/document/blob_test.dart +++ b/packages/cbl_e2e_tests/lib/src/document/blob_test.dart @@ -100,13 +100,12 @@ void main() { final content = randomTestContent(large: blobSize.value == BlobSize.large); - - Blob? _writeBlob; + Blob? writeBlobInstance; final doc = MutableDocument(); switch (writeBlob.value) { case WriteBlob.data: - _writeBlob = Blob.fromData(contentType, content); + writeBlobInstance = Blob.fromData(contentType, content); break; case WriteBlob.properties: final blob = Blob.fromData(contentType, content); @@ -114,37 +113,38 @@ void main() { doc['blob'].value = blob.properties; break; case WriteBlob.stream: - _writeBlob = Blob.fromStream(contentType, Stream.value(content)); + writeBlobInstance = + Blob.fromStream(contentType, Stream.value(content)); if (api.value == Api.sync) { - await db.saveBlob(_writeBlob); + await db.saveBlob(writeBlobInstance); } break; } - if (_writeBlob != null) { - doc['blob'].value = _writeBlob; + if (writeBlobInstance != null) { + doc['blob'].value = writeBlobInstance; } Future read() async { - Blob _readBlob; + Blob readBlobInstance; switch (readBlob.value) { case ReadBlob.sourceBlob: - _readBlob = _writeBlob!; + readBlobInstance = writeBlobInstance!; break; case ReadBlob.loadedBlob: final loadedDoc = (await db.document(doc.id))!; - _readBlob = loadedDoc.blob('blob')!; + readBlobInstance = loadedDoc.blob('blob')!; break; } switch (readMode.value) { case ReadMode.future: - expect(await _readBlob.content(), content); + expect(await readBlobInstance.content(), content); break; case ReadMode.stream: expect( - await byteStreamToFuture(_readBlob.contentStream()), + await byteStreamToFuture(readBlobInstance.contentStream()), content, ); break; diff --git a/packages/cbl_e2e_tests/lib/src/fleece/coding_test.dart b/packages/cbl_e2e_tests/lib/src/fleece/coding_test.dart index 4fbf8337..3ffeae19 100644 --- a/packages/cbl_e2e_tests/lib/src/fleece/coding_test.dart +++ b/packages/cbl_e2e_tests/lib/src/fleece/coding_test.dart @@ -7,8 +7,8 @@ import 'package:cbl_ffi/cbl_ffi.dart'; import '../../test_binding_impl.dart'; import '../test_binding.dart'; -late final _decoderBinds = CBLBindings.instance.fleece.decoder; -late final _valueBinds = CBLBindings.instance.fleece.value; +final _decoderBinds = CBLBindings.instance.fleece.decoder; +final _valueBinds = CBLBindings.instance.fleece.value; void main() { setupTestBinding(); diff --git a/packages/cbl_e2e_tests/lib/src/fleece/integration_test.dart b/packages/cbl_e2e_tests/lib/src/fleece/integration_test.dart index 110a7f49..0f31ae4c 100644 --- a/packages/cbl_e2e_tests/lib/src/fleece/integration_test.dart +++ b/packages/cbl_e2e_tests/lib/src/fleece/integration_test.dart @@ -11,8 +11,8 @@ import '../test_binding.dart'; import '../utils/fleece_coding.dart'; import '../utils/matchers.dart'; -late final _arrayBinds = CBLBindings.instance.fleece.array; -late final _dictBinds = CBLBindings.instance.fleece.dict; +final _arrayBinds = CBLBindings.instance.fleece.array; +final _dictBinds = CBLBindings.instance.fleece.dict; void main() { setupTestBinding(); diff --git a/packages/cbl_e2e_tests/lib/src/query/query_builder_test.dart b/packages/cbl_e2e_tests/lib/src/query/query_builder_test.dart index 2c8f484b..6554a05e 100644 --- a/packages/cbl_e2e_tests/lib/src/query/query_builder_test.dart +++ b/packages/cbl_e2e_tests/lib/src/query/query_builder_test.dart @@ -54,8 +54,8 @@ void main() { } void exploreBuilderQuery( - final Query query, - final Map selectQuery, + Query query, + Map selectQuery, ) { if (query is FromRouter) { final fromRouter = query as FromRouter; diff --git a/packages/cbl_e2e_tests/lib/src/test_binding.dart b/packages/cbl_e2e_tests/lib/src/test_binding.dart index 2d385154..1124307b 100644 --- a/packages/cbl_e2e_tests/lib/src/test_binding.dart +++ b/packages/cbl_e2e_tests/lib/src/test_binding.dart @@ -161,9 +161,9 @@ abstract class CblE2eTestBinding { } /// Alias of [CblE2eTestBinding.tmpDir]. -late final tmpDir = CblE2eTestBinding.instance.tmpDir; +final tmpDir = CblE2eTestBinding.instance.tmpDir; -late final largeJsonFixture = CblE2eTestBinding.instance.largeJsonFixture; +final largeJsonFixture = CblE2eTestBinding.instance.largeJsonFixture; String? get testId => Zone.current[#testId] as String?; diff --git a/packages/cbl_e2e_tests/lib/src/utils/database_utils.dart b/packages/cbl_e2e_tests/lib/src/utils/database_utils.dart index 489b11bb..0f288794 100644 --- a/packages/cbl_e2e_tests/lib/src/utils/database_utils.dart +++ b/packages/cbl_e2e_tests/lib/src/utils/database_utils.dart @@ -119,7 +119,7 @@ Future openAsyncTestDatabase({ await File(config.directory).parent.create(recursive: true); final AsyncDatabase db; - if (usePublicApi == true) { + if (usePublicApi ?? false) { db = await (typedDataAdapter != null ? AsyncDatabase.openInternal(name, config, typedDataAdapter) : AsyncDatabase.open(name, config)); diff --git a/packages/cbl_e2e_tests/lib/src/utils/matchers.dart b/packages/cbl_e2e_tests/lib/src/utils/matchers.dart index fcfa1458..08b76ea4 100644 --- a/packages/cbl_e2e_tests/lib/src/utils/matchers.dart +++ b/packages/cbl_e2e_tests/lib/src/utils/matchers.dart @@ -21,7 +21,7 @@ class _IsDirectory extends Matcher { description.add('is directory'); @override - bool matches(final Object? item, Map matchState) { + bool matches(Object? item, Map matchState) { final String path; if (item is FileSystemEntity) { path = item.path; diff --git a/packages/cbl_e2e_tests/lib/src/utils/time_bomb.dart b/packages/cbl_e2e_tests/lib/src/utils/time_bomb.dart index 962baaa9..36be17d6 100644 --- a/packages/cbl_e2e_tests/lib/src/utils/time_bomb.dart +++ b/packages/cbl_e2e_tests/lib/src/utils/time_bomb.dart @@ -88,5 +88,5 @@ final _stdLib = Platform.isWindows ? DynamicLibrary.open('ucrtbase.dll') : DynamicLibrary.process(); -late final _abort = +final _abort = _stdLib.lookupFunction('abort'); diff --git a/packages/cbl_e2e_tests/pubspec.yaml b/packages/cbl_e2e_tests/pubspec.yaml index 90e55a18..7400cce3 100644 --- a/packages/cbl_e2e_tests/pubspec.yaml +++ b/packages/cbl_e2e_tests/pubspec.yaml @@ -11,6 +11,9 @@ dependencies: collection: ^1.16.0 crypto: ^3.0.1 http: ^0.13.4 + meta: ^1.7.0 + path: ^1.8.1 rxdart: ^0.27.3 + stream_channel: ^2.1.0 test: ^1.21.1 web_socket_channel: ^2.2.0 diff --git a/packages/cbl_e2e_tests_flutter/pubspec.yaml b/packages/cbl_e2e_tests_flutter/pubspec.yaml index 75fe8797..17db56cd 100644 --- a/packages/cbl_e2e_tests_flutter/pubspec.yaml +++ b/packages/cbl_e2e_tests_flutter/pubspec.yaml @@ -24,8 +24,11 @@ dependencies: http: ^0.13.4 integration_test: sdk: flutter + meta: ^1.7.0 + path: ^1.8.1 path_provider: ^2.0.10 rxdart: ^0.27.3 + stream_channel: ^2.1.0 test: 1.21.1 web_socket_channel: ^2.2.0 diff --git a/packages/cbl_e2e_tests_standalone_dart/pubspec.yaml b/packages/cbl_e2e_tests_standalone_dart/pubspec.yaml index ce24aca4..b3c7aaf8 100644 --- a/packages/cbl_e2e_tests_standalone_dart/pubspec.yaml +++ b/packages/cbl_e2e_tests_standalone_dart/pubspec.yaml @@ -11,6 +11,9 @@ dependencies: collection: ^1.16.0 crypto: ^3.0.1 http: ^0.13.4 + meta: ^1.7.0 + path: ^1.8.1 rxdart: ^0.27.3 + stream_channel: ^2.1.0 test: ^1.21.1 web_socket_channel: ^2.2.0 diff --git a/packages/cbl_ffi/analysis_options.yaml b/packages/cbl_ffi/analysis_options.yaml index 748ff689..c28f1f9a 100644 --- a/packages/cbl_ffi/analysis_options.yaml +++ b/packages/cbl_ffi/analysis_options.yaml @@ -1,4 +1,4 @@ -include: ../analysis_options.yaml +include: ../../analysis_options.yaml linter: rules: diff --git a/packages/cbl_ffi/lib/src/base.dart b/packages/cbl_ffi/lib/src/base.dart index 78c0e779..be5a60f1 100644 --- a/packages/cbl_ffi/lib/src/base.dart +++ b/packages/cbl_ffi/lib/src/base.dart @@ -7,7 +7,7 @@ import 'bindings.dart'; import 'fleece.dart'; import 'global.dart'; -late final _baseBinds = CBLBindings.instance.base; +final _baseBinds = CBLBindings.instance.base; // === Option ================================================================== @@ -374,10 +374,10 @@ class BaseBindings extends Bindings { assert(!io.Platform.isAndroid || context != null); withZoneArena(() { - Pointer<_CBLInitContext> _context = nullptr; + Pointer<_CBLInitContext> contextStruct = nullptr; if (context != null) { - _context = zoneArena<_CBLInitContext>() + contextStruct = zoneArena<_CBLInitContext>() ..ref.filesDir = context.filesDir.toNativeUtf8(allocator: zoneArena) ..ref.tempDir = context.tempDir.toNativeUtf8(allocator: zoneArena); } @@ -386,7 +386,11 @@ class BaseBindings extends Bindings { // initialization to be completed. final error = zoneArena(); - if (!_initialize(NativeApi.initializeApiDLData, _context.cast(), error)) { + if (!_initialize( + NativeApi.initializeApiDLData, + contextStruct.cast(), + error, + )) { throw CBLErrorException.fromCBLError(error); } }); diff --git a/packages/cbl_ffi/lib/src/global.dart b/packages/cbl_ffi/lib/src/global.dart index 4f4e18d5..99cbd078 100644 --- a/packages/cbl_ffi/lib/src/global.dart +++ b/packages/cbl_ffi/lib/src/global.dart @@ -6,7 +6,7 @@ import 'base.dart'; import 'fleece.dart'; import 'slice.dart'; -late final globalArena = Arena(cachedSliceResultAllocator); +final globalArena = Arena(cachedSliceResultAllocator); T withGlobalArena(T Function() f) { try { @@ -16,21 +16,21 @@ T withGlobalArena(T Function() f) { } } -late final globalFLErrorCode = sliceResultAllocator(); +final globalFLErrorCode = sliceResultAllocator(); -late final nullFLSlice = sliceResultAllocator() +final nullFLSlice = sliceResultAllocator() ..ref.buf = nullptr ..ref.size = 0; -late final globalFLSlice = sliceResultAllocator(); +final globalFLSlice = sliceResultAllocator(); -late final nullFLSliceResult = nullFLSlice.cast(); -late final globalFLSliceResult = sliceResultAllocator(); +final nullFLSliceResult = nullFLSlice.cast(); +final globalFLSliceResult = sliceResultAllocator(); -late final nullFLString = nullFLSlice.cast(); -late final globalFLString = sliceResultAllocator(); +final nullFLString = nullFLSlice.cast(); +final globalFLString = sliceResultAllocator(); -late final globalLoadedDictKey = sliceResultAllocator(); -late final globalLoadedFLValue = sliceResultAllocator(); +final globalLoadedDictKey = sliceResultAllocator(); +final globalLoadedFLValue = sliceResultAllocator(); -late final globalCBLError = sliceResultAllocator(); -late final globalErrorPosition = sliceResultAllocator(); +final globalCBLError = sliceResultAllocator(); +final globalErrorPosition = sliceResultAllocator(); diff --git a/packages/cbl_ffi/lib/src/libraries.dart b/packages/cbl_ffi/lib/src/libraries.dart index 42612765..c1194901 100644 --- a/packages/cbl_ffi/lib/src/libraries.dart +++ b/packages/cbl_ffi/lib/src/libraries.dart @@ -87,16 +87,16 @@ extension on LibraryConfiguration { name = [directory, name].join(Platform.pathSeparator); } - if (isAppleFramework == true) { + if (isAppleFramework ?? false) { name = '$name.framework/Versions/A/$name'; - } else if (appendExtension == true) { + } else if (appendExtension ?? false) { name += _dynamicLibraryExtension(version: version); } return DynamicLibrary.open(name); } - if (process == true) { + if (process ?? false) { return DynamicLibrary.process(); } @@ -140,13 +140,13 @@ String _dynamicLibraryExtension({String? version}) { // === Windows DLL Loading ===================================================== -late final _kernel32 = DynamicLibrary.open('kernel32.dll'); +final _kernel32 = DynamicLibrary.open('kernel32.dll'); -late final _AddDllDirectoryFn = _kernel32.lookupFunction< +final _AddDllDirectoryFn = _kernel32.lookupFunction< Pointer Function(Pointer), Pointer Function(Pointer)>('AddDllDirectory'); -late final _RemoveDllDirectoryFn = _kernel32.lookupFunction< +final _RemoveDllDirectoryFn = _kernel32.lookupFunction< Bool Function(Pointer), bool Function(Pointer)>('RemoveDllDirectory'); diff --git a/packages/cbl_ffi/lib/src/slice.dart b/packages/cbl_ffi/lib/src/slice.dart index 463532a4..709a821d 100644 --- a/packages/cbl_ffi/lib/src/slice.dart +++ b/packages/cbl_ffi/lib/src/slice.dart @@ -11,7 +11,7 @@ import 'fleece.dart'; import 'global.dart'; import 'utils.dart'; -late final _sliceBindings = CBLBindings.instance.fleece.slice; +final _sliceBindings = CBLBindings.instance.fleece.slice; /// A contiguous area of native memory, whose lifetime is tied to some other /// object. @@ -348,7 +348,7 @@ class SingleSliceResultAllocator implements Allocator { } } -late final cachedSliceResultAllocator = SingleSliceResultAllocator( +final cachedSliceResultAllocator = SingleSliceResultAllocator( sliceResult: SliceResult(1024), delegate: malloc, ); diff --git a/packages/cbl_flutter/example/lib/main.dart b/packages/cbl_flutter/example/lib/main.dart index 0185247f..e1cd95e1 100644 --- a/packages/cbl_flutter/example/lib/main.dart +++ b/packages/cbl_flutter/example/lib/main.dart @@ -1,4 +1,4 @@ -// ignore_for_file: avoid_print, lines_longer_than_80_chars +// ignore_for_file: avoid_print, lines_longer_than_80_chars, diagnostic_describe_all_properties /// This simple example app allows users to view and add to a list of log /// messages. @@ -88,7 +88,7 @@ class _LogMessagesPageState extends State { ), ), const Divider(height: 0), - LogMessageForm(onSubmit: logMessageRepository.createLogMessage) + _LogMessageForm(onSubmit: logMessageRepository.createLogMessage) ]), ), ); @@ -116,8 +116,8 @@ class LogMessageTile extends StatelessWidget { ); } -class LogMessageForm extends StatefulWidget { - const LogMessageForm({super.key, required this.onSubmit}); +class _LogMessageForm extends StatefulWidget { + const _LogMessageForm({required this.onSubmit}); final ValueChanged onSubmit; @@ -125,7 +125,7 @@ class LogMessageForm extends StatefulWidget { _LogMessageFormState createState() => _LogMessageFormState(); } -class _LogMessageFormState extends State { +class _LogMessageFormState extends State<_LogMessageForm> { late final TextEditingController _messageController; late final FocusNode _messageFocusNode; diff --git a/packages/cbl_sentry/lib/src/sentry_tracing_delegate.dart b/packages/cbl_sentry/lib/src/sentry_tracing_delegate.dart index a4c8501c..2775ee7c 100644 --- a/packages/cbl_sentry/lib/src/sentry_tracing_delegate.dart +++ b/packages/cbl_sentry/lib/src/sentry_tracing_delegate.dart @@ -72,8 +72,8 @@ class SentryTracingDelegate extends TracingDelegate { // Transactions are always started from the user delegate. In the // worker delegate we only sample a transaction if the user delegate // decided to sample it. - ..tracesSampler = - (trace) => trace.transactionContext.parentSampled == true ? 1 : 0; + ..tracesSampler = (trace) => + trace.transactionContext.parentSampled ?? false ? 1 : 0; }); } else { onInitialize?.call();