From 2eb50dec69e20e9768854439a500ef3392e26358 Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Wed, 23 Feb 2022 11:05:14 +0300 Subject: [PATCH] style: stricter linting --- analysis_options.yaml | 17 +++++++++++++++++ lib/src/bindings/reference.dart | 4 ++-- lib/src/config.dart | 4 ++-- lib/src/index.dart | 4 ++-- lib/src/oid.dart | 2 ++ lib/src/reference.dart | 19 +++++++++---------- lib/src/reflog.dart | 4 ++-- lib/src/signature.dart | 2 ++ lib/src/util.dart | 2 +- test/odb_test.dart | 2 +- test/reference_test.dart | 10 +++++----- test/revparse_test.dart | 4 ++-- 12 files changed, 47 insertions(+), 27 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 6a83aec..ee80c33 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -14,9 +14,12 @@ linter: rules: - always_use_package_imports - avoid_bool_literals_in_conditional_expressions + - avoid_double_and_int_checks - avoid_dynamic_calls + - avoid_equals_and_hash_code_on_mutable_classes - avoid_escaping_inner_quotes - avoid_field_initializers_in_const_classes + - avoid_js_rounded_ints - avoid_positional_boolean_parameters - avoid_print - avoid_redundant_argument_values @@ -28,27 +31,41 @@ linter: - avoid_unused_constructor_parameters - avoid_void_async - cast_nullable_to_non_nullable + - deprecated_consistency - directives_ordering - eol_at_end_of_file - join_return_with_assignment - library_private_types_in_public_api - lines_longer_than_80_chars + - literal_only_boolean_expressions - missing_whitespace_between_adjacent_strings + - no_default_cases - noop_primitive_operations + - null_check_on_nullable_type_parameter - omit_local_variable_types + - one_member_abstracts - parameter_assignments + - prefer_asserts_in_initializer_lists + - prefer_asserts_with_message - prefer_const_constructors - prefer_constructors_over_static_methods - prefer_final_in_for_each - prefer_final_locals - prefer_if_elements_to_conditional_expressions + - prefer_int_literals - prefer_null_aware_method_calls - require_trailing_commas - sort_constructors_first - sort_pub_dependencies - sort_unnamed_constructors_first + - tighten_type_of_initializing_formals - type_annotate_public_apis - unawaited_futures + - unnecessary_await_in_return + - unnecessary_parenthesis + - unnecessary_raw_strings + - use_is_even_rather_than_modulo + - use_late_for_private_fields_and_variables - use_named_constants - use_raw_strings - use_setters_to_change_properties diff --git a/lib/src/bindings/reference.dart b/lib/src/bindings/reference.dart index 93b00e9..c911e45 100644 --- a/lib/src/bindings/reference.dart +++ b/lib/src/bindings/reference.dart @@ -249,7 +249,7 @@ Pointer createDirect({ if (error < 0) { calloc.free(out); - throw (LibGit2Error(libgit2.git_error_last())); + throw LibGit2Error(libgit2.git_error_last()); } else { return out.value; } @@ -309,7 +309,7 @@ Pointer createSymbolic({ if (error < 0) { calloc.free(out); - throw (LibGit2Error(libgit2.git_error_last())); + throw LibGit2Error(libgit2.git_error_last()); } else { return out.value; } diff --git a/lib/src/config.dart b/lib/src/config.dart index 429160d..1b84f4c 100644 --- a/lib/src/config.dart +++ b/lib/src/config.dart @@ -211,12 +211,12 @@ class _ConfigIterator implements Iterator { /// Pointer to memory address for allocated config iterator. final Pointer _iteratorPointer; - ConfigEntry? _currentEntry; + late ConfigEntry _currentEntry; int error = 0; final entry = calloc>(); @override - ConfigEntry get current => _currentEntry!; + ConfigEntry get current => _currentEntry; @override bool moveNext() { diff --git a/lib/src/index.dart b/lib/src/index.dart index 46cb50a..dd94306 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -394,12 +394,12 @@ class _IndexIterator implements Iterator { } final Pointer _indexPointer; - IndexEntry? _currentEntry; + late IndexEntry _currentEntry; int _index = 0; late final int count; @override - IndexEntry get current => _currentEntry!; + IndexEntry get current => _currentEntry; @override bool moveNext() { diff --git a/lib/src/oid.dart b/lib/src/oid.dart index 3f51eef..eeb4a62 100644 --- a/lib/src/oid.dart +++ b/lib/src/oid.dart @@ -5,7 +5,9 @@ import 'package:libgit2dart/src/bindings/libgit2_bindings.dart'; import 'package:libgit2dart/src/bindings/odb.dart' as odb_bindings; import 'package:libgit2dart/src/bindings/oid.dart' as bindings; import 'package:libgit2dart/src/util.dart'; +import 'package:meta/meta.dart'; +@immutable class Oid { /// Initializes a new instance of [Oid] class from provided /// pointer to Oid object in memory. diff --git a/lib/src/reference.dart b/lib/src/reference.dart index 2d969fd..c67b721 100644 --- a/lib/src/reference.dart +++ b/lib/src/reference.dart @@ -280,21 +280,20 @@ class Reference { /// Repository where a reference resides. Repository get owner => Repository(bindings.owner(_refPointer)); - @override - bool operator ==(Object other) { - return (other is Reference) && - bindings.compare( - ref1Pointer: _refPointer, - ref2Pointer: other._refPointer, - ); + /// Compares two references. + bool equals(Reference other) { + return bindings.compare( + ref1Pointer: _refPointer, + ref2Pointer: other._refPointer, + ); } + /// Compares two references. + bool notEquals(Reference other) => !equals(other); + /// Releases memory allocated for reference object. void free() => bindings.free(_refPointer); - @override // coverage:ignore-line - int get hashCode => _refPointer.address.hashCode; // coverage:ignore-line - @override String toString() { return 'Reference{name: $name, target: $target, type: $type, ' diff --git a/lib/src/reflog.dart b/lib/src/reflog.dart index 81ce9b0..89a50a2 100644 --- a/lib/src/reflog.dart +++ b/lib/src/reflog.dart @@ -129,12 +129,12 @@ class _RefLogIterator implements Iterator { /// Pointer to memory address for allocated reflog object. final Pointer _reflogPointer; - RefLogEntry? _currentEntry; + late RefLogEntry _currentEntry; int _index = 0; late final int _count; @override - RefLogEntry get current => _currentEntry!; + RefLogEntry get current => _currentEntry; @override bool moveNext() { diff --git a/lib/src/signature.dart b/lib/src/signature.dart index ae6f278..4c821a7 100644 --- a/lib/src/signature.dart +++ b/lib/src/signature.dart @@ -4,7 +4,9 @@ import 'package:libgit2dart/libgit2dart.dart'; import 'package:libgit2dart/src/bindings/libgit2_bindings.dart'; import 'package:libgit2dart/src/bindings/signature.dart' as bindings; import 'package:libgit2dart/src/util.dart'; +import 'package:meta/meta.dart'; +@immutable class Signature { /// Initializes a new instance of [Signature] class from provided pointer to /// signature object in memory. diff --git a/lib/src/util.dart b/lib/src/util.dart index adb5e2b..e145c60 100644 --- a/lib/src/util.dart +++ b/lib/src/util.dart @@ -18,7 +18,7 @@ String getLibName() { ext = 'dll'; } else if (Platform.isMacOS) { ext = 'dylib'; - } else if (!(Platform.isLinux)) { + } else if (!Platform.isLinux) { throw Exception('Unsupported platform.'); } diff --git a/test/odb_test.dart b/test/odb_test.dart index c8f479f..51f989a 100644 --- a/test/odb_test.dart +++ b/test/odb_test.dart @@ -32,7 +32,7 @@ void main() { }); test('throws when trying to get odb and error occurs', () { - expect(() => Repository((nullptr)).odb, throwsA(isA())); + expect(() => Repository(nullptr).odb, throwsA(isA())); }); test('creates new odb with no backends', () { diff --git a/test/reference_test.dart b/test/reference_test.dart index dc3231f..3c1f436 100644 --- a/test/reference_test.dart +++ b/test/reference_test.dart @@ -166,7 +166,7 @@ void main() { final duplicate = ref.duplicate(); expect(repo.references.length, 6); - expect(duplicate, equals(ref)); + expect(duplicate.equals(ref), true); duplicate.free(); ref.free(); @@ -519,10 +519,10 @@ void main() { final ref2 = Reference.lookup(repo: repo, name: 'refs/heads/master'); final ref3 = Reference.lookup(repo: repo, name: 'refs/heads/feature'); - expect(ref1 == ref2, true); - expect(ref1 != ref2, false); - expect(ref1 == ref3, false); - expect(ref1 != ref3, true); + expect(ref1.equals(ref2), true); + expect(ref1.notEquals(ref2), false); + expect(ref1.equals(ref3), false); + expect(ref1.notEquals(ref3), true); ref1.free(); ref2.free(); diff --git a/test/revparse_test.dart b/test/revparse_test.dart index 80b07c4..8892d0d 100644 --- a/test/revparse_test.dart +++ b/test/revparse_test.dart @@ -65,7 +65,7 @@ void main() { var headParse = RevParse.ext(repo: repo, spec: 'master'); expect(headParse.object.oid.sha, headSHA); - expect(headParse.reference, masterRef); + expect(headParse.reference?.equals(masterRef), true); expect(headParse.toString(), contains('RevParse{')); masterRef.free(); @@ -82,7 +82,7 @@ void main() { headParse.object.oid.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4', ); - expect(headParse.reference, featureRef); + expect(headParse.reference?.equals(featureRef), true); featureRef.free(); headParse.object.free();