Update package to pedantic 1.8.0 (#12)
* Update package to pedantic 1.8.0
* Update travis to use stable, update SDK constraints
* format files
* Travis: test with 2.1.1
diff --git a/.travis.yml b/.travis.yml
index 963abdd..412ec44 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,7 +2,7 @@
dart:
- dev
-- 2.0.0
+- 2.1.1
dart_task:
- test
diff --git a/analysis_options.yaml b/analysis_options.yaml
new file mode 100644
index 0000000..168ac15
--- /dev/null
+++ b/analysis_options.yaml
@@ -0,0 +1,93 @@
+include: package:pedantic/analysis_options.yaml
+analyzer:
+ strong-mode:
+ implicit-casts: false
+linter:
+ rules:
+ - always_declare_return_types
+ #- annotate_overrides
+ - avoid_bool_literals_in_conditional_expressions
+ - avoid_classes_with_only_static_members
+ - avoid_empty_else
+ - avoid_function_literals_in_foreach_calls
+ - avoid_init_to_null
+ - avoid_null_checks_in_equality_operators
+ - avoid_relative_lib_imports
+ - avoid_renaming_method_parameters
+ - avoid_return_types_on_setters
+ - avoid_returning_null
+ - avoid_returning_null_for_future
+ - avoid_returning_null_for_void
+ - avoid_returning_this
+ - avoid_shadowing_type_parameters
+ - avoid_single_cascade_in_expression_statements
+ - avoid_types_as_parameter_names
+ - 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_catches
+ - empty_constructor_bodies
+ - empty_statements
+ - file_names
+ - hash_and_equals
+ - implementation_imports
+ - invariant_booleans
+ - iterable_contains_unrelated_type
+ - join_return_with_assignment
+ - library_names
+ - library_prefixes
+ - list_remove_unrelated_type
+ - literal_only_boolean_expressions
+ - no_adjacent_strings_in_list
+ - no_duplicate_case_values
+ - non_constant_identifier_names
+ - null_closures
+ - 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_contains
+ - prefer_equal_for_default_values
+ - prefer_final_fields
+ #- prefer_final_locals
+ - prefer_generic_function_type_aliases
+ - prefer_initializing_formals
+ - prefer_interpolation_to_compose_strings
+ - prefer_is_empty
+ - prefer_is_not_empty
+ - prefer_null_aware_operators
+ #- prefer_single_quotes
+ - prefer_typing_uninitialized_variables
+ - recursive_getters
+ - slash_for_doc_comments
+ - test_types_in_equals
+ - throw_in_finally
+ - type_init_formals
+ - unawaited_futures
+ - unnecessary_await_in_return
+ - unnecessary_brace_in_string_interps
+ - unnecessary_const
+ - unnecessary_getters_setters
+ - unnecessary_lambdas
+ - unnecessary_new
+ - unnecessary_null_aware_assignments
+ - unnecessary_parenthesis
+ - unnecessary_statements
+ - unnecessary_this
+ - unrelated_type_equality_checks
+ - use_function_type_syntax_for_parameters
+ - use_rethrow_when_possible
+ - valid_regexps
+ - void_checks
diff --git a/lib/clock.dart b/lib/clock.dart
index f7bf0b7..9836b39 100644
--- a/lib/clock.dart
+++ b/lib/clock.dart
@@ -12,18 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+import 'src/default.dart';
+
export 'src/clock.dart';
export 'src/default.dart';
-import 'src/default.dart';
-
/// Returns current time.
@Deprecated("Pass around an instance of Clock instead.")
-typedef DateTime TimeFunction();
+typedef TimeFunction = DateTime Function();
/// Returns the current system time.
@Deprecated("Use new DateTime.now() instead.")
-DateTime systemTime() => new DateTime.now();
+DateTime systemTime() => DateTime.now();
/// Returns the current time as reported by [clock].
@Deprecated("Use clock.now() instead.")
diff --git a/lib/src/clock.dart b/lib/src/clock.dart
index 2984e30..088f701 100644
--- a/lib/src/clock.dart
+++ b/lib/src/clock.dart
@@ -12,10 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-import 'utils.dart';
-
import '../clock.dart';
import 'stopwatch.dart';
+import 'utils.dart';
/// A provider for the "current time" and points relative to the current time.
///
@@ -34,7 +33,9 @@
/// Creates a clock based on the given [currentTime], or on the system clock
/// by default.
- const Clock([DateTime currentTime() = systemTime]) : _time = currentTime;
+ // ignore: deprecated_member_use_from_same_package
+ const Clock([DateTime Function() currentTime = systemTime])
+ : _time = currentTime;
/// Creates [Clock] that always considers the current time to be [time].
Clock.fixed(DateTime time) : _time = (() => time);
@@ -52,13 +53,13 @@
///
/// The amount of time is the sum of the individual parts.
DateTime ago(
- {int days: 0,
- int hours: 0,
- int minutes: 0,
- int seconds: 0,
- int milliseconds: 0,
- int microseconds: 0}) =>
- agoBy(new Duration(
+ {int days = 0,
+ int hours = 0,
+ int minutes = 0,
+ int seconds = 0,
+ int milliseconds = 0,
+ int microseconds = 0}) =>
+ agoBy(Duration(
days: days,
hours: hours,
minutes: minutes,
@@ -70,13 +71,13 @@
///
/// The amount of time is the sum of the individual parts.
DateTime fromNow(
- {int days: 0,
- int hours: 0,
- int minutes: 0,
- int seconds: 0,
- int milliseconds: 0,
- int microseconds: 0}) =>
- fromNowBy(new Duration(
+ {int days = 0,
+ int hours = 0,
+ int minutes = 0,
+ int seconds = 0,
+ int milliseconds = 0,
+ int microseconds = 0}) =>
+ fromNowBy(Duration(
days: days,
hours: hours,
minutes: minutes,
@@ -137,7 +138,7 @@
var month = (time.month - months - 1) % 12 + 1;
var year = time.year - (months + 12 - time.month) ~/ 12;
var day = clampDayOfMonth(year: year, month: month, day: time.day);
- return new DateTime(year, month, day, time.hour, time.minute, time.second,
+ return DateTime(year, month, day, time.hour, time.minute, time.second,
time.millisecond);
}
@@ -150,7 +151,7 @@
var month = (time.month + months - 1) % 12 + 1;
var year = time.year + (months + time.month - 1) ~/ 12;
var day = clampDayOfMonth(year: year, month: month, day: time.day);
- return new DateTime(year, month, day, time.hour, time.minute, time.second,
+ return DateTime(year, month, day, time.hour, time.minute, time.second,
time.millisecond);
}
@@ -162,8 +163,8 @@
var time = now();
var year = time.year - years;
var day = clampDayOfMonth(year: year, month: time.month, day: time.day);
- return new DateTime(year, time.month, day, time.hour, time.minute,
- time.second, time.millisecond);
+ return DateTime(year, time.month, day, time.hour, time.minute, time.second,
+ time.millisecond);
}
/// Return the point in time [years] from now on the same date.
@@ -172,10 +173,10 @@
/// valid day in the original month will be used.
DateTime yearsFromNow(int years) => yearsAgo(-years);
- /// Returns a new stopwatch that uses the current time as reported by [this].
- Stopwatch stopwatch() => new ClockStopwatch(this);
+ /// Returns a new stopwatch that uses the current time as reported by `this`.
+ Stopwatch stopwatch() => ClockStopwatch(this);
- /// Returns a new stopwatch that uses the current time as reported by [this].
+ /// Returns a new stopwatch that uses the current time as reported by `this`.
@Deprecated("Use stopwatch() instead.")
Stopwatch getStopwatch() => stopwatch();
}
diff --git a/lib/src/default.dart b/lib/src/default.dart
index b380927..7cb47b2 100644
--- a/lib/src/default.dart
+++ b/lib/src/default.dart
@@ -18,29 +18,31 @@
/// The key for the [Zone] value that controls the current implementation of
/// [clock].
-final _clockKey = new Object();
+final _clockKey = Object();
/// The key for the [Zone] value that controls whether nested zones can override
/// [clock].
-final _isFinalKey = new Object();
+final _isFinalKey = Object();
/// The default implementation of [clock] for the current [Zone].
///
/// This defaults to the system clock. It can be set within a zone using
/// [withClock].
-Clock get clock => Zone.current[_clockKey] ?? const Clock();
+Clock get clock => Zone.current[_clockKey] as Clock ?? const Clock();
/// Runs [callback] with the given value for the top-level [clock] field.
///
/// This is [Zone]-scoped, so asynchronous callbacks spawned within [callback]
/// will also use the new value for [clock].
///
+// ignore: deprecated_member_use_from_same_package
/// If [isFinal] is `true`, calls to [withClock] within [callback] will throw a
/// [StateError]. However, this parameter is deprecated and should be avoided.
-T withClock<T>(Clock clock, T callback(), {@deprecated bool isFinal: false}) {
- if (Zone.current[_isFinalKey] ?? false) {
- throw new StateError(
- "Cannot call withClock() within a call to withClock(isFinal: true).");
+T withClock<T>(Clock clock, T Function() callback,
+ {@deprecated bool isFinal = false}) {
+ if ((Zone.current[_isFinalKey] ?? false) == true) {
+ throw StateError(
+ "Cannot call withClock() within a call to withClock(isFinal = true).");
}
return runZoned(callback,
diff --git a/lib/src/stopwatch.dart b/lib/src/stopwatch.dart
index 1cf66a4..625a5d9 100644
--- a/lib/src/stopwatch.dart
+++ b/lib/src/stopwatch.dart
@@ -19,7 +19,7 @@
/// We can't really know how frequently the clock is updated, and that may not
/// even make sense for some implementations, so we just pretend we follow the
/// system's frequency.
-final _frequency = new Stopwatch().frequency;
+final _frequency = Stopwatch().frequency;
/// A stopwatch that gets its notion of the current time from a [Clock].
class ClockStopwatch implements Stopwatch {
@@ -40,7 +40,7 @@
int get frequency => _frequency;
int get elapsedTicks => (elapsedMicroseconds * frequency) ~/ 1000000;
- Duration get elapsed => new Duration(microseconds: elapsedMicroseconds);
+ Duration get elapsed => Duration(microseconds: elapsedMicroseconds);
int get elapsedMilliseconds => elapsedMicroseconds ~/ 1000;
bool get isRunning => _start != null;
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index c1223cf..843be0b 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -22,7 +22,7 @@
///
/// This array uses 1-based month numbers, i.e. January is the 1-st element in
/// the array, not the 0-th.
-const _daysInMonth = const [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
+const _daysInMonth = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
/// Returns the number of days in the specified month.
///
@@ -42,7 +42,7 @@
bool isLeapYear(int year) =>
year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
-/// Takes a [date] that may be outside the allowed range of dates for a given
+/// Takes a `date` that may be outside the allowed range of dates for a given
/// [month] in a given [year] and returns the closest date that is within the
/// allowed range.
///
@@ -58,4 +58,4 @@
/// doesn't have 31-st date.
int clampDayOfMonth(
{@required int year, @required int month, @required int day}) =>
- day.clamp(1, daysInMonth(year, month));
+ day.clamp(1, daysInMonth(year, month)) as int;
diff --git a/pubspec.yaml b/pubspec.yaml
index 4abae3f..f67cc71 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -5,10 +5,11 @@
homepage: https://github.com/dart-lang/clock
environment:
- sdk: '>=2.0.0 <3.0.0'
+ sdk: '>=2.1.1 <3.0.0'
dependencies:
meta: '>=0.9.0 <2.0.0'
dev_dependencies:
test: ^1.0.0
+ pedantic: ^1.8.0
diff --git a/test/clock_test.dart b/test/clock_test.dart
index 3d2d1b2..b92b531 100644
--- a/test/clock_test.dart
+++ b/test/clock_test.dart
@@ -18,10 +18,10 @@
import 'utils.dart';
-main() {
+void main() {
Clock clock;
setUp(() {
- clock = new Clock.fixed(date(2013));
+ clock = Clock.fixed(date(2013));
});
test('should return a non-null value from system clock', () {
@@ -33,17 +33,15 @@
test('should be close enough to system clock', () {
// At 10ms the test doesn't seem to be flaky.
var epsilon = 10;
- expect(
- new DateTime.now().difference(new Clock().now()).inMilliseconds.abs(),
+ expect(DateTime.now().difference(const Clock().now()).inMilliseconds.abs(),
lessThan(epsilon));
- expect(
- new DateTime.now().difference(const Clock().now()).inMilliseconds.abs(),
+ expect(DateTime.now().difference(const Clock().now()).inMilliseconds.abs(),
lessThan(epsilon));
});
test('should return time provided by a custom function', () {
var time = date(2013);
- var fixedClock = new Clock(() => time);
+ var fixedClock = Clock(() => time);
expect(fixedClock.now(), date(2013));
time = date(2014);
@@ -51,7 +49,7 @@
});
test('should return fixed time', () {
- expect(new Clock.fixed(date(2013)).now(), date(2013));
+ expect(Clock.fixed(date(2013)).now(), date(2013));
});
test('should return time Duration ago', () {
@@ -71,7 +69,7 @@
seconds: 1,
milliseconds: 1,
microseconds: 1000),
- new DateTime(2012, 12, 30, 22, 58, 58, 998));
+ DateTime(2012, 12, 30, 22, 58, 58, 998));
});
test('should return time parts from now', () {
@@ -83,47 +81,47 @@
seconds: 1,
milliseconds: 1,
microseconds: 1000),
- new DateTime(2013, 1, 2, 1, 1, 1, 2));
+ DateTime(2013, 1, 2, 1, 1, 1, 2));
});
test('should return time micros ago', () {
- expect(clock.microsAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 999));
+ expect(clock.microsAgo(1000), DateTime(2012, 12, 31, 23, 59, 59, 999));
});
test('should return time micros from now', () {
- expect(clock.microsFromNow(1000), new DateTime(2013, 1, 1, 0, 0, 0, 1));
+ expect(clock.microsFromNow(1000), DateTime(2013, 1, 1, 0, 0, 0, 1));
});
test('should return time millis ago', () {
- expect(clock.millisAgo(1000), new DateTime(2012, 12, 31, 23, 59, 59, 000));
+ expect(clock.millisAgo(1000), DateTime(2012, 12, 31, 23, 59, 59, 000));
});
test('should return time millis from now', () {
- expect(clock.millisFromNow(3), new DateTime(2013, 1, 1, 0, 0, 0, 3));
+ expect(clock.millisFromNow(3), DateTime(2013, 1, 1, 0, 0, 0, 3));
});
test('should return time seconds ago', () {
- expect(clock.secondsAgo(10), new DateTime(2012, 12, 31, 23, 59, 50, 000));
+ expect(clock.secondsAgo(10), DateTime(2012, 12, 31, 23, 59, 50, 000));
});
test('should return time seconds from now', () {
- expect(clock.secondsFromNow(3), new DateTime(2013, 1, 1, 0, 0, 3, 0));
+ expect(clock.secondsFromNow(3), DateTime(2013, 1, 1, 0, 0, 3, 0));
});
test('should return time minutes ago', () {
- expect(clock.minutesAgo(10), new DateTime(2012, 12, 31, 23, 50, 0, 000));
+ expect(clock.minutesAgo(10), DateTime(2012, 12, 31, 23, 50, 0, 000));
});
test('should return time minutes from now', () {
- expect(clock.minutesFromNow(3), new DateTime(2013, 1, 1, 0, 3, 0, 0));
+ expect(clock.minutesFromNow(3), DateTime(2013, 1, 1, 0, 3, 0, 0));
});
test('should return time hours ago', () {
- expect(clock.hoursAgo(10), new DateTime(2012, 12, 31, 14, 0, 0, 000));
+ expect(clock.hoursAgo(10), DateTime(2012, 12, 31, 14, 0, 0, 000));
});
test('should return time hours from now', () {
- expect(clock.hoursFromNow(3), new DateTime(2013, 1, 1, 3, 0, 0, 0));
+ expect(clock.hoursFromNow(3), DateTime(2013, 1, 1, 3, 0, 0, 0));
});
test('should return time days ago', () {
diff --git a/test/default_test.dart b/test/default_test.dart
index d75e8da..6cbd085 100644
--- a/test/default_test.dart
+++ b/test/default_test.dart
@@ -22,7 +22,7 @@
void main() {
test("the default clock returns the system time", () {
- expect(new DateTime.now().difference(clock.now()).inMilliseconds.abs(),
+ expect(DateTime.now().difference(clock.now()).inMilliseconds.abs(),
lessThan(100));
});
@@ -30,7 +30,7 @@
group("overrides the clock", () {
test("synchronously", () {
var time = date(1990, 11, 8);
- withClock(new Clock(() => time), () {
+ withClock(Clock(() => time), () {
expect(clock.now(), equals(time));
time = date(2016, 6, 26);
expect(clock.now(), equals(time));
@@ -39,8 +39,8 @@
test("asynchronously", () {
var time = date(1990, 11, 8);
- withClock(new Clock.fixed(time), () {
- expect(new Future(() async {
+ withClock(Clock.fixed(time), () {
+ expect(Future(() async {
expect(clock.now(), equals(time));
}), completes);
});
@@ -48,13 +48,13 @@
test("within another withClock() call", () {
var outerTime = date(1990, 11, 8);
- withClock(new Clock.fixed(outerTime), () {
+ withClock(Clock.fixed(outerTime), () {
expect(clock.now(), equals(outerTime));
var innerTime = date(2016, 11, 8);
- withClock(new Clock.fixed(innerTime), () {
+ withClock(Clock.fixed(innerTime), () {
expect(clock.now(), equals(innerTime));
- expect(new Future(() async {
+ expect(Future(() async {
expect(clock.now(), equals(innerTime));
}), completes);
});
@@ -66,7 +66,7 @@
test("with isFinal: true doesn't allow nested calls", () {
var outerTime = date(1990, 11, 8);
- withClock(new Clock.fixed(outerTime), () {
+ withClock(Clock.fixed(outerTime), () {
expect(clock.now(), equals(outerTime));
expect(() => withClock(fixed(2016, 11, 8), neverCalledVoid),
diff --git a/test/stopwatch_test.dart b/test/stopwatch_test.dart
index 151d2dc..66d1194 100644
--- a/test/stopwatch_test.dart
+++ b/test/stopwatch_test.dart
@@ -21,7 +21,7 @@
void main() {
test("returns the system frequency", () {
expect(fixed(1990, 11, 8).stopwatch().frequency,
- equals(new Stopwatch().frequency));
+ equals(Stopwatch().frequency));
});
group("before it starts", () {
@@ -52,7 +52,7 @@
Stopwatch stopwatch;
setUp(() {
time = date(1990, 11, 8);
- clock = new Clock(() => time);
+ clock = Clock(() => time);
stopwatch = clock.stopwatch()..start();
time = clock.microsFromNow(12345);
});
@@ -90,12 +90,13 @@
group("reports elapsed", () {
test("duration", () {
- expect(stopwatch.elapsed, equals(new Duration(microseconds: 12345)));
+ expect(
+ stopwatch.elapsed, equals(const Duration(microseconds: 12345)));
});
test("ticks", () {
expect(stopwatch.elapsedTicks,
- equals((new Stopwatch().frequency * 12345) ~/ 1000000));
+ equals((Stopwatch().frequency * 12345) ~/ 1000000));
});
test("microseconds", () {
@@ -146,12 +147,13 @@
group("reports elapsed", () {
test("duration", () {
- expect(stopwatch.elapsed, equals(new Duration(microseconds: 12345)));
+ expect(
+ stopwatch.elapsed, equals(const Duration(microseconds: 12345)));
});
test("ticks", () {
expect(stopwatch.elapsedTicks,
- equals((new Stopwatch().frequency * 12345) ~/ 1000000));
+ equals((Stopwatch().frequency * 12345) ~/ 1000000));
});
test("microseconds", () {
diff --git a/test/utils.dart b/test/utils.dart
index 17c07f3..3fd1372 100644
--- a/test/utils.dart
+++ b/test/utils.dart
@@ -17,9 +17,9 @@
/// A utility function for tersely constructing a [DateTime] with no time
/// component.
DateTime date(int year, [int month, int day]) =>
- new DateTime(year, month ?? 1, day ?? 1);
+ DateTime(year, month ?? 1, day ?? 1);
/// Returns a clock that always returns a date with the given [year], [month],
/// and [day].
Clock fixed(int year, [int month, int day]) =>
- new Clock.fixed(date(year, month, day));
+ Clock.fixed(date(year, month, day));