Skip to content

Commit

Permalink
refactor: enable more lint rules (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold committed May 20, 2022
1 parent d3f2151 commit 69a6423
Show file tree
Hide file tree
Showing 42 changed files with 154 additions and 121 deletions.
56 changes: 30 additions & 26 deletions packages/analysis_options.yaml → 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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -82,20 +80,20 @@ 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
- missing_whitespace_between_adjacent_strings
- 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -136,21 +137,20 @@ 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
- prefer_spread_collections
- 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
15 changes: 15 additions & 0 deletions 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
8 changes: 4 additions & 4 deletions packages/cbl/lib/src/database/ffi_blob_store.dart
Expand Up @@ -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;

Expand Down Expand Up @@ -111,7 +111,7 @@ class FfiBlobStore implements BlobStore, SyncBlobStore {
}
}

late final _writeStreamBindings = cblBindings.blobs.writeStream;
final _writeStreamBindings = cblBindings.blobs.writeStream;

Future<CBLObject<CBLBlob>> _createBlobFromStream(
FfiDatabase database,
Expand Down Expand Up @@ -144,7 +144,7 @@ class _BlobReadStream extends Stream<Data> {
/// 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<CBLBlob> blob;
Expand Down
2 changes: 1 addition & 1 deletion packages/cbl/lib/src/database/ffi_database.dart
Expand Up @@ -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<FfiDocumentDelegate>, ClosableResourceMixin
Expand Down
6 changes: 3 additions & 3 deletions packages/cbl/lib/src/document/common.dart
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions packages/cbl/lib/src/document/ffi_document.dart
Expand Up @@ -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<CBLDocument> {
Expand Down
2 changes: 1 addition & 1 deletion packages/cbl/lib/src/document/fragment.dart
Expand Up @@ -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() {
Expand Down
20 changes: 10 additions & 10 deletions packages/cbl/lib/src/fleece/containers.dart
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -174,7 +174,7 @@ class Value extends FleeceValueObject<FLValue> {
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.
Expand Down Expand Up @@ -379,7 +379,7 @@ class Array extends Value with ListMixin<Value> {
adopt: adopt,
);

static late final _bindings = cblBindings.fleece.array;
static final _bindings = cblBindings.fleece.array;

@override
int get length {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -596,7 +596,7 @@ class Dict extends Value with MapMixin<String, Value> {
adopt: adopt,
);

static late final _bindings = cblBindings.fleece.dict;
static final _bindings = cblBindings.fleece.dict;

/// Returns the number of items in a dictionary.
@override
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions packages/cbl/lib/src/fleece/decoder.dart
Expand Up @@ -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].
///
Expand Down Expand Up @@ -547,12 +547,12 @@ class _ArrayIndexLoader extends _FleeceValueLoader {

class _DictIteratorLoader extends _FleeceValueLoader {
_DictIteratorLoader(
Pointer<FLDict> _dict,
Pointer<FLDict> dict,
this._listener,
this._sharedKeysTable,
this._sharedStringsTable,
) : _it = DictIterator(
_dict,
dict,
sharedKeysTable: _sharedKeysTable,
keyOut: globalLoadedDictKey,
valueOut: globalLoadedFLValue,
Expand Down
4 changes: 2 additions & 2 deletions packages/cbl/lib/src/fleece/dict_key.dart
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/cbl/lib/src/fleece/encoder.dart
Expand Up @@ -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.
///
Expand Down
2 changes: 1 addition & 1 deletion packages/cbl/lib/src/fleece/integration/array.dart
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion packages/cbl/lib/src/fleece/integration/delegate.dart
Expand Up @@ -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;
Expand Down

0 comments on commit 69a6423

Please sign in to comment.