Formatting + pedantic

This commit is contained in:
Tobe O 2019-04-10 22:37:05 -04:00
parent 53b47dd43f
commit d210456d44
14 changed files with 47 additions and 43 deletions

View file

@ -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

View file

@ -7,7 +7,7 @@ const List<Type> _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<String> optional: const []}) {
RequestHandler ioc(Function handler, {Iterable<String> optional = const []}) {
InjectionRequest injection;
RequestHandler contained;
@ -129,10 +129,10 @@ class InjectionRequest {
final Map<String, Parameter> 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 = {},

View file

@ -23,10 +23,10 @@ class MapService extends Service<String, Map<String, dynamic>> {
final List<Map<String, dynamic>> 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 =>

View file

@ -18,7 +18,7 @@ class Hooks {
final List<HookedServiceEventListener> before;
final List<HookedServiceEventListener> 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<String> 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,

View file

@ -191,7 +191,7 @@ abstract class RequestContext<RawRequest> {
/// [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<RawRequest> {
bool get acceptsAll => _acceptsAllCache ??= accepts('*/*');
/// Manually parses the request body, if it has not already been parsed.
Future<void> parseBody({Encoding encoding: utf8}) async {
Future<void> 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<String> readAsString({Encoding encoding: utf8}) {
Future<String> readAsString({Encoding encoding = utf8}) {
return data.transform(encoding.decoder).join();
}
}

View file

@ -173,7 +173,7 @@ abstract class ResponseContext<RawResponse>
/// 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<RawResponse>
/// 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'

View file

@ -95,7 +95,7 @@ class Routable extends Router<RequestHandler> {
@override
Route<RequestHandler> addRoute(
String method, String path, RequestHandler handler,
{Iterable<RequestHandler> middleware: const <RequestHandler>[]}) {
{Iterable<RequestHandler> middleware = const []}) {
final handlers = <RequestHandler>[];
// Merge @Middleware declaration, if any
Middleware middlewareDeclaration =

View file

@ -150,7 +150,7 @@ class Angel extends Routable {
@override
Route<RequestHandler> addRoute(
String method, String path, RequestHandler handler,
{Iterable<RequestHandler> middleware: const <RequestHandler>[]}) {
{Iterable<RequestHandler> 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) {

View file

@ -26,19 +26,19 @@ class AngelHttp extends Driver<HttpRequest, HttpResponse, HttpServer,
Future<HttpServer> 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<HttpServer> 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<HttpRequest, HttpResponse, HttpServer,
/// the server.
factory AngelHttp.secure(
Angel app, String certificateChainPath, String serverKeyPath,
{String password, bool useZone: true}) {
{String password, bool useZone = true}) {
var certificateChain =
Platform.script.resolve(certificateChainPath).toFilePath();
var serverKey = Platform.script.resolve(serverKeyPath).toFilePath();
@ -86,7 +86,7 @@ class AngelHttp extends Driver<HttpRequest, HttpResponse, HttpServer,
Future<HttpRequestContext> 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);
}

View file

@ -71,7 +71,7 @@ class HttpResponseContext extends ResponseContext<HttpResponse> {
}
@override
void set contentType(MediaType value) {
set contentType(MediaType value) {
super.contentType = value;
if (!_streamInitialized)
rawResponse.headers.contentType =

View file

@ -30,7 +30,7 @@ class AngelHttp2 extends Driver<Socket, ServerTransportStream,
);
factory AngelHttp2(Angel app, SecurityContext securityContext,
{bool useZone: true, ServerSettings settings}) {
{bool useZone = true, ServerSettings settings}) {
return new AngelHttp2.custom(app, securityContext, SecureServerSocket.bind,
settings: settings);
}
@ -40,7 +40,7 @@ class AngelHttp2 extends Driver<Socket, ServerTransportStream,
SecurityContext ctx,
Future<SecureServerSocket> 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

View file

@ -204,7 +204,7 @@ class Http2ResponseContext extends ResponseContext<ServerTransportStream> {
/// Pushes a resource to the client.
Http2ResponseContext push(String path,
{Map<String, String> headers: const {}, String method: 'GET'}) {
{Map<String, String> headers = const {}, String method = 'GET'}) {
var targetUri = _req.uri.replace(path: path);
var h = <Header>[

View file

@ -30,4 +30,5 @@ dependencies:
dev_dependencies:
http: ^0.11.3
io: ^0.3.0
pedantic: ^1.0.0
test: ^1.0.0

View file

@ -11,8 +11,8 @@ void main() {
var http = AngelHttp(app);
Future<RequestContext> request(
{bool asJson: true,
bool parse: true,
{bool asJson = true,
bool parse = true,
Map<String, dynamic> bodyFields,
List bodyList}) async {
var rq = MockHttpRequest('POST', Uri(path: '/'));