Skip to content

Commit 5574029

Browse files
committed
enable and fix a number of lints
1 parent 062ac55 commit 5574029

File tree

3 files changed

+156
-120
lines changed

3 files changed

+156
-120
lines changed

analysis_options.yaml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@ analyzer:
1313
linter:
1414
rules:
1515
- avoid_bool_literals_in_conditional_expressions
16+
- avoid_catching_errors
1617
- avoid_classes_with_only_static_members
1718
- avoid_function_literals_in_foreach_calls
19+
- avoid_private_typedef_functions
20+
- avoid_redundant_argument_values
1821
- avoid_renaming_method_parameters
1922
- avoid_returning_null
2023
- avoid_returning_null_for_future
2124
- avoid_returning_null_for_void
2225
- avoid_returning_this
2326
- avoid_single_cascade_in_expression_statements
2427
- avoid_unused_constructor_parameters
28+
- avoid_void_async
2529
- await_only_futures
2630
- camel_case_types
2731
- cancel_subscriptions
28-
#- cascade_invocations
32+
- cascade_invocations
2933
- comment_references
3034
- constant_identifier_names
3135
- control_flow_in_finally
@@ -37,28 +41,44 @@ linter:
3741
- invariant_booleans
3842
- iterable_contains_unrelated_type
3943
- join_return_with_assignment
44+
- lines_longer_than_80_chars
4045
- list_remove_unrelated_type
4146
- literal_only_boolean_expressions
47+
- missing_whitespace_between_adjacent_strings
4248
- no_adjacent_strings_in_list
49+
- no_runtimeType_toString
4350
- non_constant_identifier_names
4451
- only_throw_errors
4552
- overridden_fields
4653
- package_api_docs
4754
- package_names
4855
- package_prefixed_library_names
56+
- prefer_asserts_in_initializer_lists
4957
- prefer_const_constructors
50-
#- prefer_final_locals
58+
- prefer_const_declarations
59+
- prefer_expression_function_bodies
60+
- prefer_final_locals
61+
- prefer_function_declarations_over_variables
5162
- prefer_initializing_formals
63+
- prefer_inlined_adds
5264
- prefer_interpolation_to_compose_strings
65+
- prefer_is_not_operator
5366
- prefer_null_aware_operators
67+
- prefer_relative_imports
5468
- prefer_typing_uninitialized_variables
69+
- prefer_void_to_null
70+
- provide_deprecation_message
71+
- sort_pub_dependencies
5572
- test_types_in_equals
5673
- throw_in_finally
5774
- unnecessary_await_in_return
5875
- unnecessary_brace_in_string_interps
5976
- unnecessary_getters_setters
6077
- unnecessary_lambdas
6178
- unnecessary_null_aware_assignments
79+
- unnecessary_overrides
6280
- unnecessary_parenthesis
6381
- unnecessary_statements
82+
- unnecessary_string_interpolations
83+
- use_string_buffers
6484
- void_checks

lib/http_retry.dart

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,21 @@ class RetryClient extends BaseClient {
4848
/// the client has a chance to perform side effects like logging. The
4949
/// `response` parameter will be null if the request was retried due to an
5050
/// error for which [whenError] returned `true`.
51-
RetryClient(this._inner,
52-
{int retries,
53-
bool when(BaseResponse response),
54-
bool whenError(error, StackTrace stackTrace),
55-
Duration delay(int retryCount),
56-
void onRetry(BaseRequest request, BaseResponse response, int retryCount)})
57-
: _retries = retries ?? 3,
51+
RetryClient(
52+
this._inner, {
53+
int retries,
54+
bool Function(BaseResponse) when,
55+
bool Function(Object, StackTrace) whenError,
56+
Duration Function(int retryCount) delay,
57+
void Function(BaseRequest, BaseResponse, int retryCount) onRetry,
58+
}) : _retries = retries ?? 3,
5859
_when = when ?? ((response) => response.statusCode == 503),
5960
_whenError = whenError ?? ((_, __) => false),
6061
_delay = delay ??
6162
((retryCount) =>
62-
Duration(milliseconds: 500) * math.pow(1.5, retryCount)),
63+
const Duration(milliseconds: 500) * math.pow(1.5, retryCount)),
6364
_onRetry = onRetry {
64-
RangeError.checkNotNegative(_retries, "retries");
65+
RangeError.checkNotNegative(_retries, 'retries');
6566
}
6667

