Skip to content

Commit 347b507

Browse files
authored
Enable and fix lint cascade_invocations (#307)
1 parent 4cf5ec5 commit 347b507

12 files changed

+107
-113
lines changed

analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ linter:
1919
- avoid_unused_constructor_parameters
2020
- await_only_futures
2121
- camel_case_types
22-
# cascade_invocations
22+
- cascade_invocations
2323
# comment_references
2424
- control_flow_in_finally
2525
- curly_braces_in_flow_control_structures

lib/src/browser_client.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class BrowserClient extends BaseClient {
4747
var xhr = HttpRequest();
4848
_xhrs.add(xhr);
4949
_openHttpRequest(xhr, request.method, request.url.toString(), asynch: true);
50-
xhr.responseType = 'blob';
51-
xhr.withCredentials = withCredentials;
50+
xhr
51+
..responseType = 'blob'
52+
..withCredentials = withCredentials;
5253
request.headers.forEach(xhr.setRequestHeader);
5354

5455
var completer = Completer<StreamedResponse>();

lib/src/io_client.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ class IOClient extends BaseClient {
3131
var stream = request.finalize();
3232

3333
try {
34-
var ioRequest = await _inner.openUrl(request.method, request.url);
35-
36-
ioRequest
34+
var ioRequest = (await _inner.openUrl(request.method, request.url))
3735
..followRedirects = request.followRedirects
3836
..maxRedirects = request.maxRedirects
3937
..contentLength =

test/html/streamed_request_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import 'utils.dart';
1313
void main() {
1414
group('contentLength', () {
1515
test("works when it's set", () {
16-
var request = http.StreamedRequest('POST', echoUrl);
17-
request.contentLength = 10;
18-
request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
19-
request.sink.close();
16+
var request = http.StreamedRequest('POST', echoUrl)
17+
..contentLength = 10
18+
..sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
19+
..sink.close();
2020

2121
return BrowserClient().send(request).then((response) {
2222
expect(response.stream.toBytes(),

test/io/request_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ void main() {
1313
test('.send', () {
1414
expect(
1515
startServer().then((_) {
16-
var request = http.Request('POST', serverUrl);
17-
request.body = 'hello';
18-
request.headers['User-Agent'] = 'Dart';
16+
var request = http.Request('POST', serverUrl)
17+
..body = 'hello'
18+
..headers['User-Agent'] = 'Dart';
1919

2020
expect(
2121
request.send().then((response) {

test/io/streamed_request_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ void main() {
1515
group('contentLength', () {
1616
test('controls the Content-Length header', () {
1717
return startServer().then((_) {
18-
var request = http.StreamedRequest('POST', serverUrl);
19-
request.contentLength = 10;
20-
request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
21-
request.sink.close();
18+
var request = http.StreamedRequest('POST', serverUrl)
19+
..contentLength = 10
20+
..sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
21+
..sink.close();
2222

2323
return request.send();
2424
}).then((response) {

test/io/utils.dart

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,39 @@ Future startServer() {
2727
var response = request.response;
2828

2929
if (path == '/error') {
30-
response.statusCode = 400;
31-
response.contentLength = 0;
32-
response.close();
30+
response
31+
..statusCode = 400
32+
..contentLength = 0
33+
..close();
3334
return;
3435
}
3536

3637
if (path == '/loop') {
3738
var n = int.parse(request.uri.query);
38-
response.statusCode = 302;
39-
response.headers
40-
.set('location', serverUrl.resolve('/loop?${n + 1}').toString());
41-
response.contentLength = 0;
42-
response.close();
39+
response
40+
..statusCode = 302
41+
..headers
42+
.set('location', serverUrl.resolve('/loop?${n + 1}').toString())
43+
..contentLength = 0
44+
..close();
4345
return;
4446
}
4547

4648
if (path == '/redirect') {
47-
response.statusCode = 302;
48-
response.headers.set('location', serverUrl.resolve('/').toString());
49-
response.contentLength = 0;
50-
response.close();
49+
response
50+
..statusCode = 302
51+
..headers.set('location', serverUrl.resolve('/').toString())
52+
..contentLength = 0
53+
..close();
5154
return;
5255
}
5356

5457
if (path == '/no-content-length') {
55-
response.statusCode = 200;
56-
response.contentLength = -1;
57-
response.write('body');
58-
response.close();
58+
response
59+
..statusCode = 200
60+
..contentLength = -1
61+
..write('body')
62+
..close();
5963
return;
6064
}
6165

@@ -99,9 +103,10 @@ Future startServer() {
99103
});
100104

101105
var body = json.encode(content);
102-
response.contentLength = body.length;
103-
response.write(body);
104-
response.close();
106+
response
107+
..contentLength = body.length
108+
..write(body)
109+
..close();
105110
});
106111
});
107112
});

test/mock_client_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ void main() {
3131
return bodyStream.bytesToString().then((bodyString) {
3232
var controller = StreamController<List<int>>(sync: true);
3333
Future.sync(() {
34-
controller.add('Request body was "$bodyString"'.codeUnits);
35-
controller.close();
34+
controller
35+
..add('Request body was "$bodyString"'.codeUnits)
36+
..close();
3637
});
3738

3839
return http.StreamedResponse(controller.stream, 200);
3940
});
4041
});
4142

4243
var uri = Uri.parse('http://example.com/foo');
43-
var request = http.Request('POST', uri);
44-
request.body = 'hello, world';
44+
var request = http.Request('POST', uri)..body = 'hello, world';
4545
var future = client
4646
.send(request)
4747
.then(http.Response.fromStream)

test/multipart_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ void main() {
203203
--{{boundary}}--
204204
'''));
205205

206-
controller.add([104, 101, 108, 108, 111]);
207-
controller.close();
206+
controller
207+
..add([104, 101, 108, 108, 111])
208+
..close();
208209
});
209210

210211
test('with an empty stream file', () {

0 commit comments

Comments
 (0)