Skip to content

Commit 4b36dfb

Browse files
authored
Update package to pedantic 1.8.0 (flutter#12)
* Update package to pedantic 1.8.0 * Update travis to use stable, update SDK constraints * format files * Travis: test with 2.1.1
1 parent 22c2eb6 commit 4b36dfb

File tree

12 files changed

+175
-78
lines changed

12 files changed

+175
-78
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: dart
22

33
dart:
44
- dev
5-
- 2.0.0
5+
- 2.1.1
66

77
dart_task:
88
- test

analysis_options.yaml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
include: package:pedantic/analysis_options.yaml
2+
analyzer:
3+
strong-mode:
4+
implicit-casts: false
5+
linter:
6+
rules:
7+
- always_declare_return_types
8+
#- annotate_overrides
9+
- avoid_bool_literals_in_conditional_expressions
10+
- avoid_classes_with_only_static_members
11+
- avoid_empty_else
12+
- avoid_function_literals_in_foreach_calls
13+
- avoid_init_to_null
14+
- avoid_null_checks_in_equality_operators
15+
- avoid_relative_lib_imports
16+
- avoid_renaming_method_parameters
17+
- avoid_return_types_on_setters
18+
- avoid_returning_null
19+
- avoid_returning_null_for_future
20+
- avoid_returning_null_for_void
21+
- avoid_returning_this
22+
- avoid_shadowing_type_parameters
23+
- avoid_single_cascade_in_expression_statements
24+
- avoid_types_as_parameter_names
25+
- avoid_unused_constructor_parameters
26+
- await_only_futures
27+
- camel_case_types
28+
- cancel_subscriptions
29+
- cascade_invocations
30+
- comment_references
31+
- constant_identifier_names
32+
- control_flow_in_finally
33+
- directives_ordering
34+
- empty_catches
35+
- empty_constructor_bodies
36+
- empty_statements
37+
- file_names
38+
- hash_and_equals
39+
- implementation_imports
40+
- invariant_booleans
41+
- iterable_contains_unrelated_type
42+
- join_return_with_assignment
43+
- library_names
44+
- library_prefixes
45+
- list_remove_unrelated_type
46+
- literal_only_boolean_expressions
47+
- no_adjacent_strings_in_list
48+
- no_duplicate_case_values
49+
- non_constant_identifier_names
50+
- null_closures
51+
- omit_local_variable_types
52+
- only_throw_errors
53+
- overridden_fields
54+
- package_api_docs
55+
- package_names
56+
- package_prefixed_library_names
57+
- prefer_adjacent_string_concatenation
58+
- prefer_collection_literals
59+
- prefer_conditional_assignment
60+
- prefer_const_constructors
61+
- prefer_contains
62+
- prefer_equal_for_default_values
63+
- prefer_final_fields
64+
#- prefer_final_locals
65+
- prefer_generic_function_type_aliases
66+
- prefer_initializing_formals
67+
- prefer_interpolation_to_compose_strings
68+
- prefer_is_empty
69+
- prefer_is_not_empty
70+
- prefer_null_aware_operators
71+
#- prefer_single_quotes
72+
- prefer_typing_uninitialized_variables
73+
- recursive_getters
74+
- slash_for_doc_comments
75+
- test_types_in_equals
76+
- throw_in_finally
77+
- type_init_formals
78+
- unawaited_futures
79+
- unnecessary_await_in_return
80+
- unnecessary_brace_in_string_interps
81+
- unnecessary_const
82+
- unnecessary_getters_setters
83+
- unnecessary_lambdas
84+
- unnecessary_new
85+
- unnecessary_null_aware_assignments
86+
- unnecessary_parenthesis
87+
- unnecessary_statements
88+
- unnecessary_this
89+
- unrelated_type_equality_checks
90+
- use_function_type_syntax_for_parameters
91+
- use_rethrow_when_possible
92+
- valid_regexps
93+
- void_checks

lib/clock.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import 'src/default.dart';
16+
1517
export 'src/clock.dart';
1618
export 'src/default.dart';
1719

18-
import 'src/default.dart';
19-
2020
/// Returns current time.
2121
@Deprecated("Pass around an instance of Clock instead.")
22-
typedef DateTime TimeFunction();
22+
typedef TimeFunction = DateTime Function();
2323

2424
/// Returns the current system time.
2525
@Deprecated("Use new DateTime.now() instead.")
26-
DateTime systemTime() => new DateTime.now();
26+
DateTime systemTime() => DateTime.now();
2727

2828
/// Returns the current time as reported by [clock].
2929
@Deprecated("Use clock.now() instead.")

lib/src/clock.dart

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import 'utils.dart';
16-
1715
import '../clock.dart';
1816
import 'stopwatch.dart';
17+
import 'utils.dart';
1918

2019
/// A provider for the "current time" and points relative to the current time.
2120
///
@@ -34,7 +33,9 @@ class Clock {
3433

3534
/// Creates a clock based on the given [currentTime], or on the system clock
3635
/// by default.
37-
const Clock([DateTime currentTime() = systemTime]) : _time = currentTime;
36+
// ignore: deprecated_member_use_from_same_package
37+
const Clock([DateTime Function() currentTime = systemTime])
38+
: _time = currentTime;
3839

3940
/// Creates [Clock] that always considers the current time to be [time].
4041
Clock.fixed(DateTime time) : _time = (() => time);
@@ -52,13 +53,13 @@ class Clock {
5253
///
5354
/// The amount of time is the sum of the individual parts.
5455
DateTime ago(
55-
{int days: 0,
56-
int hours: 0,
57-
int minutes: 0,
58-
int seconds: 0,
59-
int milliseconds: 0,
60-
int microseconds: 0}) =>
61-
agoBy(new Duration(
56+
{int days = 0,
57+
int hours = 0,
58+
int minutes = 0,
59+
int seconds = 0,
60+
int milliseconds = 0,
61+
int microseconds = 0}) =>
62+
agoBy(Duration(
6263
days: days,
6364
hours: hours,
6465
minutes: minutes,
@@ -70,13 +71,13 @@ class Clock {
7071
///
7172
/// The amount of time is the sum of the individual parts.
7273
DateTime fromNow(
73-
{int days: 0,
74-
int hours: 0,
75-
int minutes: 0,
76-
int seconds: 0,
77-
int milliseconds: 0,
78-
int microseconds: 0}) =>
79-
fromNowBy(new Duration(
74+
{int days = 0,
75+
int hours = 0,
76+
int minutes = 0,
77+
int seconds = 0,
78+
int milliseconds = 0,
79+
int microseconds = 0}) =>
80+
fromNowBy(Duration(
8081
days: days,
8182
hours: hours,
8283
minutes: minutes,
@@ -137,7 +138,7 @@ class Clock {
137138
var month = (time.month - months - 1) % 12 + 1;
138139
var year = time.year - (months + 12 - time.month) ~/ 12;
139140
var day = clampDayOfMonth(year: year, month: month, day: time.day);
140-
return new DateTime(year, month, day, time.hour, time.minute, time.second,
141+
return DateTime(year, month, day, time.hour, time.minute, time.second,
141142
time.millisecond);
142143
}
143144

@@ -150,7 +151,7 @@ class Clock {
150151
var month = (time.month + months - 1) % 12 + 1;
151152
var year = time.year + (months + time.month - 1) ~/ 12;
152153
var day = clampDayOfMonth(year: year, month: month, day: time.day);
153-
return new DateTime(year, month, day, time.hour, time.minute, time.second,
154+
return DateTime(year, month, day, time.hour, time.minute, time.second,
154155
time.millisecond);
155156
}
156157

@@ -162,8 +163,8 @@ class Clock {
162163
var time = now();
163164
var year = time.year - years;
164165
var day = clampDayOfMonth(year: year, month: time.month, day: time.day);
165-
return new DateTime(year, time.month, day, time.hour, time.minute,
166-
time.second, time.millisecond);
166+
return DateTime(year, time.month, day, time.hour, time.minute, time.second,
167+
time.millisecond);
167168
}
168169

169170
/// Return the point in time [years] from now on the same date.
@@ -172,10 +173,10 @@ class Clock {
172173
/// valid day in the original month will be used.
173174
DateTime yearsFromNow(int years) => yearsAgo(-years);
174175

175-
/// Returns a new stopwatch that uses the current time as reported by [this].
176-
Stopwatch stopwatch() => new ClockStopwatch(this);
176+
/// Returns a new stopwatch that uses the current time as reported by `this`.
177+
Stopwatch stopwatch() => ClockStopwatch(this);
177178

178-
/// Returns a new stopwatch that uses the current time as reported by [this].
179+
/// Returns a new stopwatch that uses the current time as reported by `this`.
179180
@Deprecated("Use stopwatch() instead.")
180181
Stopwatch getStopwatch() => stopwatch();
181182
}

lib/src/default.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,31 @@ import 'clock.dart';
1818

1919
/// The key for the [Zone] value that controls the current implementation of
2020
/// [clock].
21-
final _clockKey = new Object();
21+
final _clockKey = Object();
2222

2323
/// The key for the [Zone] value that controls whether nested zones can override
2424
/// [clock].
25-
final _isFinalKey = new Object();
25+
final _isFinalKey = Object();
2626

2727
/// The default implementation of [clock] for the current [Zone].
2828
///
2929
/// This defaults to the system clock. It can be set within a zone using
3030
/// [withClock].
31-
Clock get clock => Zone.current[_clockKey] ?? const Clock();
31+
Clock get clock => Zone.current[_clockKey] as Clock ?? const Clock();
3232

3333
/// Runs [callback] with the given value for the top-level [clock] field.
3434
///
3535
/// This is [Zone]-scoped, so asynchronous callbacks spawned within [callback]
3636
/// will also use the new value for [clock].
3737
///
38+
// ignore: deprecated_member_use_from_same_package
3839
/// If [isFinal] is `true`, calls to [withClock] within [callback] will throw a
3940
/// [StateError]. However, this parameter is deprecated and should be avoided.
40-
T withClock<T>(Clock clock, T callback(), {@deprecated bool isFinal: false}) {
41-
if (Zone.current[_isFinalKey] ?? false) {
42-
throw new StateError(
43-
"Cannot call withClock() within a call to withClock(isFinal: true).");
41+
T withClock<T>(Clock clock, T Function() callback,
42+
{@deprecated bool isFinal = false}) {
43+
if ((Zone.current[_isFinalKey] ?? false) == true) {
44+
throw StateError(
45+
"Cannot call withClock() within a call to withClock(isFinal = true).");
4446
}
4547

4648
return runZoned(callback,

lib/src/stopwatch.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import 'clock.dart';
1919
/// We can't really know how frequently the clock is updated, and that may not
2020
/// even make sense for some implementations, so we just pretend we follow the
2121
/// system's frequency.
22-
final _frequency = new Stopwatch().frequency;
22+
final _frequency = Stopwatch().frequency;
2323

2424
/// A stopwatch that gets its notion of the current time from a [Clock].
2525
class ClockStopwatch implements Stopwatch {
@@ -40,7 +40,7 @@ class ClockStopwatch implements Stopwatch {
4040

4141
int get frequency => _frequency;
4242
int get elapsedTicks => (elapsedMicroseconds * frequency) ~/ 1000000;
43-
Duration get elapsed => new Duration(microseconds: elapsedMicroseconds);
43+
Duration get elapsed => Duration(microseconds: elapsedMicroseconds);
4444
int get elapsedMilliseconds => elapsedMicroseconds ~/ 1000;
4545
bool get isRunning => _start != null;
4646

lib/src/utils.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import 'package:meta/meta.dart';
2222
///
2323
/// This array uses 1-based month numbers, i.e. January is the 1-st element in
2424
/// the array, not the 0-th.
25-
const _daysInMonth = const [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
25+
const _daysInMonth = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
2626

2727
/// Returns the number of days in the specified month.
2828
///
@@ -42,7 +42,7 @@ int daysInMonth(int year, int month) =>
4242
bool isLeapYear(int year) =>
4343
year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
4444

45-
/// Takes a [date] that may be outside the allowed range of dates for a given
45+
/// Takes a `date` that may be outside the allowed range of dates for a given
4646
/// [month] in a given [year] and returns the closest date that is within the
4747
/// allowed range.
4848
///
@@ -58,4 +58,4 @@ bool isLeapYear(int year) =>
5858
/// doesn't have 31-st date.
5959
int clampDayOfMonth(
6060
{@required int year, @required int month, @required int day}) =>
61-
day.clamp(1, daysInMonth(year, month));
61+
day.clamp(1, daysInMonth(year, month)) as int;

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ author: Dart Team <[email protected]>
55
homepage: https://github.com/dart-lang/clock
66

77
environment:
8-
sdk: '>=2.0.0 <3.0.0'
8+
sdk: '>=2.1.1 <3.0.0'
99

1010
dependencies:
1111
meta: '>=0.9.0 <2.0.0'
1212

1313
dev_dependencies:
1414
test: ^1.0.0
15+
pedantic: ^1.8.0

0 commit comments

Comments
 (0)