From d210456d44b1bc57b5d45e1ee9b6e5c66fd06ce9 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 10 Apr 2019 22:37:05 -0400 Subject: [PATCH] Formatting + pedantic --- analysis_options.yaml | 3 +++ lib/src/core/injection.dart | 10 +++++----- lib/src/core/map_service.dart | 8 ++++---- lib/src/core/metadata.dart | 18 +++++++++--------- lib/src/core/request_context.dart | 6 +++--- lib/src/core/response_context.dart | 4 ++-- lib/src/core/routable.dart | 2 +- lib/src/core/server.dart | 16 ++++++++-------- lib/src/http/angel_http.dart | 10 +++++----- lib/src/http/http_response_context.dart | 2 +- lib/src/http2/angel_http2.dart | 4 ++-- lib/src/http2/http2_response_context.dart | 2 +- pubspec.yaml | 1 + test/body_test.dart | 4 ++-- 14 files changed, 47 insertions(+), 43 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index fb26f9d9..b3302c76 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,6 +1,9 @@ +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/core/injection.dart b/lib/src/core/injection.dart index 4db5c9ca..ededfb9b 100644 --- a/lib/src/core/injection.dart +++ b/lib/src/core/injection.dart @@ -7,7 +7,7 @@ const List _primitiveTypes = [String, int, num, double, Null]; /// Use this to instantly create a request handler for a DI-enabled method. /// /// Calling [ioc] also auto-serializes the result of a [handler]. -RequestHandler ioc(Function handler, {Iterable optional: const []}) { +RequestHandler ioc(Function handler, {Iterable optional = const []}) { InjectionRequest injection; RequestHandler contained; @@ -129,10 +129,10 @@ class InjectionRequest { final Map parameters; const InjectionRequest.constant( - {this.named: const {}, - this.required: const [], - this.optional: const [], - this.parameters: const {}}); + {this.named = const {}, + this.required = const [], + this.optional = const [], + this.parameters = const {}}); InjectionRequest() : named = {}, diff --git a/lib/src/core/map_service.dart b/lib/src/core/map_service.dart index 75eef3df..511ce780 100644 --- a/lib/src/core/map_service.dart +++ b/lib/src/core/map_service.dart @@ -23,10 +23,10 @@ class MapService extends Service> { final List> items = []; MapService( - {this.allowRemoveAll: false, - this.allowQuery: true, - this.autoIdAndDateFields: true, - this.autoSnakeCaseNames: true}) + {this.allowRemoveAll = false, + this.allowQuery = true, + this.autoIdAndDateFields = true, + this.autoSnakeCaseNames = true}) : super(); String get createdAtKey => diff --git a/lib/src/core/metadata.dart b/lib/src/core/metadata.dart index 5e1f0f00..ebc917d6 100644 --- a/lib/src/core/metadata.dart +++ b/lib/src/core/metadata.dart @@ -18,7 +18,7 @@ class Hooks { final List before; final List after; - const Hooks({this.before: const [], this.after: const []}); + const Hooks({this.before = const [], this.after = const []}); } /// Exposes a [Controller] to the Internet. @@ -30,10 +30,10 @@ class Expose { final List allowNull; const Expose(this.path, - {this.method: "GET", - this.middleware: const [], - this.as: null, - this.allowNull: const []}); + {this.method = "GET", + this.middleware = const [], + this.as, + this.allowNull = const []}); } /// Used to apply special dependency injections or functionality to a function parameter. @@ -101,7 +101,7 @@ class Parameter { /// Shortcut for declaring a request header [Parameter]. class Header extends Parameter { - const Header(String header, {match, defaultValue, bool required: true}) + const Header(String header, {match, defaultValue, bool required = true}) : super( header: header, match: match, @@ -111,7 +111,7 @@ class Header extends Parameter { /// Shortcut for declaring a request session [Parameter]. class Session extends Parameter { - const Session(String session, {match, defaultValue, bool required: true}) + const Session(String session, {match, defaultValue, bool required = true}) : super( session: session, match: match, @@ -121,7 +121,7 @@ class Session extends Parameter { /// Shortcut for declaring a request query [Parameter]. class Query extends Parameter { - const Query(String query, {match, defaultValue, bool required: true}) + const Query(String query, {match, defaultValue, bool required = true}) : super( query: query, match: match, @@ -131,7 +131,7 @@ class Query extends Parameter { /// Shortcut for declaring a request cookie [Parameter]. class CookieValue extends Parameter { - const CookieValue(String cookie, {match, defaultValue, bool required: true}) + const CookieValue(String cookie, {match, defaultValue, bool required = true}) : super( cookie: cookie, match: match, diff --git a/lib/src/core/request_context.dart b/lib/src/core/request_context.dart index 8d0cc337..0e1853e0 100644 --- a/lib/src/core/request_context.dart +++ b/lib/src/core/request_context.dart @@ -191,7 +191,7 @@ abstract class RequestContext { /// [contentType] can be either of the following: /// * A [ContentType], in which case the `Accept` header will be compared against its `mimeType` property. /// * Any other Dart value, in which case the `Accept` header will be compared against the result of a `toString()` call. - bool accepts(contentType, {bool strict: false}) { + bool accepts(contentType, {bool strict = false}) { var contentTypeString = contentType is MediaType ? contentType.mimeType : contentType?.toString(); @@ -215,7 +215,7 @@ abstract class RequestContext { bool get acceptsAll => _acceptsAllCache ??= accepts('*/*'); /// Manually parses the request body, if it has not already been parsed. - Future parseBody({Encoding encoding: utf8}) async { + Future parseBody({Encoding encoding = utf8}) async { if (contentType == null) { throw FormatException('Missing "content-type" header.'); } @@ -322,7 +322,7 @@ class UploadedFile { } /// Reads the contents of the file as [String], using the given [encoding]. - Future readAsString({Encoding encoding: utf8}) { + Future readAsString({Encoding encoding = utf8}) { return data.transform(encoding.decoder).join(); } } diff --git a/lib/src/core/response_context.dart b/lib/src/core/response_context.dart index eb4de267..f4fa7f0b 100644 --- a/lib/src/core/response_context.dart +++ b/lib/src/core/response_context.dart @@ -173,7 +173,7 @@ abstract class ResponseContext /// Returns a JSONP response. /// /// You can override the [contentType] sent; by default it is `application/javascript`. - void jsonp(value, {String callbackName: "callback", MediaType contentType}) { + void jsonp(value, {String callbackName = "callback", MediaType contentType}) { if (!isOpen) throw closed(); this.contentType = contentType ?? new MediaType('application', 'javascript'); @@ -201,7 +201,7 @@ abstract class ResponseContext /// based on the provided params. /// /// See [Router]#navigate for more. :) - void redirect(url, {bool absolute: true, int code: 302}) { + void redirect(url, {bool absolute = true, int code = 302}) { if (!isOpen) throw closed(); headers ..['content-type'] = 'text/html' diff --git a/lib/src/core/routable.dart b/lib/src/core/routable.dart index 01cfe1a9..05463d70 100644 --- a/lib/src/core/routable.dart +++ b/lib/src/core/routable.dart @@ -95,7 +95,7 @@ class Routable extends Router { @override Route addRoute( String method, String path, RequestHandler handler, - {Iterable middleware: const []}) { + {Iterable middleware = const []}) { final handlers = []; // Merge @Middleware declaration, if any Middleware middlewareDeclaration = diff --git a/lib/src/core/server.dart b/lib/src/core/server.dart index b4d401f8..8055f6ca 100644 --- a/lib/src/core/server.dart +++ b/lib/src/core/server.dart @@ -150,7 +150,7 @@ class Angel extends Routable { @override Route addRoute( String method, String path, RequestHandler handler, - {Iterable middleware: const []}) { + {Iterable middleware = const []}) { if (_flattened != null) { logger?.warning( 'WARNING: You added a route ($method $path) to the router, after it had been optimized.'); @@ -216,9 +216,9 @@ class Angel extends Routable { @override void dumpTree( {callback(String tree), - String header: 'Dumping route tree:', - String tab: ' ', - bool showMatchers: false}) { + String header = 'Dumping route tree:', + String tab = ' ', + bool showMatchers = false}) { if (environment.isProduction) { _flattened ??= flatten(this); @@ -292,7 +292,7 @@ class Angel extends Routable { /// * [flatten]s the route tree into a linear one. /// /// You may [force] the optimization to run, if you are not running in production. - void optimizeForProduction({bool force: false}) { + void optimizeForProduction({bool force = false}) { if (environment.isProduction || force == true) { _flattened ??= flatten(this); logger?.info('Angel is running in production mode.'); @@ -354,10 +354,10 @@ class Angel extends Routable { } Angel( - {Reflector reflector: const EmptyReflector(), - this.environment: angelEnv, + {Reflector reflector = const EmptyReflector(), + this.environment = angelEnv, this.logger, - this.allowMethodOverrides: true, + this.allowMethodOverrides = true, this.serializer, this.viewGenerator}) : super(reflector) { diff --git a/lib/src/http/angel_http.dart b/lib/src/http/angel_http.dart index cb6ff71a..9eea0a9b 100644 --- a/lib/src/http/angel_http.dart +++ b/lib/src/http/angel_http.dart @@ -26,19 +26,19 @@ class AngelHttp extends Driver Function(dynamic, int) serverGenerator, bool useZone) : super(app, serverGenerator, useZone: useZone); - factory AngelHttp(Angel app, {bool useZone: true}) { + factory AngelHttp(Angel app, {bool useZone = true}) { return new AngelHttp._(app, HttpServer.bind, useZone); } /// An instance mounted on a server started by the [serverGenerator]. factory AngelHttp.custom( Angel app, Future Function(dynamic, int) serverGenerator, - {bool useZone: true}) { + {bool useZone = true}) { return new AngelHttp._(app, serverGenerator, useZone); } factory AngelHttp.fromSecurityContext(Angel app, SecurityContext context, - {bool useZone: true}) { + {bool useZone = true}) { return new AngelHttp._(app, (address, int port) { return HttpServer.bindSecure(address, port, context); }, useZone); @@ -51,7 +51,7 @@ class AngelHttp extends Driver createRequestContext( HttpRequest request, HttpResponse response) { var path = request.uri.path.replaceAll(_straySlashes, ''); - if (path.length == 0) path = '/'; + if (path.isEmpty) path = '/'; return HttpRequestContext.from(request, app, path); } diff --git a/lib/src/http/http_response_context.dart b/lib/src/http/http_response_context.dart index 50e3c546..a4d140e2 100644 --- a/lib/src/http/http_response_context.dart +++ b/lib/src/http/http_response_context.dart @@ -71,7 +71,7 @@ class HttpResponseContext extends ResponseContext { } @override - void set contentType(MediaType value) { + set contentType(MediaType value) { super.contentType = value; if (!_streamInitialized) rawResponse.headers.contentType = diff --git a/lib/src/http2/angel_http2.dart b/lib/src/http2/angel_http2.dart index 3a90e58f..86e64c97 100644 --- a/lib/src/http2/angel_http2.dart +++ b/lib/src/http2/angel_http2.dart @@ -30,7 +30,7 @@ class AngelHttp2 extends Driver serverGenerator( address, int port, SecurityContext ctx), - {bool useZone: true, + {bool useZone = true, ServerSettings settings}) { return new AngelHttp2._(app, (address, port) { var addr = address is InternetAddress diff --git a/lib/src/http2/http2_response_context.dart b/lib/src/http2/http2_response_context.dart index 0e1224db..bc5c0e4d 100644 --- a/lib/src/http2/http2_response_context.dart +++ b/lib/src/http2/http2_response_context.dart @@ -204,7 +204,7 @@ class Http2ResponseContext extends ResponseContext { /// Pushes a resource to the client. Http2ResponseContext push(String path, - {Map headers: const {}, String method: 'GET'}) { + {Map headers = const {}, String method = 'GET'}) { var targetUri = _req.uri.replace(path: path); var h =
[ diff --git a/pubspec.yaml b/pubspec.yaml index 3d105177..fc678f71 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -30,4 +30,5 @@ dependencies: dev_dependencies: http: ^0.11.3 io: ^0.3.0 + pedantic: ^1.0.0 test: ^1.0.0 diff --git a/test/body_test.dart b/test/body_test.dart index 3c085df1..2f69b541 100644 --- a/test/body_test.dart +++ b/test/body_test.dart @@ -11,8 +11,8 @@ void main() { var http = AngelHttp(app); Future request( - {bool asJson: true, - bool parse: true, + {bool asJson = true, + bool parse = true, Map bodyFields, List bodyList}) async { var rq = MockHttpRequest('POST', Uri(path: '/'));