Skip to content

Commit afcbd57

Browse files
kevmoonatebosch
authored andcommitted
Remove implicit casts (#344)
1 parent 9a17157 commit afcbd57

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

analysis_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
include: package:pedantic/analysis_options.yaml
2+
analyzer:
3+
strong-mode:
4+
implicit-casts: false
25
linter:
36
rules:
47
- annotate_overrides

lib/src/base_client.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ abstract class BaseClient implements Client {
157157
Future<Response> _sendUnstreamed(
158158
String method, url, Map<String, String> headers,
159159
[body, Encoding encoding]) async {
160-
if (url is String) url = Uri.parse(url);
161-
var request = Request(method, url);
160+
var request = Request(method, _fromUriOrString(url));
162161

163162
if (headers != null) request.headers.addAll(headers);
164163
if (encoding != null) request.encoding = encoding;
@@ -184,8 +183,7 @@ abstract class BaseClient implements Client {
184183
if (response.reasonPhrase != null) {
185184
message = '$message: ${response.reasonPhrase}';
186185
}
187-
if (url is String) url = Uri.parse(url);
188-
throw ClientException('$message.', url);
186+
throw ClientException('$message.', _fromUriOrString(url));
189187
}
190188

191189
/// Closes the client and cleans up any resources associated with it.
@@ -195,3 +193,5 @@ abstract class BaseClient implements Client {
195193
@override
196194
void close() {}
197195
}
196+
197+
Uri _fromUriOrString(uri) => uri is String ? Uri.parse(uri) : uri as Uri;

lib/src/browser_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class BrowserClient extends BaseClient {
5555
unawaited(xhr.onLoad.first.then((_) {
5656
// TODO(nweiz): Set the response type to "arraybuffer" when issue 18542
5757
// is fixed.
58-
var blob = xhr.response ?? Blob([]);
58+
var blob = xhr.response as Blob ?? Blob([]);
5959
var reader = FileReader();
6060

6161
reader.onLoad.first.then((_) {

lib/src/io_client.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ class IOClient extends BaseClient {
4040
});
4141

4242
var response =
43-
await stream.pipe(DelegatingStreamConsumer.typed(ioRequest));
43+
await stream.pipe(DelegatingStreamConsumer.typed(ioRequest))
44+
as HttpClientResponse;
45+
4446
var headers = <String, String>{};
4547
response.headers.forEach((key, values) {
4648
headers[key] = values.join(',');
4749
});
4850

4951
return StreamedResponse(
5052
DelegatingStream.typed<List<int>>(response).handleError(
51-
(error) => throw ClientException(error.message, error.uri),
53+
(HttpException error) =>
54+
throw ClientException(error.message, error.uri),
5255
test: (error) => error is HttpException),
5356
response.statusCode,
5457
contentLength:

test/utils.dart

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ String cleanUpLiteral(String text) {
4040

4141
/// A matcher that matches JSON that parses to a value that matches the inner
4242
/// matcher.
43-
Matcher parse(matcher) => _Parse(matcher);
43+
Matcher parse(Matcher matcher) => _Parse(matcher);
4444

4545
class _Parse extends Matcher {
4646
final Matcher _matcher;
@@ -49,16 +49,17 @@ class _Parse extends Matcher {
4949

5050
@override
5151
bool matches(item, Map matchState) {
52-
if (item is! String) return false;
53-
54-
dynamic parsed;
55-
try {
56-
parsed = json.decode(item);
57-
} catch (e) {
58-
return false;
52+
if (item is String) {
53+
dynamic parsed;
54+
try {
55+
parsed = json.decode(item);
56+
} catch (e) {
57+
return false;
58+
}
59+
60+
return _matcher.matches(parsed, matchState);
5961
}
60-
61-
return _matcher.matches(parsed, matchState);
62+
return false;
6263
}
6364

6465
@override
@@ -83,9 +84,11 @@ class _BodyMatches extends Matcher {
8384

8485
@override
8586
bool matches(item, Map matchState) {
86-
if (item is! http.MultipartRequest) return false;
87+
if (item is http.MultipartRequest) {
88+
return completes.matches(_checks(item), matchState);
89+
}
8790

88-
return completes.matches(_checks(item), matchState);
91+
return false;
8992
}
9093

9194
Future<void> _checks(http.MultipartRequest item) async {

0 commit comments

Comments
 (0)