6768
/// Like [new RetryClient], but with a pre-computed list of [delays]
@@ -70,27 +71,38 @@ class RetryClient extends BaseClient {
7071
/// This will retry a request at most `delays.length` times, using each delay
7172
/// in order. It will wait for `delays[0]` after the initial request,
7273
/// `delays[1]` after the first retry, and so on.
73-
RetryClient.withDelays(Client inner, Iterable<Duration> delays,
74-
{bool when(BaseResponse response),
75-
bool whenError(error, StackTrace stackTrace),
76-
void onRetry(BaseRequest request, BaseResponse response, int retryCount)})
77-
: this._withDelays(inner, delays.toList(),
78-
when: when, whenError: whenError, onRetry: onRetry);
79-
80-
RetryClient._withDelays(Client inner, List<Duration> delays,
81-
{bool when(BaseResponse response),
82-
bool whenError(error, StackTrace stackTrace),
83-
void onRetry(BaseRequest request, BaseResponse response, int retryCount)})
84-
: this(inner,
85-
retries: delays.length,
86-
delay: (retryCount) => delays[retryCount],
87-
when: when,
88-
whenError: whenError,
89-
onRetry: onRetry);
74+
RetryClient.withDelays(
75+
Client inner,
76+
Iterable<Duration> delays, {
77+
bool Function(BaseResponse) when,
78+
bool Function(Object, StackTrace) whenError,
79+
void Function(BaseRequest, BaseResponse, int retryCount) onRetry,
80+
}) : this._withDelays(
81+
inner,
82+
delays.toList(),
83+
when: when,
84+
whenError: whenError,
85+
onRetry: onRetry,
86+
);
87+
88+
RetryClient._withDelays(
89+
Client inner,
90+
List<Duration> delays, {
91+
bool Function(BaseResponse) when,
92+
bool Function(Object, StackTrace) whenError,
93+
void Function(BaseRequest, BaseResponse, int) onRetry,
94+
}) : this(
95+
inner,
96+
retries: delays.length,
97+
delay: (retryCount) => delays[retryCount],
98+
when: when,
99+
whenError: whenError,
100+
onRetry: onRetry,
101+
);
90102

91103
@override
92104
Future<StreamedResponse> send(BaseRequest request) async {
93-
var splitter = StreamSplitter(request.finalize());
105+
final splitter = StreamSplitter(request.finalize());
94106

95107
var i = 0;
96108
for (;;) {
@@ -117,12 +129,12 @@ class RetryClient extends BaseClient {
117129

118130
/// Returns a copy of [original] with the given [body].
119131
StreamedRequest _copyRequest(BaseRequest original, Stream<List<int>> body) {
120-
var request = StreamedRequest(original.method, original.url);
121-
request.contentLength = original.contentLength;
122-
request.followRedirects = original.followRedirects;
123-
request.headers.addAll(original.headers);
124-
request.maxRedirects = original.maxRedirects;
125-
request.persistentConnection = original.persistentConnection;
132+
final request = StreamedRequest(original.method, original.url)
133+
..contentLength = original.contentLength
134+
..followRedirects = original.followRedirects
135+
..headers.addAll(original.headers)
136+
..maxRedirects = original.maxRedirects
137+
..persistentConnection = original.persistentConnection;
126138

127139
body.listen(request.sink.add,
128140
onError: request.sink.addError,

0 commit comments

Comments
 (0)