Enable and fix some lints
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 8083db4..d24df6d 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -5,37 +5,37 @@
linter:
rules:
- - avoid_function_literals_in_foreach_calls
+ - avoid_catching_errors
+ - avoid_dynamic_calls
+ - avoid_private_typedef_functions
- avoid_returning_null
- avoid_unused_constructor_parameters
- - await_only_futures
- - camel_case_types
- cancel_subscriptions
+ - cascade_invocations
- comment_references
- #- constant_identifier_names
- - control_flow_in_finally
- directives_ordering
- - empty_statements
- - hash_and_equals
- - implementation_imports
- invariant_booleans
- - iterable_contains_unrelated_type
- - list_remove_unrelated_type
+ - join_return_with_assignment
+ - lines_longer_than_80_chars
+ - missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- - non_constant_identifier_names
+ - no_runtimeType_toString
- only_throw_errors
- - overridden_fields
- package_api_docs
- - package_names
- - package_prefixed_library_names
+ - prefer_asserts_in_initializer_lists
- prefer_const_constructors
- - prefer_initializing_formals
+ - prefer_const_declarations
+ - prefer_expression_function_bodies
- prefer_interpolation_to_compose_strings
- - prefer_typing_uninitialized_variables
+ - prefer_relative_imports
+ - sort_pub_dependencies
- test_types_in_equals
- throw_in_finally
- - unnecessary_brace_in_string_interps
- - unnecessary_getters_setters
+ - type_annotate_public_apis
- unnecessary_lambdas
- unnecessary_null_aware_assignments
+ - unnecessary_parenthesis
+ - unnecessary_raw_strings
- unnecessary_statements
+ - use_is_even_rather_than_modulo
+ - use_string_buffers
diff --git a/lib/src/int32.dart b/lib/src/int32.dart
index 48263b7..760bc22 100644
--- a/lib/src/int32.dart
+++ b/lib/src/int32.dart
@@ -63,7 +63,7 @@
if (digit < 0 || digit >= radix) {
throw FormatException('Non-radix code unit: $c');
}
- x = ((x * radix) + digit) as Int32;
+ x = (x * radix) + digit as Int32;
}
return x;
}
@@ -93,12 +93,12 @@
// The code below removes unnecessary &'s and uses a
// trick to remove one instruction in the first line.
- i -= ((i >> 1) & 0x55555555);
+ i -= (i >> 1) & 0x55555555;
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
- i = ((i + (i >> 4)) & 0x0F0F0F0F);
- i += (i >> 8);
- i += (i >> 16);
- return (i & 0x0000003F);
+ i = (i + (i >> 4)) & 0x0F0F0F0F;
+ i += i >> 8;
+ i += i >> 16;
+ return i & 0x0000003F;
}
// Assumes i is <= 32-bit
@@ -198,7 +198,7 @@
var t = toInt64();
return (t - (t ~/ other) * other).toInt32();
}
- return (this - (this ~/ other) * other) as Int32;
+ return this - (this ~/ other) * other as Int32;
}
@override
diff --git a/lib/src/int64.dart b/lib/src/int64.dart
index e9207d5..307a08f 100644
--- a/lib/src/int64.dart
+++ b/lib/src/int64.dart
@@ -59,9 +59,8 @@
/// Parses a [String] in a given [radix] between 2 and 36 and returns an
/// [Int64].
- static Int64 parseRadix(String s, int radix) {
- return _parseRadix(s, Int32._validateRadix(radix));
- }
+ static Int64 parseRadix(String s, int radix) =>
+ _parseRadix(s, Int32._validateRadix(radix));
static Int64 _parseRadix(String s, int radix) {
int i = 0;
@@ -336,9 +335,7 @@
}
@override
- Int64 operator ~() {
- return Int64._masked(~_l, ~_m, ~_h);
- }
+ Int64 operator ~() => Int64._masked(~_l, ~_m, ~_h);
@override
Int64 operator <<(int n) {
@@ -384,7 +381,7 @@
if (negative && _MASK > _MASK2) {
// Add extra one bits on the left so the sign gets shifted into the wider
// lower words.
- a2 += (_MASK - _MASK2);
+ a2 += _MASK - _MASK2;
}
if (n < _BITS) {
@@ -546,9 +543,7 @@
}
@override
- Int64 abs() {
- return isNegative ? -this : this;
- }
+ Int64 abs() => isNegative ? -this : this;
@override
Int64 clamp(Object lowerLimit, Object upperLimit) {
@@ -667,9 +662,7 @@
/// Returns an [Int32] containing the low 32 bits of this [Int64].
@override
- Int32 toInt32() {
- return Int32(((_m & 0x3ff) << _BITS) | _l);
- }
+ Int32 toInt32() => Int32(((_m & 0x3ff) << _BITS) | _l);
/// Returns `this`.
@override
@@ -695,19 +688,15 @@
/// Returns the digits of `this` when interpreted as an unsigned 64-bit value.
@pragma('dart2js:noInline')
- String toStringUnsigned() {
- return _toRadixStringUnsigned(10, _l, _m, _h, '');
- }
+ String toStringUnsigned() => _toRadixStringUnsigned(10, _l, _m, _h, '');
@pragma('dart2js:noInline')
- String toRadixStringUnsigned(int radix) {
- return _toRadixStringUnsigned(Int32._validateRadix(radix), _l, _m, _h, '');
- }
+ String toRadixStringUnsigned(int radix) =>
+ _toRadixStringUnsigned(Int32._validateRadix(radix), _l, _m, _h, '');
@override
- String toRadixString(int radix) {
- return _toRadixString(Int32._validateRadix(radix));
- }
+ String toRadixString(int radix) =>
+ _toRadixString(Int32._validateRadix(radix));
String _toRadixString(int radix) {
int d0 = _l;
@@ -870,9 +859,7 @@
36 * 36 * 36
];
- String toDebugString() {
- return 'Int64[_l=$_l, _m=$_m, _h=$_h]';
- }
+ String toDebugString() => 'Int64[_l=$_l, _m=$_m, _h=$_h]';
static Int64 _masked(int a0, int a1, int a2) =>
Int64._bits(_MASK & a0, _MASK & a1, _MASK2 & a2);
@@ -884,9 +871,7 @@
return _masked(diff0, diff1, diff2);
}
- static Int64 _negate(int b0, int b1, int b2) {
- return _sub(0, 0, 0, b0, b1, b2);
- }
+ static Int64 _negate(int b0, int b1, int b2) => _sub(0, 0, 0, b0, b1, b2);
String _hexDigit(int digit) => '0123456789ABCDEF'[digit];
diff --git a/lib/src/intx.dart b/lib/src/intx.dart
index 4c0dd61..bedb3e1 100644
--- a/lib/src/intx.dart
+++ b/lib/src/intx.dart
@@ -120,31 +120,33 @@
/// for non-negative (unsigned) values. Negative values are complemented to
/// return the bit position of the first bit that differs from the sign bit.
///
- /// To find the the number of bits needed to store the value as a signed value,
- /// add one, i.e. use `x.bitLength + 1`.
+ /// To find the the number of bits needed to store the value as a signed
+ /// value, add one, i.e. use `x.bitLength + 1`.
int get bitLength;
/// Returns the number of high-order zeros in this integer's bit
/// representation.
int numberOfLeadingZeros();
- /// Returns the number of low-order zeros in this integer's bit representation.
+ /// Returns the number of low-order zeros in this integer's bit
+ /// representation.
int numberOfTrailingZeros();
/// Returns the least significant [width] bits of this integer, extending the
- /// highest retained bit to the sign. This is the same as truncating the value
- /// to fit in [width] bits using an signed 2-s complement representation. The
- /// returned value has the same bit value in all positions higher than [width].
+ /// highest retained bit to the sign. This is the same as truncating the
+ /// value to fit in [width] bits using an signed 2-s complement
+ /// representation. The returned value has the same bit value in all positions
+ /// higher than [width].
///
/// If the input value fits in [width] bits without truncation, the result is
- /// the same as the input. The minimum width needed to avoid truncation of `x`
- /// is `x.bitLength + 1`, i.e.
+ /// the same as the input. The minimum width needed to avoid truncation of
+ /// `x` is `x.bitLength + 1`, i.e.
///
/// x == x.toSigned(x.bitLength + 1);
IntX toSigned(int width);
/// Returns the least significant [width] bits of this integer as a
- /// non-negative number (i.e. unsigned representation). The returned value has
+ /// non-negative number (i.e. unsigned representation). The returned value has
/// zeros in all bit positions higher than [width].
///
/// If the input fits in [width] bits without truncation, the result is the
@@ -189,7 +191,8 @@
/// notation; example: `'0xd'`.
String toHexString();
- /// Returns a string representing the value of this integer in the given radix.
+ /// Returns a string representing the value of this integer in the given
+ /// radix.
///
/// [radix] must be an integer in the range 2 .. 16, inclusive.
String toRadixString(int radix);
diff --git a/test/int32_test.dart b/test/int32_test.dart
index 2363313..5e72c7b 100644
--- a/test/int32_test.dart
+++ b/test/int32_test.dart
@@ -85,10 +85,10 @@
expect(n3 * n3, Int32(1522756));
expect(n3 * n2, Int32(-12186984));
expect(Int32(0x12345678) * Int32(0x22222222), Int32(-899716112));
- expect((Int32(123456789) * Int32(987654321)), Int32(-67153019));
+ expect(Int32(123456789) * Int32(987654321), Int32(-67153019));
expect(Int32(0x12345678) * Int64(0x22222222),
Int64.fromInts(0x026D60DC, 0xCA5F6BF0));
- expect((Int32(123456789) * 987654321), Int32(-67153019));
+ expect(Int32(123456789) * 987654321, Int32(-67153019));
});
test('~/', () {
@@ -266,8 +266,8 @@
});
test('~', () {
- expect(~(Int32(0x12345678)), Int32(~0x12345678));
- expect(-(Int32(0x12345678)), Int64(-0x12345678));
+ expect(~Int32(0x12345678), Int32(~0x12345678));
+ expect(-Int32(0x12345678), Int64(-0x12345678));
});
});
@@ -294,7 +294,7 @@
expect(Int32(0x12345678).shiftRightUnsigned(33), Int32.ZERO);
expect(Int32(-42).shiftRightUnsigned(32), Int32.ZERO);
expect(Int32(-42).shiftRightUnsigned(33), Int32.ZERO);
- expect(() => (Int32(17).shiftRightUnsigned(-1)), throwsArgumentError);
+ expect(() => Int32(17).shiftRightUnsigned(-1), throwsArgumentError);
});
});
diff --git a/test/int64_test.dart b/test/int64_test.dart
index 01c8eca..ac952c1 100644
--- a/test/int64_test.dart
+++ b/test/int64_test.dart
@@ -44,15 +44,17 @@
});
});
- void argumentErrorTest(name, op, [receiver = Int64.ONE]) {
- Matcher throwsArgumentErrorMentioning(String substring) =>
- throwsA((e) => e is ArgumentError && '$e'.contains(substring));
-
+ void argumentErrorTest(
+ Object Function(Int64, Object) op, [
+ Int64 receiver = Int64.ONE,
+ ]) {
expect(
- () => op(receiver, null),
- throwsA(isA<TypeError>().having(
- (e) => e.toString(), 'should mention Null', contains('Null'))));
- expect(() => op(receiver, 'foo'), throwsArgumentErrorMentioning(r'"foo"'));
+ () => op(receiver, 'foo'),
+ throwsA(
+ isA<ArgumentError>()
+ .having((p0) => p0.toString(), 'toString', contains('"foo"')),
+ ),
+ );
}
group('is-tests', () {
@@ -116,7 +118,7 @@
expect(n3 + n4, Int64(-11110));
expect(n5 + n6, Int64.fromInts(0x89ab89ab, 0xcdeff011));
expect(Int64.MAX_VALUE + 1, Int64.MIN_VALUE);
- argumentErrorTest('+', (a, b) => a + b);
+ argumentErrorTest((a, b) => a + b);
});
test('-', () {
@@ -125,7 +127,7 @@
expect(n3 - n4, Int64(8642));
expect(n5 - n6, Int64.fromInts(0x9abd2345, 0x89ab6789));
expect(Int64.MIN_VALUE - 1, Int64.MAX_VALUE);
- argumentErrorTest('-', (a, b) => a - b);
+ argumentErrorTest((a, b) => a - b);
});
test('unary -', () {
@@ -154,19 +156,19 @@
Int64.fromInts(0x297e3f7c, 0x1df4d840));
// RHS Int32
- expect((Int64(123456789) * Int32(987654321)),
+ expect(Int64(123456789) * Int32(987654321),
Int64.fromInts(0x1b13114, 0xfbff5385));
- expect((Int64(123456789) * Int32(987654321)),
+ expect(Int64(123456789) * Int32(987654321),
Int64.fromInts(0x1b13114, 0xfbff5385));
// Wraparound
- expect((Int64(123456789) * Int64(987654321)),
+ expect(Int64(123456789) * Int64(987654321),
Int64.fromInts(0x1b13114, 0xfbff5385));
expect(Int64.MIN_VALUE * Int64(2), Int64.ZERO);
expect(Int64.MIN_VALUE * Int64(1), Int64.MIN_VALUE);
expect(Int64.MIN_VALUE * Int64(-1), Int64.MIN_VALUE);
- argumentErrorTest('*', (a, b) => a * b);
+ argumentErrorTest((a, b) => a * b);
});
test('~/', () {
@@ -243,7 +245,7 @@
expect(Int64.MIN_VALUE ~/ Int64(-1), Int64.MIN_VALUE);
expect(() => Int64(17) ~/ Int64.ZERO,
throwsA(isIntegerDivisionByZeroException));
- argumentErrorTest('~/', (a, b) => a ~/ b);
+ argumentErrorTest((a, b) => a ~/ b);
});
test('%', () {
@@ -283,7 +285,7 @@
Int64(-0x12345678.remainder(0x22)));
expect(Int32(0x12345678).remainder(Int64(0x22)),
Int64(0x12345678.remainder(0x22)));
- argumentErrorTest('%', (a, b) => a % b);
+ argumentErrorTest((a, b) => a % b);
});
test('clamp', () {
@@ -360,7 +362,7 @@
expect(largePosPlusOne < largePos, false);
expect(Int64.MIN_VALUE < Int64.MAX_VALUE, true);
expect(Int64.MAX_VALUE < Int64.MIN_VALUE, false);
- argumentErrorTest('<', (a, b) => a < b);
+ argumentErrorTest((a, b) => a < b);
});
test('<=', () {
@@ -379,7 +381,7 @@
expect(largePosPlusOne <= largePos, false);
expect(Int64.MIN_VALUE <= Int64.MAX_VALUE, true);
expect(Int64.MAX_VALUE <= Int64.MIN_VALUE, false);
- argumentErrorTest('<=', (a, b) => a <= b);
+ argumentErrorTest((a, b) => a <= b);
});
test('==', () {
@@ -426,7 +428,7 @@
expect(largePosPlusOne >= largePos, true);
expect(Int64.MIN_VALUE >= Int64.MAX_VALUE, false);
expect(Int64.MAX_VALUE >= Int64.MIN_VALUE, true);
- argumentErrorTest('>=', (a, b) => a >= b);
+ argumentErrorTest((a, b) => a >= b);
});
test('>', () {
@@ -447,7 +449,7 @@
expect(Int64.ZERO > Int64.MIN_VALUE, true);
expect(Int64.MIN_VALUE > Int64.MAX_VALUE, false);
expect(Int64.MAX_VALUE > Int64.MIN_VALUE, true);
- argumentErrorTest('>', (a, b) => a > b);
+ argumentErrorTest((a, b) => a > b);
});
});
@@ -462,21 +464,21 @@
expect(n1 & n2, Int64(1168));
expect(n3 & n2, Int64(8708));
expect(n4 & n5, Int64(0x1034) << 32);
- argumentErrorTest('&', (a, b) => a & b);
+ argumentErrorTest((a, b) => a & b);
});
test('|', () {
expect(n1 | n2, Int64(9942));
expect(n3 | n2, Int64(-66));
expect(n4 | n5, Int64(0x9a76) << 32);
- argumentErrorTest('|', (a, b) => a | b);
+ argumentErrorTest((a, b) => a | b);
});
test('^', () {
expect(n1 ^ n2, Int64(8774));
expect(n3 ^ n2, Int64(-8774));
expect(n4 ^ n5, Int64(0x8a42) << 32);
- argumentErrorTest('^', (a, b) => a ^ b);
+ argumentErrorTest((a, b) => a ^ b);
});
test('~', () {