Remove implicit casts (#344)
diff --git a/analysis_options.yaml b/analysis_options.yaml
index e42fee8..60a8ea8 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -1,4 +1,7 @@
include: package:pedantic/analysis_options.yaml
+analyzer:
+ strong-mode:
+ implicit-casts: false
linter:
rules:
- annotate_overrides
diff --git a/lib/src/base_client.dart b/lib/src/base_client.dart
index 3be18a8..007fe37 100644
--- a/lib/src/base_client.dart
+++ b/lib/src/base_client.dart
@@ -157,8 +157,7 @@
Future<Response> _sendUnstreamed(
String method, url, Map<String, String> headers,
[body, Encoding encoding]) async {
- if (url is String) url = Uri.parse(url);
- var request = Request(method, url);
+ var request = Request(method, _fromUriOrString(url));
if (headers != null) request.headers.addAll(headers);
if (encoding != null) request.encoding = encoding;
@@ -184,8 +183,7 @@
if (response.reasonPhrase != null) {
message = '$message: ${response.reasonPhrase}';
}
- if (url is String) url = Uri.parse(url);
- throw ClientException('$message.', url);
+ throw ClientException('$message.', _fromUriOrString(url));
}
/// Closes the client and cleans up any resources associated with it.
@@ -195,3 +193,5 @@
@override
void close() {}
}
+
+Uri _fromUriOrString(uri) => uri is String ? Uri.parse(uri) : uri as Uri;
diff --git a/lib/src/browser_client.dart b/lib/src/browser_client.dart
index 76c613d..1fb25b5 100644
--- a/lib/src/browser_client.dart
+++ b/lib/src/browser_client.dart
@@ -55,7 +55,7 @@
unawaited(xhr.onLoad.first.then((_) {
// TODO(nweiz): Set the response type to "arraybuffer" when issue 18542
// is fixed.
- var blob = xhr.response ?? Blob([]);
+ var blob = xhr.response as Blob ?? Blob([]);
var reader = FileReader();
reader.onLoad.first.then((_) {
diff --git a/lib/src/io_client.dart b/lib/src/io_client.dart
index f19594f..402ce81 100644
--- a/lib/src/io_client.dart
+++ b/lib/src/io_client.dart
@@ -40,7 +40,9 @@
});
var response =
- await stream.pipe(DelegatingStreamConsumer.typed(ioRequest));
+ await stream.pipe(DelegatingStreamConsumer.typed(ioRequest))
+ as HttpClientResponse;
+
var headers = <String, String>{};
response.headers.forEach((key, values) {
headers[key] = values.join(',');
@@ -48,7 +50,8 @@
return StreamedResponse(
DelegatingStream.typed<List<int>>(response).handleError(
- (error) => throw ClientException(error.message, error.uri),
+ (HttpException error) =>
+ throw ClientException(error.message, error.uri),
test: (error) => error is HttpException),
response.statusCode,
contentLength:
diff --git a/test/utils.dart b/test/utils.dart
index cd6190c..6411b1a 100644
--- a/test/utils.dart
+++ b/test/utils.dart
@@ -40,7 +40,7 @@
/// A matcher that matches JSON that parses to a value that matches the inner
/// matcher.
-Matcher parse(matcher) => _Parse(matcher);
+Matcher parse(Matcher matcher) => _Parse(matcher);
class _Parse extends Matcher {
final Matcher _matcher;
@@ -49,16 +49,17 @@
@override
bool matches(item, Map matchState) {
- if (item is! String) return false;
+ if (item is String) {
+ dynamic parsed;
+ try {
+ parsed = json.decode(item);
+ } catch (e) {
+ return false;
+ }
- dynamic parsed;
- try {
- parsed = json.decode(item);
- } catch (e) {
- return false;
+ return _matcher.matches(parsed, matchState);
}
-
- return _matcher.matches(parsed, matchState);
+ return false;
}
@override
@@ -83,9 +84,11 @@
@override
bool matches(item, Map matchState) {
- if (item is! http.MultipartRequest) return false;
+ if (item is http.MultipartRequest) {
+ return completes.matches(_checks(item), matchState);
+ }
- return completes.matches(_checks(item), matchState);
+ return false;
}
Future<void> _checks(http.MultipartRequest item) async {