Skip to content

Commit 14e4fec

Browse files
kevmoonatebosch
andauthored
enable avoid dynamic calls lint (#560)
Co-authored-by: Nate Bosch <[email protected]>
1 parent f38a189 commit 14e4fec

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 0.13.2-dev
2+
13
## 0.13.1
24

35
* Fix code samples in `README` to pass a `Uri` instance.

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ linter:
1212
- avoid_bool_literals_in_conditional_expressions
1313
- avoid_catching_errors
1414
- avoid_classes_with_only_static_members
15+
- avoid_dynamic_calls
1516
- avoid_empty_else
1617
- avoid_function_literals_in_foreach_calls
1718
- avoid_init_to_null

example/main.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:convert' as convert;
2+
23
import 'package:http/http.dart' as http;
34

45
void main(List<String> arguments) async {
@@ -10,7 +11,8 @@ void main(List<String> arguments) async {
1011
// Await the http get response, then decode the json-formatted response.
1112
var response = await http.get(url);
1213
if (response.statusCode == 200) {
13-
var jsonResponse = convert.jsonDecode(response.body);
14+
var jsonResponse =
15+
convert.jsonDecode(response.body) as Map<String, dynamic>;
1416
var itemCount = jsonResponse['totalItems'];
1517
print('Number of books about http: $itemCount.');
1618
} else {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: http
2-
version: 0.13.1
2+
version: 0.13.2-dev
33
homepage: https://github.com/dart-lang/http
44
description: A composable, multi-platform, Future-based API for HTTP requests.
55

test/io/client_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
@TestOn('vm')
6-
76
import 'dart:convert';
87
import 'dart:io';
98

@@ -117,7 +116,8 @@ void main() {
117116
var bytesString = await response.stream.bytesToString();
118117
client.close();
119118

120-
var headers = jsonDecode(bytesString)['headers'] as Map<String, dynamic>;
119+
var headers = (jsonDecode(bytesString) as Map<String, dynamic>)['headers']
120+
as Map<String, dynamic>;
121121
var contentType = (headers['content-type'] as List).single;
122122
expect(contentType, startsWith('multipart/form-data; boundary='));
123123
});

test/io/utils.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,23 @@ Future<void> startServer() async {
8383
requestBody = requestBodyBytes;
8484
}
8585

86-
var content = <String, dynamic>{
87-
'method': request.method,
88-
'path': request.uri.path,
89-
'headers': {}
90-
};
91-
if (requestBody != null) content['body'] = requestBody;
86+
final headers = <String, List<String>>{};
87+
9288
request.headers.forEach((name, values) {
9389
// These headers are automatically generated by dart:io, so we don't
9490
// want to test them here.
9591
if (name == 'cookie' || name == 'host') return;
9692

97-
content['headers'][name] = values;
93+
headers[name] = values;
9894
});
9995

96+
var content = <String, dynamic>{
97+
'method': request.method,
98+
'path': request.uri.path,
99+
if (requestBody != null) 'body': requestBody,
100+
'headers': headers,
101+
};
102+
100103
var body = json.encode(content);
101104
response
102105
..contentLength = body.length

0 commit comments

Comments
 (0)