style: stricter linting

This commit is contained in:
Aleksey Kulikov 2022-02-23 11:05:14 +03:00
parent d0f7746a01
commit 2eb50dec69
12 changed files with 47 additions and 27 deletions

View file

@ -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

View file

@ -249,7 +249,7 @@ Pointer<git_reference> 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<git_reference> createSymbolic({
if (error < 0) {
calloc.free(out);
throw (LibGit2Error(libgit2.git_error_last()));
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}

View file

@ -211,12 +211,12 @@ class _ConfigIterator implements Iterator<ConfigEntry> {
/// Pointer to memory address for allocated config iterator.
final Pointer<git_config_iterator> _iteratorPointer;
ConfigEntry? _currentEntry;
late ConfigEntry _currentEntry;
int error = 0;
final entry = calloc<Pointer<git_config_entry>>();
@override
ConfigEntry get current => _currentEntry!;
ConfigEntry get current => _currentEntry;
@override
bool moveNext() {

View file

@ -394,12 +394,12 @@ class _IndexIterator implements Iterator<IndexEntry> {
}
final Pointer<git_index> _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() {

View file

@ -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.

View file

@ -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(
/// 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, '

View file

@ -129,12 +129,12 @@ class _RefLogIterator implements Iterator<RefLogEntry> {
/// Pointer to memory address for allocated reflog object.
final Pointer<git_reflog> _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() {

View file

@ -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.

View file

@ -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.');
}

View file

@ -32,7 +32,7 @@ void main() {
});
test('throws when trying to get odb and error occurs', () {
expect(() => Repository((nullptr)).odb, throwsA(isA<LibGit2Error>()));
expect(() => Repository(nullptr).odb, throwsA(isA<LibGit2Error>()));
});
test('creates new odb with no backends', () {

View file

@ -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();

View file

@ -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();