Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Enable and fix a number of lints (#45)
Browse files Browse the repository at this point in the history
Almost entirely `dartfmt --fix -w .`
  • Loading branch information
kevmoo authored Nov 7, 2018
1 parent 7604fc5 commit 8ed49bd
Show file tree
Hide file tree
Showing 9 changed files with 895 additions and 960 deletions.
58 changes: 58 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
include: package:pedantic/analysis_options.yaml
linter:
rules:
#- annotate_overrides
- avoid_function_literals_in_foreach_calls
- avoid_init_to_null
- avoid_null_checks_in_equality_operators
- avoid_relative_lib_imports
- avoid_returning_null
- avoid_unused_constructor_parameters
- await_only_futures
- camel_case_types
- cancel_subscriptions
- comment_references
#- constant_identifier_names
- control_flow_in_finally
- directives_ordering
- empty_catches
- empty_constructor_bodies
- empty_statements
- hash_and_equals
- implementation_imports
- invariant_booleans
- iterable_contains_unrelated_type
- library_names
- library_prefixes
- list_remove_unrelated_type
- no_adjacent_strings_in_list
- non_constant_identifier_names
#- omit_local_variable_types
- only_throw_errors
- overridden_fields
- package_api_docs
- package_names
- package_prefixed_library_names
- prefer_adjacent_string_concatenation
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_const_constructors
- prefer_final_fields
- prefer_initializing_formals
- prefer_interpolation_to_compose_strings
#- prefer_single_quotes
- prefer_typing_uninitialized_variables
- slash_for_doc_comments
- test_types_in_equals
- super_goes_last
- test_types_in_equals
- throw_in_finally
- type_init_formals
- unnecessary_brace_in_string_interps
- unnecessary_const
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_statements
#- unnecessary_this
18 changes: 8 additions & 10 deletions lib/fixnum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/**
* Signed 32- and 64-bit integer support.
*
* The integer implementations in this library are designed to work
* identically whether executed on the Dart VM or compiled to JavaScript.
*
* For information on installing and importing this library, see the
* [fixnum package on pub.dartlang.org]
* (http://pub.dartlang.org/packages/fixnum).
*/
/// Signed 32- and 64-bit integer support.
///
/// The integer implementations in this library are designed to work
/// identically whether executed on the Dart VM or compiled to JavaScript.
///
/// For information on installing and importing this library, see the
/// [fixnum package on pub.dartlang.org]
/// (http://pub.dartlang.org/packages/fixnum).
library fixnum;

part 'src/intx.dart';
Expand Down
134 changes: 56 additions & 78 deletions lib/src/int32.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,25 @@

part of fixnum;

/**
* An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1].
* Arithmetic operations may overflow in order to maintain this range.
*/
/// An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1].
/// Arithmetic operations may overflow in order to maintain this range.
class Int32 implements IntX {
/**
* The maximum positive value attainable by an [Int32], namely
* 2147483647.
*/
static const Int32 MAX_VALUE = const Int32._internal(0x7FFFFFFF);

/**
* The minimum positive value attainable by an [Int32], namely
* -2147483648.
*/
static const Int32 MIN_VALUE = const Int32._internal(-0x80000000);

/**
* An [Int32] constant equal to 0.
*/
static const Int32 ZERO = const Int32._internal(0);

/**
* An [Int32] constant equal to 1.
*/
static const Int32 ONE = const Int32._internal(1);

/**
* An [Int32] constant equal to 2.
*/
static const Int32 TWO = const Int32._internal(2);
/// The maximum positive value attainable by an [Int32], namely
/// 2147483647.
static const Int32 MAX_VALUE = Int32._internal(0x7FFFFFFF);

/// The minimum positive value attainable by an [Int32], namely
/// -2147483648.
static const Int32 MIN_VALUE = Int32._internal(-0x80000000);

/// An [Int32] constant equal to 0.
static const Int32 ZERO = Int32._internal(0);

/// An [Int32] constant equal to 1.
static const Int32 ONE = Int32._internal(1);

/// An [Int32] constant equal to 2.
static const Int32 TWO = Int32._internal(2);

// Hex digit char codes
static const int _CC_0 = 48; // '0'.codeUnitAt(0)
Expand All @@ -58,13 +46,11 @@ class Int32 implements IntX {

static int _validateRadix(int radix) {
if (2 <= radix && radix <= 36) return radix;
throw new RangeError.range(radix, 2, 36, 'radix');
throw RangeError.range(radix, 2, 36, 'radix');
}

/**
* Parses a [String] in a given [radix] between 2 and 16 and returns an
* [Int32].
*/
/// Parses a [String] in a given [radix] between 2 and 16 and returns an
/// [Int32].
// TODO(rice) - Make this faster by converting several digits at once.
static Int32 parseRadix(String s, int radix) {
_validateRadix(radix);
Expand All @@ -73,21 +59,17 @@ class Int32 implements IntX {
int c = s.codeUnitAt(i);
int digit = _decodeDigit(c);
if (digit < 0 || digit >= radix) {
throw new FormatException("Non-radix code unit: $c");
throw FormatException("Non-radix code unit: $c");
}
x = (x * radix) + digit;
}
return x;
}

/**
* Parses a decimal [String] and returns an [Int32].
*/
static Int32 parseInt(String s) => new Int32(int.parse(s));
/// Parses a decimal [String] and returns an [Int32].
static Int32 parseInt(String s) => Int32(int.parse(s));

/**
* Parses a hexadecimal [String] and returns an [Int32].
*/
/// Parses a hexadecimal [String] and returns an [Int32].
static Int32 parseHex(String s) => parseRadix(s, 16);

// Assumes i is <= 32-bit.
Expand Down Expand Up @@ -134,10 +116,8 @@ class Int32 implements IntX {

const Int32._internal(int i) : _i = i;

/**
* Constructs an [Int32] from an [int]. Only the low 32 bits of the input
* are used.
*/
/// Constructs an [Int32] from an [int]. Only the low 32 bits of the input
/// are used.
Int32([int i = 0]) : _i = (i & 0x7fffffff) - (i & 0x80000000);

// Returns the [int] representation of the specified value. Throws
Expand All @@ -148,7 +128,7 @@ class Int32 implements IntX {
} else if (val is int) {
return val;
}
throw new ArgumentError(val);
throw ArgumentError(val);
}

// The +, -, * , &, |, and ^ operaters deal with types as follows:
Expand All @@ -169,17 +149,17 @@ class Int32 implements IntX {
if (other is Int64) {
return this.toInt64() + other;
}
return new Int32(_i + _toInt(other));
return Int32(_i + _toInt(other));
}

IntX operator -(other) {
if (other is Int64) {
return this.toInt64() - other;
}
return new Int32(_i - _toInt(other));
return Int32(_i - _toInt(other));
}

Int32 operator -() => new Int32(-_i);
Int32 operator -() => Int32(-_i);

IntX operator *(other) {
if (other is Int64) {
Expand All @@ -194,14 +174,14 @@ class Int32 implements IntX {
// Result will be Int32
return (this.toInt64() % other).toInt32();
}
return new Int32(_i % _toInt(other));
return Int32(_i % _toInt(other));
}

Int32 operator ~/(other) {
if (other is Int64) {
return (this.toInt64() ~/ other).toInt32();
}
return new Int32(_i ~/ _toInt(other));
return Int32(_i ~/ _toInt(other));
}

Int32 remainder(other) {
Expand All @@ -216,38 +196,38 @@ class Int32 implements IntX {
if (other is Int64) {
return (this.toInt64() & other).toInt32();
}
return new Int32(_i & _toInt(other));
return Int32(_i & _toInt(other));
}

Int32 operator |(other) {
if (other is Int64) {
return (this.toInt64() | other).toInt32();
}
return new Int32(_i | _toInt(other));
return Int32(_i | _toInt(other));
}

Int32 operator ^(other) {
if (other is Int64) {
return (this.toInt64() ^ other).toInt32();
}
return new Int32(_i ^ _toInt(other));
return Int32(_i ^ _toInt(other));
}

Int32 operator ~() => new Int32(~_i);
Int32 operator ~() => Int32(~_i);

Int32 operator <<(int n) {
if (n < 0) {
throw new ArgumentError(n);
throw ArgumentError(n);
}
if (n >= 32) {
return ZERO;
}
return new Int32(_i << n);
return Int32(_i << n);
}

Int32 operator >>(int n) {
if (n < 0) {
throw new ArgumentError(n);
throw ArgumentError(n);
}
if (n >= 32) {
return isNegative ? const Int32._internal(-1) : ZERO;
Expand All @@ -258,12 +238,12 @@ class Int32 implements IntX {
} else {
value = (_i >> n) | (0xffffffff << (32 - n));
}
return new Int32(value);
return Int32(value);
}

Int32 shiftRightUnsigned(int n) {
if (n < 0) {
throw new ArgumentError(n);
throw ArgumentError(n);
}
if (n >= 32) {
return ZERO;
Expand All @@ -274,13 +254,11 @@ class Int32 implements IntX {
} else {
value = (_i >> n) & ((1 << (32 - n)) - 1);
}
return new Int32(value);
return Int32(value);
}

/**
* Returns [:true:] if this [Int32] has the same numeric value as the
* given object. The argument may be an [int] or an [IntX].
*/
/// Returns [:true:] if this [Int32] has the same numeric value as the
/// given object. The argument may be an [int] or an [IntX].
bool operator ==(other) {
if (other is Int32) {
return _i == other._i;
Expand Down Expand Up @@ -337,17 +315,17 @@ class Int32 implements IntX {

int get hashCode => _i;

Int32 abs() => _i < 0 ? new Int32(-_i) : this;
Int32 abs() => _i < 0 ? Int32(-_i) : this;

Int32 clamp(lowerLimit, upperLimit) {
if (this < lowerLimit) {
if (lowerLimit is IntX) return lowerLimit.toInt32();
if (lowerLimit is int) return new Int32(lowerLimit);
throw new ArgumentError(lowerLimit);
if (lowerLimit is int) return Int32(lowerLimit);
throw ArgumentError(lowerLimit);
} else if (this > upperLimit) {
if (upperLimit is IntX) return upperLimit.toInt32();
if (upperLimit is int) return new Int32(upperLimit);
throw new ArgumentError(upperLimit);
if (upperLimit is int) return Int32(upperLimit);
throw ArgumentError(upperLimit);
}
return this;
}
Expand All @@ -356,17 +334,17 @@ class Int32 implements IntX {
int numberOfTrailingZeros() => _numberOfTrailingZeros(_i);

Int32 toSigned(int width) {
if (width < 1 || width > 32) throw new RangeError.range(width, 1, 32);
return new Int32(_i.toSigned(width));
if (width < 1 || width > 32) throw RangeError.range(width, 1, 32);
return Int32(_i.toSigned(width));
}

Int32 toUnsigned(int width) {
if (width < 0 || width > 32) throw new RangeError.range(width, 0, 32);
return new Int32(_i.toUnsigned(width));
if (width < 0 || width > 32) throw RangeError.range(width, 0, 32);
return Int32(_i.toUnsigned(width));
}

List<int> toBytes() {
List<int> result = new List<int>(4);
List<int> result = List<int>(4);
result[0] = _i & 0xff;
result[1] = (_i >> 8) & 0xff;
result[2] = (_i >> 16) & 0xff;
Expand All @@ -377,7 +355,7 @@ class Int32 implements IntX {
double toDouble() => _i.toDouble();
int toInt() => _i;
Int32 toInt32() => this;
Int64 toInt64() => new Int64(_i);
Int64 toInt64() => Int64(_i);

String toString() => _i.toString();
String toHexString() => _i.toRadixString(16);
Expand Down
Loading

0 comments on commit 8ed49bd

Please sign in to comment.