Skip to content

Commit 04d7e7d

Browse files
committed
Test on oldest supported SDK, enable and fix many lints
1 parent bebd9cb commit 04d7e7d

File tree

5 files changed

+170
-78
lines changed

5 files changed

+170
-78
lines changed

.travis.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
language: dart
22

3-
# By default, builds are run in containers.
4-
# https://docs.travis-ci.com/user/getting-started/#Selecting-infrastructure-(optional)
5-
# Set `sudo: true` to disable containers if you need to use sudo in your scripts.
6-
# sudo: true
7-
83
dart:
4+
- 2.0.0
95
- dev
10-
# See https://docs.travis-ci.com/user/languages/dart/ for details.
6+
117
dart_task:
128
- dartfmt
139
- dartanalyzer
10+
1411
# TODO: reinstate tests once https://github.com/dart-lang/http_retry/issues/6 is fixed
1512
# - test: --platform vm
1613
# xvfb: false

analysis_options.yaml

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

lib/http_retry.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:math' as math;
77

88
import 'package:async/async.dart';
99
import 'package:http/http.dart';
10+
import 'package:pedantic/pedantic.dart';
1011

1112
/// An HTTP client wrapper that automatically retries failing requests.
1213
class RetryClient extends BaseClient {
@@ -28,7 +29,7 @@ class RetryClient extends BaseClient {
2829
/// The callback to call to indicate that a request is being retried.
2930
final void Function(BaseRequest, BaseResponse, int) _onRetry;
3031

31-
/// Creates a client wrapping [inner] that retries HTTP requests.
32+
/// Creates a client wrapping [_inner] that retries HTTP requests.
3233
///
3334
/// This retries a failing request [retries] times (3 by default). Note that
3435
/// `n` retries means that the request will be sent at most `n + 1` times.
@@ -58,7 +59,7 @@ class RetryClient extends BaseClient {
5859
_whenError = whenError ?? ((_, __) => false),
5960
_delay = delay ??
6061
((retryCount) =>
61-
new Duration(milliseconds: 500) * math.pow(1.5, retryCount)),
62+
Duration(milliseconds: 500) * math.pow(1.5, retryCount)),
6263
_onRetry = onRetry {
6364
RangeError.checkNotNegative(_retries, "retries");
6465
}
@@ -87,11 +88,12 @@ class RetryClient extends BaseClient {
8788
whenError: whenError,
8889
onRetry: onRetry);
8990

91+
@override
9092
Future<StreamedResponse> send(BaseRequest request) async {
91-
var splitter = new StreamSplitter(request.finalize());
93+
var splitter = StreamSplitter(request.finalize());
9294

9395
var i = 0;
94-
while (true) {
96+
for (;;) {
9597
StreamedResponse response;
9698
try {
9799
response = await _inner.send(_copyRequest(request, splitter.split()));
@@ -104,18 +106,18 @@ class RetryClient extends BaseClient {
104106

105107
// Make sure the response stream is listened to so that we don't leave
106108
// dangling connections.
107-
response.stream.listen((_) {}).cancel()?.catchError((_) {});
109+
unawaited(response.stream.listen((_) {}).cancel()?.catchError((_) {}));
108110
}
109111

110-
await new Future.delayed(_delay(i));
112+
await Future.delayed(_delay(i));
111113
if (_onRetry != null) _onRetry(request, response, i);
112114
i++;
113115
}
114116
}
115117

116118
/// Returns a copy of [original] with the given [body].
117119
StreamedRequest _copyRequest(BaseRequest original, Stream<List<int>> body) {
118-
var request = new StreamedRequest(original.method, original.url);
120+
var request = StreamedRequest(original.method, original.url);
119121
request.contentLength = original.contentLength;
120122
request.followRedirects = original.followRedirects;
121123
request.headers.addAll(original.headers);
@@ -130,5 +132,6 @@ class RetryClient extends BaseClient {
130132
return request;
131133
}
132134

135+
@override
133136
void close() => _inner.close();
134137
}

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ environment:
1111
dependencies:
1212
async: ^2.0.7
1313
http: '>=0.11.0 <0.13.0'
14+
pedantic: ^1.0.0
1415

1516
dev_dependencies:
1617
fake_async: ^1.0.0

0 commit comments

Comments
 (0)