From 1c07aa5243f7d4b5369525ad8a726223cb93412f Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 17 Apr 2019 15:42:24 -0400 Subject: [PATCH] apply pkg:pedantic lints --- analysis_options.yaml | 2 -- lib/src/http2/angel_http2.dart | 9 ++++---- pubspec.yaml | 2 +- test/detach_test.dart | 8 +++---- test/di_test.dart | 3 ++- test/encoders_buffer_test.dart | 11 +++++----- test/http2/adapter_test.dart | 10 ++++----- test/http2/http2_client.dart | 3 ++- test/parameter_meta_test.dart | 38 ++++++++++++++++++++-------------- test/precontained_test.dart | 3 ++- test/primitives_test.dart | 14 ++++++++----- test/server_test.dart | 24 ++++++++++++--------- test/streaming_test.dart | 10 ++++++--- 13 files changed, 78 insertions(+), 59 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index b3302c76..55411a32 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -2,8 +2,6 @@ include: package:pedantic/analysis_options.yaml analyzer: strong-mode: implicit-casts: false - errors: - unawaited_futures: ignore linter: rules: - avoid_slow_async_io diff --git a/lib/src/http2/angel_http2.dart b/lib/src/http2/angel_http2.dart index 86e64c97..c062f0de 100644 --- a/lib/src/http2/angel_http2.dart +++ b/lib/src/http2/angel_http2.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:angel_framework/angel_framework.dart' hide Header; import 'package:http2/transport.dart'; import 'package:mock_request/mock_request.dart'; +import 'package:pedantic/pedantic.dart'; import 'http2_request_context.dart'; import 'http2_response_context.dart'; import 'package:uuid/uuid.dart'; @@ -148,7 +149,7 @@ class _FakeServerSocket extends Stream implements ServerSocket { @override Future close() async { - _ctrl.close(); + unawaited(_ctrl.close()); return this; } @@ -202,9 +203,9 @@ class _AngelHttp2ServerSocket extends Stream int get port => socket.port; Future close() async { - _sub?.cancel(); - _fake.close(); - _ctrl.close(); + unawaited(_sub?.cancel()); + unawaited(_fake.close()); + unawaited(_ctrl.close()); return await socket.close(); } diff --git a/pubspec.yaml b/pubspec.yaml index 3ad3dc10..35018389 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,6 +23,7 @@ dependencies: mime: ^0.9.3 mock_request: ^1.0.0 path: ^1.0.0 + pedantic: ^1.0.0 quiver_hashcode: ^2.0.0 stack_trace: ^1.0.0 tuple: ^1.0.0 @@ -30,5 +31,4 @@ dependencies: dev_dependencies: http: ^0.11.3 io: ^0.3.0 - pedantic: ^1.0.0 test: ^1.0.0 diff --git a/test/detach_test.dart b/test/detach_test.dart index 57f4d628..481557fa 100644 --- a/test/detach_test.dart +++ b/test/detach_test.dart @@ -14,9 +14,8 @@ void main() { app.get('/detach', (req, res) async { if (res is HttpResponseContext) { var io = await res.detach(); - io - ..write('Hey!') - ..close(); + io..write('Hey!'); + await io.close(); } else { throw new StateError('This endpoint only supports HTTP/1.1.'); } @@ -26,7 +25,8 @@ void main() { tearDown(() => http.close()); test('detach response', () async { - var rq = new MockHttpRequest('GET', Uri.parse('/detach'))..close(); + var rq = new MockHttpRequest('GET', Uri.parse('/detach')); + await rq.close(); var rs = rq.response; await http.handleRequest(rq); var body = await rs.transform(utf8.decoder).join(); diff --git a/test/di_test.dart b/test/di_test.dart index ea7205cb..c46315b7 100644 --- a/test/di_test.dart +++ b/test/di_test.dart @@ -62,7 +62,8 @@ main() { return app.runContained((Todo t) => t.text, req, res, c); }); - var rq = new MockHttpRequest('GET', new Uri(path: '/'))..close(); + var rq = new MockHttpRequest('GET', new Uri(path: '/')); + await rq.close(); var rs = rq.response; await new AngelHttp(app).handleRequest(rq); var text = await rs.transform(utf8.decoder).join(); diff --git a/test/encoders_buffer_test.dart b/test/encoders_buffer_test.dart index 09fa887d..07aea608 100644 --- a/test/encoders_buffer_test.dart +++ b/test/encoders_buffer_test.dart @@ -51,7 +51,8 @@ void encodingTests(Angel getApp()) { }); test('sends plaintext if no accept-encoding', () async { - var rq = new MockHttpRequest('GET', Uri.parse('/hello'))..close(); + var rq = new MockHttpRequest('GET', Uri.parse('/hello')); + await rq.close(); var rs = rq.response; await http.handleRequest(rq); @@ -61,8 +62,8 @@ void encodingTests(Angel getApp()) { test('encodes if wildcard', () async { var rq = new MockHttpRequest('GET', Uri.parse('/hello')) - ..headers.set('accept-encoding', '*') - ..close(); + ..headers.set('accept-encoding', '*'); + await rq.close(); var rs = rq.response; await http.handleRequest(rq); @@ -74,8 +75,8 @@ void encodingTests(Angel getApp()) { test('encodes if wildcard + multiple', () async { var rq = new MockHttpRequest('GET', Uri.parse('/hello')) - ..headers.set('accept-encoding', ['foo', 'bar', '*']) - ..close(); + ..headers.set('accept-encoding', ['foo', 'bar', '*']); + await rq.close(); var rs = rq.response; await http.handleRequest(rq); diff --git a/test/http2/adapter_test.dart b/test/http2/adapter_test.dart index ea625790..dddfa503 100644 --- a/test/http2/adapter_test.dart +++ b/test/http2/adapter_test.dart @@ -76,13 +76,11 @@ void main() { res.write('ok'); if (res is Http2ResponseContext && res.canPush) { - res.push('a') - ..write('a') - ..close(); + var a = res.push('a')..write('a'); + await a.close(); - res.push('b') - ..write('b') - ..close(); + var b = res.push('b')..write('b'); + await b.close(); } await res.close(); diff --git a/test/http2/http2_client.dart b/test/http2/http2_client.dart index 8a63e145..5bf3d320 100644 --- a/test/http2/http2_client.dart +++ b/test/http2/http2_client.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:http/http.dart'; import 'package:http2/transport.dart'; +import 'package:pedantic/pedantic.dart'; /// Simple HTTP/2 client class Http2Client extends BaseClient { @@ -46,7 +47,7 @@ class Http2Client extends BaseClient { if (body.isNotEmpty) { stream.sendData(body, endStream: true); } else { - stream.outgoingMessages.close(); + unawaited(stream.outgoingMessages.close()); } return stream; diff --git a/test/parameter_meta_test.dart b/test/parameter_meta_test.dart index 6b65ca70..2c12c9e4 100644 --- a/test/parameter_meta_test.dart +++ b/test/parameter_meta_test.dart @@ -5,6 +5,7 @@ import 'package:angel_container/mirrors.dart'; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/http.dart'; import 'package:mock_request/mock_request.dart'; +import 'package:pedantic/pedantic.dart'; import 'package:test/test.dart'; Future readResponse(MockHttpResponse rs) { @@ -68,19 +69,20 @@ parameterMetaTests() { test('injects header or throws', () async { // Invalid request - var rq = new MockHttpRequest('GET', Uri.parse('/header'))..close(); + var rq = new MockHttpRequest('GET', Uri.parse('/header')); + unawaited(rq.close()); var rs = rq.response; - http.handleRequest(rq); + unawaited(http.handleRequest(rq)); await printResponse(rs); expect(rs.statusCode, 400); // Valid request rq = new MockHttpRequest('GET', Uri.parse('/header')) - ..headers.add('x-foo', 'bar') - ..close(); + ..headers.add('x-foo', 'bar'); + unawaited(rq.close()); rs = rq.response; - await http.handleRequest(rq); + await unawaited(http.handleRequest(rq)); var body = await readResponse(rs); print('Body: $body'); @@ -90,21 +92,22 @@ parameterMetaTests() { test('injects session or throws', () async { // Invalid request - var rq = new MockHttpRequest('GET', Uri.parse('/session'))..close(); + var rq = new MockHttpRequest('GET', Uri.parse('/session')); + unawaited(rq.close()); var rs = rq.response; - http + unawaited(http .handleRequest(rq) .timeout(const Duration(seconds: 5)) - .catchError((_) => null); + .catchError((_) => null)); await printResponse(rs); expect(rs.statusCode, 500); rq = new MockHttpRequest('GET', Uri.parse('/session')); rq.session['foo'] = 'bar'; - rq.close(); + unawaited(rq.close()); rs = rq.response; - http.handleRequest(rq); + unawaited(http.handleRequest(rq)); await printResponse(rs); expect(rs.statusCode, 200); @@ -115,26 +118,29 @@ parameterMetaTests() { // they will all function the same way. test('pattern matching', () async { - var rq = new MockHttpRequest('GET', Uri.parse('/match?mode=pos'))..close(); + var rq = new MockHttpRequest('GET', Uri.parse('/match?mode=pos')); + unawaited(rq.close()); var rs = rq.response; - http.handleRequest(rq); + unawaited(http.handleRequest(rq)); var body = await readResponse(rs); print('Body: $body'); expect(rs.statusCode, 200); expect(body, json.encode('YES pos')); - rq = new MockHttpRequest('GET', Uri.parse('/match?mode=neg'))..close(); + rq = new MockHttpRequest('GET', Uri.parse('/match?mode=neg')); + unawaited(rq.close()); rs = rq.response; - http.handleRequest(rq); + unawaited(http.handleRequest(rq)); body = await readResponse(rs); print('Body: $body'); expect(rs.statusCode, 200); expect(body, json.encode('NO neg')); // Fallback - rq = new MockHttpRequest('GET', Uri.parse('/match?mode=ambi'))..close(); + rq = new MockHttpRequest('GET', Uri.parse('/match?mode=ambi')); + unawaited(rq.close()); rs = rq.response; - http.handleRequest(rq); + unawaited(http.handleRequest(rq)); body = await readResponse(rs); print('Body: $body'); expect(rs.statusCode, 200); diff --git a/test/precontained_test.dart b/test/precontained_test.dart index dd2e42dd..736ee372 100644 --- a/test/precontained_test.dart +++ b/test/precontained_test.dart @@ -4,6 +4,7 @@ import 'package:angel_container/mirrors.dart'; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/http.dart'; import 'package:mock_request/mock_request.dart'; +import 'package:pedantic/pedantic.dart'; import 'package:test/test.dart'; main() { @@ -16,7 +17,7 @@ main() { expect(app.preContained.keys, contains(echoAppFoo)); var rq = new MockHttpRequest('GET', new Uri(path: '/foo')); - rq.close(); + unawaited(rq.close()); await new AngelHttp(app).handleRequest(rq); var rs = rq.response; var body = await rs.transform(utf8.decoder).join(); diff --git a/test/primitives_test.dart b/test/primitives_test.dart index 200fd8eb..904f88f6 100644 --- a/test/primitives_test.dart +++ b/test/primitives_test.dart @@ -5,6 +5,7 @@ import 'package:angel_container/mirrors.dart'; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/http.dart'; import 'package:mock_request/mock_request.dart'; +import 'package:pedantic/pedantic.dart'; import 'package:test/test.dart'; main() { @@ -38,21 +39,24 @@ main() { tearDown(() => app.close()); test('String type annotation', () async { - var rq = new MockHttpRequest('GET', Uri.parse('/string/hello'))..close(); + var rq = new MockHttpRequest('GET', Uri.parse('/string/hello')); + unawaited(rq.close()); await http.handleRequest(rq); var rs = await rq.response.transform(utf8.decoder).join(); expect(rs, json.encode('hello')); }); test('Primitive after parsed param injection', () async { - var rq = new MockHttpRequest('GET', Uri.parse('/num/parsed/24'))..close(); + var rq = new MockHttpRequest('GET', Uri.parse('/num/parsed/24')); + unawaited(rq.close()); await http.handleRequest(rq); var rs = await rq.response.transform(utf8.decoder).join(); expect(rs, json.encode(24)); }); test('globally-injected primitive', () async { - var rq = new MockHttpRequest('GET', Uri.parse('/num/global'))..close(); + var rq = new MockHttpRequest('GET', Uri.parse('/num/global')); + unawaited(rq.close()); await http.handleRequest(rq); var rs = await rq.response.transform(utf8.decoder).join(); expect(rs, json.encode(305)); @@ -60,8 +64,8 @@ main() { test('unparsed primitive throws error', () async { try { - var rq = new MockHttpRequest('GET', Uri.parse('/num/unparsed/32')) - ..close(); + var rq = new MockHttpRequest('GET', Uri.parse('/num/unparsed/32')); + unawaited(rq.close()); var req = await http.createRequestContext(rq, rq.response); var res = await http.createResponseContext(rq, rq.response, req); await app.runContained((num unparsed) => unparsed, req, res); diff --git a/test/server_test.dart b/test/server_test.dart index 079cf1e5..d00e9ce2 100644 --- a/test/server_test.dart +++ b/test/server_test.dart @@ -7,6 +7,7 @@ import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/http.dart'; import 'package:matcher/matcher.dart'; import 'package:mock_request/mock_request.dart'; +import 'package:pedantic/pedantic.dart'; import 'package:test/test.dart'; final Uri $foo = Uri.parse('http://localhost:3000/foo'); @@ -42,7 +43,7 @@ main() { var app = new Angel(reflector: MirrorsReflector()); var http = new AngelHttp(app); var rq = new MockHttpRequest('GET', $foo); - rq.close(); + unawaited(rq.close()); var rs = rq.response; var req = await http.createRequestContext(rq, rs); var res = await http.createResponseContext(rq, rs); @@ -94,7 +95,8 @@ main() { ..configuration['a'] = 'b'; var http = new AngelHttp(app); app.get('/', ioc((String a) => a)); - var rq = new MockHttpRequest('GET', Uri.parse('/'))..close(); + var rq = new MockHttpRequest('GET', Uri.parse('/')); + unawaited(rq.close()); await http.handleRequest(rq); var body = await rq.response.transform(utf8.decoder).join(); expect(body, json.encode('b')); @@ -104,7 +106,8 @@ main() { var app = new Angel(reflector: MirrorsReflector())..serializer = (_) => 'x'; var http = new AngelHttp(app); app.get($foo.path, (req, ResponseContext res) => res.serialize(null)); - var rq = new MockHttpRequest('GET', $foo)..close(); + var rq = new MockHttpRequest('GET', $foo); + unawaited(rq.close()); await http.handleRequest(rq); var body = await rq.response.transform(utf8.decoder).join(); expect(body, 'x'); @@ -119,7 +122,8 @@ main() { ResponseContext res; setUp(() async { - var rq = new MockHttpRequest('GET', $foo)..close(); + var rq = new MockHttpRequest('GET', $foo); + unawaited(rq.close()); req = await http.createRequestContext(rq, rq.response); res = await http.createResponseContext(rq, rq.response); }); @@ -176,8 +180,8 @@ main() { test('can send json', () async { var rq = new MockHttpRequest('GET', new Uri(path: 'wtf')) ..headers.set('accept', 'application/json'); - rq.close(); - http.handleRequest(rq); + unawaited(rq.close()); + unawaited(http.handleRequest(rq)); await rq.response.toList(); expect(rq.response.statusCode, 403); expect(rq.response.headers.contentType.mimeType, 'application/json'); @@ -186,8 +190,8 @@ main() { test('can throw in finalizer', () async { var rq = new MockHttpRequest('GET', new Uri(path: 'wtf')) ..headers.set('accept', 'application/json'); - rq.close(); - http.handleRequest(rq); + unawaited(rq.close()); + unawaited(http.handleRequest(rq)); await rq.response.toList(); expect(rq.response.statusCode, 403); expect(rq.response.headers.contentType.mimeType, 'application/json'); @@ -196,8 +200,8 @@ main() { test('can send html', () async { var rq = new MockHttpRequest('GET', new Uri(path: 'wtf2')); rq.headers.set('accept', 'text/html'); - rq.close(); - http.handleRequest(rq); + unawaited(rq.close()); + unawaited(http.handleRequest(rq)); await rq.response.toList(); expect(rq.response.statusCode, 403); expect(rq.response.headers.contentType?.mimeType, 'text/html'); diff --git a/test/streaming_test.dart b/test/streaming_test.dart index a7d21d15..6661b8f9 100644 --- a/test/streaming_test.dart +++ b/test/streaming_test.dart @@ -8,6 +8,7 @@ import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/http.dart'; import 'package:logging/logging.dart'; import 'package:mock_request/mock_request.dart'; +import 'package:pedantic/pedantic.dart'; import 'package:test/test.dart'; import 'encoders_buffer_test.dart' show encodingTests; @@ -76,7 +77,8 @@ main() { tearDown(() => http.close()); _expectHelloBye(String path) async { - var rq = new MockHttpRequest('GET', Uri.parse(path))..close(); + var rq = new MockHttpRequest('GET', Uri.parse(path)); + unawaited(rq.close()); await http.handleRequest(rq); var body = await rq.response.transform(utf8.decoder).join(); expect(body, 'Hello, world!bye'); @@ -88,7 +90,8 @@ main() { test('cannot write after close', () async { try { - var rq = new MockHttpRequest('GET', Uri.parse('/overwrite'))..close(); + var rq = new MockHttpRequest('GET', Uri.parse('/overwrite')); + unawaited(rq.close()); await http.handleRequest(rq); var body = await rq.response.transform(utf8.decoder).join(); @@ -101,7 +104,8 @@ main() { test('res => addError', () async { try { - var rq = new MockHttpRequest('GET', Uri.parse('/error'))..close(); + var rq = new MockHttpRequest('GET', Uri.parse('/error')); + unawaited(rq.close()); await http.handleRequest(rq); var body = await rq.response.transform(utf8.decoder).join(); throw 'addError should throw error; response: $body';