Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahad-10 committed Mar 2, 2024
1 parent 3cc099e commit f9652b0
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 34 deletions.
9 changes: 3 additions & 6 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ linter:
- always_declare_return_types
- always_put_control_body_on_new_line
- always_put_required_named_parameters_first
- always_specify_types
- always_use_package_imports
- annotate_overrides
- annotate_redeclares
Expand Down Expand Up @@ -117,7 +116,7 @@ linter:
- null_check_on_nullable_type_parameter
- null_closures
- one_member_abstracts
- only_throw_errors
# - only_throw_errors
- overridden_fields
- package_api_docs
- package_names
Expand All @@ -132,14 +131,12 @@ linter:
- prefer_const_constructors_in_immutables
- prefer_const_declarations
- prefer_const_literals_to_create_immutables
- prefer_constructors_over_static_methods
- prefer_contains
- prefer_double_quotes
- prefer_expression_function_bodies
- prefer_final_fields
- prefer_final_in_for_each
- prefer_final_locals
- prefer_final_parameters
# - prefer_final_locals
# - prefer_final_parameters
- prefer_for_elements_to_map_fromIterable
- prefer_foreach
- prefer_function_declarations_over_variables
Expand Down
2 changes: 1 addition & 1 deletion lib/messages.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export 'src/messages/hello.dart' show Hello;
export "src/messages/hello.dart" show Hello;
2 changes: 1 addition & 1 deletion lib/serializers.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export 'src/serializers/json.dart' show JsonSerializer;
export "src/serializers/json.dart" show JsonSerializer;
14 changes: 6 additions & 8 deletions lib/src/messages/hello.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'message.dart';
import "package:wampproto/src/messages/message.dart";

class Hello implements Message {

Hello(this.realm, this.roles, this.authID, this.authMethods);
static const int id = 1;

final String realm;
final Map<String, Map<String, bool>> roles;
final String authID;
final List<String> authMethods;

Hello(this.realm, this.roles, this.authID, this.authMethods);

static Hello parse(List<dynamic> message) {
static Hello parse(final List<dynamic> message) {
if (message.length < 2) {
throw ArgumentError("invalid hello message");
}
Expand All @@ -22,7 +22,7 @@ class Hello implements Message {

if (type != Hello.id) {
throw ArgumentError(
"invalid message type: must be ${Hello.id}, was $type");
"invalid message type: must be ${Hello.id}, was $type",);
}

final realm = message[1];
Expand All @@ -44,7 +44,5 @@ class Hello implements Message {
}

@override
int messageType() {
return id;
}
int messageType() => id;
}
16 changes: 8 additions & 8 deletions lib/src/serializers/json.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import 'dart:convert';
import 'dart:typed_data';
import "dart:convert";
import "dart:typed_data";

import 'package:wampproto/src/messages/message.dart';
import 'package:wampproto/src/serializers/serializer.dart';
import "package:wampproto/src/messages/message.dart";
import "package:wampproto/src/serializers/serializer.dart";

class JsonSerializer implements Serializer {
@override
Uint8List serialize(Message message) {
Uint8List serialize(final Message message) {
var jsonString = jsonEncode(message.marshal());
return Uint8List.fromList(jsonString.codeUnits);
}

@override
Message deserialize(Uint8List message) {
String s = String.fromCharCodes(message);
Message deserialize(final Uint8List message) {
final String s = String.fromCharCodes(message);

List<dynamic> wampMessage = jsonDecode(s);
final List<dynamic> wampMessage = jsonDecode(s);
return toMessage(wampMessage);
}
}
10 changes: 5 additions & 5 deletions lib/src/serializers/serializer.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:typed_data';
import "dart:typed_data";

import 'package:wampproto/messages.dart';
import "package:wampproto/messages.dart";

import '../messages/message.dart';
import "package:wampproto/src/messages/message.dart";

Message toMessage(List<dynamic> message) {
var messageType = message[0];
Expand All @@ -21,6 +21,6 @@ Message toMessage(List<dynamic> message) {
}

abstract class Serializer {
Message deserialize(Uint8List message);
Uint8List serialize(Message message);
Message deserialize(final Uint8List message);
Uint8List serialize(final Message message);
}
4 changes: 2 additions & 2 deletions test/messages/hello_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:wampproto/messages.dart';
import 'package:test/test.dart';
import "package:test/test.dart";
import "package:wampproto/messages.dart";

void main() {
test("test parse", testParse);
Expand Down
6 changes: 3 additions & 3 deletions test/serializers/json_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:wampproto/messages.dart';
import 'package:wampproto/serializers.dart';
import 'package:test/test.dart';
import "package:test/test.dart";
import "package:wampproto/messages.dart";
import "package:wampproto/serializers.dart";

void main() {
test("test serialize and deserialize", testJson);
Expand Down

0 comments on commit f9652b0

Please sign in to comment.