Formatting + pedantic
This commit is contained in:
parent
53b47dd43f
commit
d210456d44
14 changed files with 47 additions and 43 deletions
|
@ -1,6 +1,9 @@
|
||||||
|
include: package:pedantic/analysis_options.yaml
|
||||||
analyzer:
|
analyzer:
|
||||||
strong-mode:
|
strong-mode:
|
||||||
implicit-casts: false
|
implicit-casts: false
|
||||||
|
errors:
|
||||||
|
unawaited_futures: ignore
|
||||||
linter:
|
linter:
|
||||||
rules:
|
rules:
|
||||||
- avoid_slow_async_io
|
- avoid_slow_async_io
|
||||||
|
|
|
@ -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.
|
/// Use this to instantly create a request handler for a DI-enabled method.
|
||||||
///
|
///
|
||||||
/// Calling [ioc] also auto-serializes the result of a [handler].
|
/// 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;
|
InjectionRequest injection;
|
||||||
RequestHandler contained;
|
RequestHandler contained;
|
||||||
|
|
||||||
|
@ -129,10 +129,10 @@ class InjectionRequest {
|
||||||
final Map<String, Parameter> parameters;
|
final Map<String, Parameter> parameters;
|
||||||
|
|
||||||
const InjectionRequest.constant(
|
const InjectionRequest.constant(
|
||||||
{this.named: const {},
|
{this.named = const {},
|
||||||
this.required: const [],
|
this.required = const [],
|
||||||
this.optional: const [],
|
this.optional = const [],
|
||||||
this.parameters: const {}});
|
this.parameters = const {}});
|
||||||
|
|
||||||
InjectionRequest()
|
InjectionRequest()
|
||||||
: named = {},
|
: named = {},
|
||||||
|
|
|
@ -23,10 +23,10 @@ class MapService extends Service<String, Map<String, dynamic>> {
|
||||||
final List<Map<String, dynamic>> items = [];
|
final List<Map<String, dynamic>> items = [];
|
||||||
|
|
||||||
MapService(
|
MapService(
|
||||||
{this.allowRemoveAll: false,
|
{this.allowRemoveAll = false,
|
||||||
this.allowQuery: true,
|
this.allowQuery = true,
|
||||||
this.autoIdAndDateFields: true,
|
this.autoIdAndDateFields = true,
|
||||||
this.autoSnakeCaseNames: true})
|
this.autoSnakeCaseNames = true})
|
||||||
: super();
|
: super();
|
||||||
|
|
||||||
String get createdAtKey =>
|
String get createdAtKey =>
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Hooks {
|
||||||
final List<HookedServiceEventListener> before;
|
final List<HookedServiceEventListener> before;
|
||||||
final List<HookedServiceEventListener> after;
|
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.
|
/// Exposes a [Controller] to the Internet.
|
||||||
|
@ -30,10 +30,10 @@ class Expose {
|
||||||
final List<String> allowNull;
|
final List<String> allowNull;
|
||||||
|
|
||||||
const Expose(this.path,
|
const Expose(this.path,
|
||||||
{this.method: "GET",
|
{this.method = "GET",
|
||||||
this.middleware: const [],
|
this.middleware = const [],
|
||||||
this.as: null,
|
this.as,
|
||||||
this.allowNull: const []});
|
this.allowNull = const []});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to apply special dependency injections or functionality to a function parameter.
|
/// 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].
|
/// Shortcut for declaring a request header [Parameter].
|
||||||
class Header extends Parameter {
|
class Header extends Parameter {
|
||||||
const Header(String header, {match, defaultValue, bool required: true})
|
const Header(String header, {match, defaultValue, bool required = true})
|
||||||
: super(
|
: super(
|
||||||
header: header,
|
header: header,
|
||||||
match: match,
|
match: match,
|
||||||
|
@ -111,7 +111,7 @@ class Header extends Parameter {
|
||||||
|
|
||||||
/// Shortcut for declaring a request session [Parameter].
|
/// Shortcut for declaring a request session [Parameter].
|
||||||
class Session extends Parameter {
|
class Session extends Parameter {
|
||||||
const Session(String session, {match, defaultValue, bool required: true})
|
const Session(String session, {match, defaultValue, bool required = true})
|
||||||
: super(
|
: super(
|
||||||
session: session,
|
session: session,
|
||||||
match: match,
|
match: match,
|
||||||
|
@ -121,7 +121,7 @@ class Session extends Parameter {
|
||||||
|
|
||||||
/// Shortcut for declaring a request query [Parameter].
|
/// Shortcut for declaring a request query [Parameter].
|
||||||
class Query extends Parameter {
|
class Query extends Parameter {
|
||||||
const Query(String query, {match, defaultValue, bool required: true})
|
const Query(String query, {match, defaultValue, bool required = true})
|
||||||
: super(
|
: super(
|
||||||
query: query,
|
query: query,
|
||||||
match: match,
|
match: match,
|
||||||
|
@ -131,7 +131,7 @@ class Query extends Parameter {
|
||||||
|
|
||||||
/// Shortcut for declaring a request cookie [Parameter].
|
/// Shortcut for declaring a request cookie [Parameter].
|
||||||
class CookieValue extends Parameter {
|
class CookieValue extends Parameter {
|
||||||
const CookieValue(String cookie, {match, defaultValue, bool required: true})
|
const CookieValue(String cookie, {match, defaultValue, bool required = true})
|
||||||
: super(
|
: super(
|
||||||
cookie: cookie,
|
cookie: cookie,
|
||||||
match: match,
|
match: match,
|
||||||
|
|
|
@ -191,7 +191,7 @@ abstract class RequestContext<RawRequest> {
|
||||||
/// [contentType] can be either of the following:
|
/// [contentType] can be either of the following:
|
||||||
/// * A [ContentType], in which case the `Accept` header will be compared against its `mimeType` property.
|
/// * 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.
|
/// * 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
|
var contentTypeString = contentType is MediaType
|
||||||
? contentType.mimeType
|
? contentType.mimeType
|
||||||
: contentType?.toString();
|
: contentType?.toString();
|
||||||
|
@ -215,7 +215,7 @@ abstract class RequestContext<RawRequest> {
|
||||||
bool get acceptsAll => _acceptsAllCache ??= accepts('*/*');
|
bool get acceptsAll => _acceptsAllCache ??= accepts('*/*');
|
||||||
|
|
||||||
/// Manually parses the request body, if it has not already been parsed.
|
/// 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) {
|
if (contentType == null) {
|
||||||
throw FormatException('Missing "content-type" header.');
|
throw FormatException('Missing "content-type" header.');
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,7 @@ class UploadedFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads the contents of the file as [String], using the given [encoding].
|
/// 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();
|
return data.transform(encoding.decoder).join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,7 +173,7 @@ abstract class ResponseContext<RawResponse>
|
||||||
/// Returns a JSONP response.
|
/// Returns a JSONP response.
|
||||||
///
|
///
|
||||||
/// You can override the [contentType] sent; by default it is `application/javascript`.
|
/// 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();
|
if (!isOpen) throw closed();
|
||||||
this.contentType =
|
this.contentType =
|
||||||
contentType ?? new MediaType('application', 'javascript');
|
contentType ?? new MediaType('application', 'javascript');
|
||||||
|
@ -201,7 +201,7 @@ abstract class ResponseContext<RawResponse>
|
||||||
/// based on the provided params.
|
/// based on the provided params.
|
||||||
///
|
///
|
||||||
/// See [Router]#navigate for more. :)
|
/// 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();
|
if (!isOpen) throw closed();
|
||||||
headers
|
headers
|
||||||
..['content-type'] = 'text/html'
|
..['content-type'] = 'text/html'
|
||||||
|
|
|
@ -95,7 +95,7 @@ class Routable extends Router<RequestHandler> {
|
||||||
@override
|
@override
|
||||||
Route<RequestHandler> addRoute(
|
Route<RequestHandler> addRoute(
|
||||||
String method, String path, RequestHandler handler,
|
String method, String path, RequestHandler handler,
|
||||||
{Iterable<RequestHandler> middleware: const <RequestHandler>[]}) {
|
{Iterable<RequestHandler> middleware = const []}) {
|
||||||
final handlers = <RequestHandler>[];
|
final handlers = <RequestHandler>[];
|
||||||
// Merge @Middleware declaration, if any
|
// Merge @Middleware declaration, if any
|
||||||
Middleware middlewareDeclaration =
|
Middleware middlewareDeclaration =
|
||||||
|
|
|
@ -150,7 +150,7 @@ class Angel extends Routable {
|
||||||
@override
|
@override
|
||||||
Route<RequestHandler> addRoute(
|
Route<RequestHandler> addRoute(
|
||||||
String method, String path, RequestHandler handler,
|
String method, String path, RequestHandler handler,
|
||||||
{Iterable<RequestHandler> middleware: const <RequestHandler>[]}) {
|
{Iterable<RequestHandler> middleware = const []}) {
|
||||||
if (_flattened != null) {
|
if (_flattened != null) {
|
||||||
logger?.warning(
|
logger?.warning(
|
||||||
'WARNING: You added a route ($method $path) to the router, after it had been optimized.');
|
'WARNING: You added a route ($method $path) to the router, after it had been optimized.');
|
||||||
|
@ -216,9 +216,9 @@ class Angel extends Routable {
|
||||||
@override
|
@override
|
||||||
void dumpTree(
|
void dumpTree(
|
||||||
{callback(String tree),
|
{callback(String tree),
|
||||||
String header: 'Dumping route tree:',
|
String header = 'Dumping route tree:',
|
||||||
String tab: ' ',
|
String tab = ' ',
|
||||||
bool showMatchers: false}) {
|
bool showMatchers = false}) {
|
||||||
if (environment.isProduction) {
|
if (environment.isProduction) {
|
||||||
_flattened ??= flatten(this);
|
_flattened ??= flatten(this);
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ class Angel extends Routable {
|
||||||
/// * [flatten]s the route tree into a linear one.
|
/// * [flatten]s the route tree into a linear one.
|
||||||
///
|
///
|
||||||
/// You may [force] the optimization to run, if you are not running in production.
|
/// 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) {
|
if (environment.isProduction || force == true) {
|
||||||
_flattened ??= flatten(this);
|
_flattened ??= flatten(this);
|
||||||
logger?.info('Angel is running in production mode.');
|
logger?.info('Angel is running in production mode.');
|
||||||
|
@ -354,10 +354,10 @@ class Angel extends Routable {
|
||||||
}
|
}
|
||||||
|
|
||||||
Angel(
|
Angel(
|
||||||
{Reflector reflector: const EmptyReflector(),
|
{Reflector reflector = const EmptyReflector(),
|
||||||
this.environment: angelEnv,
|
this.environment = angelEnv,
|
||||||
this.logger,
|
this.logger,
|
||||||
this.allowMethodOverrides: true,
|
this.allowMethodOverrides = true,
|
||||||
this.serializer,
|
this.serializer,
|
||||||
this.viewGenerator})
|
this.viewGenerator})
|
||||||
: super(reflector) {
|
: super(reflector) {
|
||||||
|
|
|
@ -26,19 +26,19 @@ class AngelHttp extends Driver<HttpRequest, HttpResponse, HttpServer,
|
||||||
Future<HttpServer> Function(dynamic, int) serverGenerator, bool useZone)
|
Future<HttpServer> Function(dynamic, int) serverGenerator, bool useZone)
|
||||||
: super(app, serverGenerator, useZone: 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);
|
return new AngelHttp._(app, HttpServer.bind, useZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An instance mounted on a server started by the [serverGenerator].
|
/// An instance mounted on a server started by the [serverGenerator].
|
||||||
factory AngelHttp.custom(
|
factory AngelHttp.custom(
|
||||||
Angel app, Future<HttpServer> Function(dynamic, int) serverGenerator,
|
Angel app, Future<HttpServer> Function(dynamic, int) serverGenerator,
|
||||||
{bool useZone: true}) {
|
{bool useZone = true}) {
|
||||||
return new AngelHttp._(app, serverGenerator, useZone);
|
return new AngelHttp._(app, serverGenerator, useZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory AngelHttp.fromSecurityContext(Angel app, SecurityContext context,
|
factory AngelHttp.fromSecurityContext(Angel app, SecurityContext context,
|
||||||
{bool useZone: true}) {
|
{bool useZone = true}) {
|
||||||
return new AngelHttp._(app, (address, int port) {
|
return new AngelHttp._(app, (address, int port) {
|
||||||
return HttpServer.bindSecure(address, port, context);
|
return HttpServer.bindSecure(address, port, context);
|
||||||
}, useZone);
|
}, useZone);
|
||||||
|
@ -51,7 +51,7 @@ class AngelHttp extends Driver<HttpRequest, HttpResponse, HttpServer,
|
||||||
/// the server.
|
/// the server.
|
||||||
factory AngelHttp.secure(
|
factory AngelHttp.secure(
|
||||||
Angel app, String certificateChainPath, String serverKeyPath,
|
Angel app, String certificateChainPath, String serverKeyPath,
|
||||||
{String password, bool useZone: true}) {
|
{String password, bool useZone = true}) {
|
||||||
var certificateChain =
|
var certificateChain =
|
||||||
Platform.script.resolve(certificateChainPath).toFilePath();
|
Platform.script.resolve(certificateChainPath).toFilePath();
|
||||||
var serverKey = Platform.script.resolve(serverKeyPath).toFilePath();
|
var serverKey = Platform.script.resolve(serverKeyPath).toFilePath();
|
||||||
|
@ -86,7 +86,7 @@ class AngelHttp extends Driver<HttpRequest, HttpResponse, HttpServer,
|
||||||
Future<HttpRequestContext> createRequestContext(
|
Future<HttpRequestContext> createRequestContext(
|
||||||
HttpRequest request, HttpResponse response) {
|
HttpRequest request, HttpResponse response) {
|
||||||
var path = request.uri.path.replaceAll(_straySlashes, '');
|
var path = request.uri.path.replaceAll(_straySlashes, '');
|
||||||
if (path.length == 0) path = '/';
|
if (path.isEmpty) path = '/';
|
||||||
return HttpRequestContext.from(request, app, path);
|
return HttpRequestContext.from(request, app, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ class HttpResponseContext extends ResponseContext<HttpResponse> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void set contentType(MediaType value) {
|
set contentType(MediaType value) {
|
||||||
super.contentType = value;
|
super.contentType = value;
|
||||||
if (!_streamInitialized)
|
if (!_streamInitialized)
|
||||||
rawResponse.headers.contentType =
|
rawResponse.headers.contentType =
|
||||||
|
|
|
@ -30,7 +30,7 @@ class AngelHttp2 extends Driver<Socket, ServerTransportStream,
|
||||||
);
|
);
|
||||||
|
|
||||||
factory AngelHttp2(Angel app, SecurityContext securityContext,
|
factory AngelHttp2(Angel app, SecurityContext securityContext,
|
||||||
{bool useZone: true, ServerSettings settings}) {
|
{bool useZone = true, ServerSettings settings}) {
|
||||||
return new AngelHttp2.custom(app, securityContext, SecureServerSocket.bind,
|
return new AngelHttp2.custom(app, securityContext, SecureServerSocket.bind,
|
||||||
settings: settings);
|
settings: settings);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class AngelHttp2 extends Driver<Socket, ServerTransportStream,
|
||||||
SecurityContext ctx,
|
SecurityContext ctx,
|
||||||
Future<SecureServerSocket> serverGenerator(
|
Future<SecureServerSocket> serverGenerator(
|
||||||
address, int port, SecurityContext ctx),
|
address, int port, SecurityContext ctx),
|
||||||
{bool useZone: true,
|
{bool useZone = true,
|
||||||
ServerSettings settings}) {
|
ServerSettings settings}) {
|
||||||
return new AngelHttp2._(app, (address, port) {
|
return new AngelHttp2._(app, (address, port) {
|
||||||
var addr = address is InternetAddress
|
var addr = address is InternetAddress
|
||||||
|
|
|
@ -204,7 +204,7 @@ class Http2ResponseContext extends ResponseContext<ServerTransportStream> {
|
||||||
|
|
||||||
/// Pushes a resource to the client.
|
/// Pushes a resource to the client.
|
||||||
Http2ResponseContext push(String path,
|
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 targetUri = _req.uri.replace(path: path);
|
||||||
|
|
||||||
var h = <Header>[
|
var h = <Header>[
|
||||||
|
|
|
@ -30,4 +30,5 @@ dependencies:
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
http: ^0.11.3
|
http: ^0.11.3
|
||||||
io: ^0.3.0
|
io: ^0.3.0
|
||||||
|
pedantic: ^1.0.0
|
||||||
test: ^1.0.0
|
test: ^1.0.0
|
||||||
|
|
|
@ -11,8 +11,8 @@ void main() {
|
||||||
var http = AngelHttp(app);
|
var http = AngelHttp(app);
|
||||||
|
|
||||||
Future<RequestContext> request(
|
Future<RequestContext> request(
|
||||||
{bool asJson: true,
|
{bool asJson = true,
|
||||||
bool parse: true,
|
bool parse = true,
|
||||||
Map<String, dynamic> bodyFields,
|
Map<String, dynamic> bodyFields,
|
||||||
List bodyList}) async {
|
List bodyList}) async {
|
||||||
var rq = MockHttpRequest('POST', Uri(path: '/'));
|
var rq = MockHttpRequest('POST', Uri(path: '/'));
|
||||||
|
|
Loading…
Reference in a new issue