enable and fix a number of lints
diff --git a/analysis_options.yaml b/analysis_options.yaml
new file mode 100644
index 0000000..0711aca
--- /dev/null
+++ b/analysis_options.yaml
@@ -0,0 +1,43 @@
+include: package:pedantic/analysis_options.yaml
+analyzer:
+ strong-mode:
+ implicit-casts: false
+linter:
+ rules:
+ - avoid_empty_else
+ - avoid_init_to_null
+ - avoid_null_checks_in_equality_operators
+ - avoid_unused_constructor_parameters
+ - await_only_futures
+ - camel_case_types
+ - cancel_subscriptions
+ - constant_identifier_names
+ - control_flow_in_finally
+ - directives_ordering
+ - empty_catches
+ - empty_constructor_bodies
+ - empty_statements
+ - hash_and_equals
+ - implementation_imports
+ - iterable_contains_unrelated_type
+ - library_names
+ - library_prefixes
+ - list_remove_unrelated_type
+ - non_constant_identifier_names
+ - overridden_fields
+ - package_api_docs
+ - package_names
+ - package_prefixed_library_names
+ - prefer_equal_for_default_values
+ - prefer_final_fields
+ - prefer_generic_function_type_aliases
+ - prefer_is_not_empty
+ - slash_for_doc_comments
+ - test_types_in_equals
+ - throw_in_finally
+ - type_init_formals
+ - unnecessary_brace_in_string_interps
+ - unnecessary_const
+ - unnecessary_new
+ - unrelated_type_equality_checks
+ - valid_regexps
diff --git a/lib/shelf_web_socket.dart b/lib/shelf_web_socket.dart
index 7ce32ee..ba689d8 100644
--- a/lib/shelf_web_socket.dart
+++ b/lib/shelf_web_socket.dart
@@ -45,15 +45,9 @@
{Iterable<String> protocols,
Iterable<String> allowedOrigins,
Duration pingInterval}) {
- if (protocols != null) protocols = protocols.toSet();
- if (allowedOrigins != null) {
- allowedOrigins =
- allowedOrigins.map((origin) => origin.toLowerCase()).toSet();
- }
-
if (onConnection is! _BinaryFunction) {
if (protocols != null) {
- throw new ArgumentError("If protocols is non-null, onConnection must "
+ throw ArgumentError("If protocols is non-null, onConnection must "
"take two arguments, the WebSocket and the protocol.");
}
@@ -61,7 +55,10 @@
onConnection = (webSocket, _) => innerOnConnection(webSocket);
}
- return new WebSocketHandler(
- onConnection, protocols, allowedOrigins, pingInterval)
- .handle;
+ return WebSocketHandler(
+ onConnection,
+ protocols?.toSet(),
+ allowedOrigins?.map((origin) => origin.toLowerCase())?.toSet(),
+ pingInterval,
+ ).handle;
}
diff --git a/lib/src/web_socket_handler.dart b/lib/src/web_socket_handler.dart
index 90b66e0..8762f0a 100644
--- a/lib/src/web_socket_handler.dart
+++ b/lib/src/web_socket_handler.dart
@@ -54,7 +54,7 @@
if (key == null) return _badRequest('missing Sec-WebSocket-Key header.');
if (!request.canHijack) {
- throw new ArgumentError("webSocketHandler may only be used with a server "
+ throw ArgumentError("webSocketHandler may only be used with a server "
"that supports request hijacking.");
}
@@ -79,7 +79,7 @@
sink.add("\r\n");
_onConnection(
- new WebSocketChannel(channel, pingInterval: _pingInterval), protocol);
+ WebSocketChannel(channel, pingInterval: _pingInterval), protocol);
});
// [request.hijack] is guaranteed to throw a [HijackException], so we'll
@@ -124,7 +124,7 @@
Response _htmlResponse(int statusCode, String title, String message) {
title = htmlEscape.convert(title);
message = htmlEscape.convert(message);
- return new Response(statusCode, body: """
+ return Response(statusCode, body: """
<!doctype html>
<html>
<head><title>$title</title></head>
diff --git a/test/web_socket_test.dart b/test/web_socket_test.dart
index 43abce1..a640317 100644
--- a/test/web_socket_test.dart
+++ b/test/web_socket_test.dart
@@ -178,7 +178,7 @@
}
Matcher hasStatus(int status) => completion(predicate((response) {
- expect(response, new TypeMatcher<http.Response>());
+ expect(response, TypeMatcher<http.Response>());
expect(response.statusCode, equals(status));
return true;
}));