diff --git a/lib/src/dbus_address.dart b/lib/src/dbus_address.dart index ce3001f..08efdc5 100644 --- a/lib/src/dbus_address.dart +++ b/lib/src/dbus_address.dart @@ -14,10 +14,10 @@ class DBusAddress { /// Gets this address in string format. String get value { - return '$transport:' + - properties.keys - .map((key) => '$key=${_encodeValue(properties[key]!)}') - .join(','); + var propertyString = properties.keys + .map((key) => '$key=${_encodeValue(properties[key]!)}') + .join(','); + return '$transport:$propertyString'; } /// Creates a new address from the given [address] string, e.g. 'unix:path=/run/user/1000/bus'. @@ -149,7 +149,7 @@ class DBusAddress { { escapedValue += utf8.decode([byte]); } else { - escapedValue += '%' + byte.toRadixString(16).padLeft(2, '0'); + escapedValue += '%${byte.toRadixString(16).padLeft(2, '0')}'; } } return escapedValue; diff --git a/lib/src/dbus_client.dart b/lib/src/dbus_client.dart index c2aec79..7889f96 100644 --- a/lib/src/dbus_client.dart +++ b/lib/src/dbus_client.dart @@ -75,12 +75,11 @@ class DBusProcessCredentials { 'otherCredentials': otherCredentials.isNotEmpty ? otherCredentials.toString() : null }; - return 'DBusProcessCredentials(' + - parameters.keys - .where((key) => parameters[key] != null) - .map((key) => '$key=${parameters[key]}') - .join(', ') + - ')'; + var parameterString = parameters.keys + .where((key) => parameters[key] != null) + .map((key) => '$key=${parameters[key]}') + .join(', '); + return 'DBusProcessCredentials($parameterString)'; } } @@ -787,7 +786,7 @@ class DBusClient { await _openSocket(); _authClient.requests - .listen((message) => _socket?.write(utf8.encode(message + '\r\n'))); + .listen((message) => _socket?.write(utf8.encode('$message\r\n'))); await _authClient.done; _authComplete = true; if (!_authClient.isAuthenticated) { diff --git a/lib/src/dbus_code_generator.dart b/lib/src/dbus_code_generator.dart index 9066dcc..21ef59b 100644 --- a/lib/src/dbus_code_generator.dart +++ b/lib/src/dbus_code_generator.dart @@ -24,11 +24,11 @@ class DBusCodeGenerator { /// If provided [comment] is added to the top of the source. DBusCodeGenerator(this.node, {String? comment, String? className}) : _comment = comment { - var _className = className ?? _nodeToClassName(); - if (_className == null) { + var className_ = className ?? _nodeToClassName(); + if (className_ == null) { throw 'Unable to determine class name'; } - this.className = _className; + this.className = className_; } /// Generates Dart code for a client to access the given D-Bus interface. @@ -60,7 +60,8 @@ class DBusCodeGenerator { var source = ''; if (_comment != null) { - source += '// ' + _comment!.split('\n').join('\n// ') + '\n\n'; + var escapedComment = _comment!.split('\n').join('\n// '); + source += '// $escapedComment\n\n'; } return source; diff --git a/lib/src/dbus_introspect.dart b/lib/src/dbus_introspect.dart index 50b4b49..7d3714e 100644 --- a/lib/src/dbus_introspect.dart +++ b/lib/src/dbus_introspect.dart @@ -67,12 +67,11 @@ class DBusIntrospectNode { 'interfaces': interfaces.isNotEmpty ? interfaces.toString() : null, 'children': children.isNotEmpty ? children.toString() : null }; - return 'DBusIntrospectNode(' + - parameters.keys - .where((key) => parameters[key] != null) - .map((key) => '$key: ${parameters[key]}') - .join(', ') + - ')'; + var parameterString = parameters.keys + .where((key) => parameters[key] != null) + .map((key) => '$key: ${parameters[key]}') + .join(', '); + return 'DBusIntrospectNode($parameterString)'; } @override @@ -154,13 +153,12 @@ class DBusIntrospectInterface { 'signals': signals.isNotEmpty ? signals.toString() : null, 'properties': properties.isNotEmpty ? properties.toString() : null }; - return 'DBusIntrospectInterface(' + - ["'$name'"] - .followedBy(parameters.keys - .where((key) => parameters[key] != null) - .map((key) => '$key: ${parameters[key]}')) - .join(', ') + - ')'; + var parameterString = ["'$name'"] + .followedBy(parameters.keys + .where((key) => parameters[key] != null) + .map((key) => '$key: ${parameters[key]}')) + .join(', '); + return 'DBusIntrospectInterface($parameterString)'; } @override @@ -234,13 +232,12 @@ class DBusIntrospectMethod { 'args': args.isNotEmpty ? args.toString() : null, 'annotations': annotations.isNotEmpty ? annotations.toString() : null }; - return 'DBusIntrospectMethod(' + - ["'$name'"] - .followedBy(parameters.keys - .where((key) => parameters[key] != null) - .map((key) => '$key: ${parameters[key]}')) - .join(', ') + - ')'; + var parameterString = ["'$name'"] + .followedBy(parameters.keys + .where((key) => parameters[key] != null) + .map((key) => '$key: ${parameters[key]}')) + .join(', '); + return 'DBusIntrospectMethod($parameterString)'; } @override @@ -303,13 +300,12 @@ class DBusIntrospectSignal { 'args': args.isNotEmpty ? args.toString() : null, 'annotations': annotations.isNotEmpty ? annotations.toString() : null }; - return 'DBusIntrospectSignal(' + - ["'$name'"] - .followedBy(parameters.keys - .where((key) => parameters[key] != null) - .map((key) => '$key: ${parameters[key]}')) - .join(', ') + - ')'; + var parameterString = ["'$name'"] + .followedBy(parameters.keys + .where((key) => parameters[key] != null) + .map((key) => '$key: ${parameters[key]}')) + .join(', '); + return 'DBusIntrospectSignal($parameterString)'; } @override @@ -391,13 +387,12 @@ class DBusIntrospectProperty { access != DBusPropertyAccess.readwrite ? access.toString() : null, 'annotations': annotations.isNotEmpty ? annotations.toString() : null }; - return 'DBusIntrospectProperty(' + - ["'$name'", type.toString()] - .followedBy(parameters.keys - .where((key) => parameters[key] != null) - .map((key) => '$key: ${parameters[key]}')) - .join(', ') + - ')'; + var parameterString = ["'$name'", type.toString()] + .followedBy(parameters.keys + .where((key) => parameters[key] != null) + .map((key) => '$key: ${parameters[key]}')) + .join(', '); + return 'DBusIntrospectProperty($parameterString)'; } @override @@ -477,13 +472,12 @@ class DBusIntrospectArgument { 'name': name != null ? "'$name'" : null, 'annotations': annotations.isNotEmpty ? annotations.toString() : null }; - return 'DBusIntrospectArgument(' + - [type.toString(), direction.toString()] - .followedBy(parameters.keys - .where((key) => parameters[key] != null) - .map((key) => '$key: ${parameters[key]}')) - .join(', ') + - ')'; + var parameterString = [type.toString(), direction.toString()] + .followedBy(parameters.keys + .where((key) => parameters[key] != null) + .map((key) => '$key: ${parameters[key]}')) + .join(', '); + return 'DBusIntrospectArgument($parameterString)'; } @override diff --git a/lib/src/dbus_match_rule.dart b/lib/src/dbus_match_rule.dart index 226f67c..88789a5 100644 --- a/lib/src/dbus_match_rule.dart +++ b/lib/src/dbus_match_rule.dart @@ -162,7 +162,8 @@ class DBusMatchRule { /// Escapes a string value. String _escapeString(String value) { // Replace quotes with: End quotes, escaped quote, start quotes again. - return "'" + value.replaceAll("'", "'\\''") + "'"; + var escapedValue = value.replaceAll("'", "'\\''"); + return "'$escapedValue'"; } /// True if the rule matches the supplied values. @@ -220,11 +221,10 @@ class DBusMatchRule { 'path': path?.toString(), 'pathNamespace': pathNamespace?.toString() }; - return 'DBusMatchRule(' + - parameters.keys - .where((key) => parameters[key] != null) - .map((key) => '$key=${parameters[key]}') - .join(', ') + - ')'; + var parameterString = parameters.keys + .where((key) => parameters[key] != null) + .map((key) => '$key=${parameters[key]}') + .join(', '); + return 'DBusMatchRule($parameterString)'; } } diff --git a/lib/src/dbus_message.dart b/lib/src/dbus_message.dart index 92cb384..8461e87 100644 --- a/lib/src/dbus_message.dart +++ b/lib/src/dbus_message.dart @@ -81,11 +81,10 @@ class DBusMessage { 'sender': sender?.toString(), 'values': values.isNotEmpty ? values.toString() : null }; - return 'DBusMessage(' + - parameters.keys - .where((key) => parameters[key] != null) - .map((key) => '$key: ${parameters[key]}') - .join(', ') + - ')'; + var parameterString = parameters.keys + .where((key) => parameters[key] != null) + .map((key) => '$key: ${parameters[key]}') + .join(', '); + return 'DBusMessage($parameterString)'; } } diff --git a/lib/src/dbus_method_call.dart b/lib/src/dbus_method_call.dart index 04958ca..e958e81 100644 --- a/lib/src/dbus_method_call.dart +++ b/lib/src/dbus_method_call.dart @@ -49,11 +49,10 @@ class DBusMethodCall { 'allowInteractiveAuthorization': allowInteractiveAuthorization ? 'true' : null }; - return 'DBusMethodCall(' + - parameters.keys - .where((key) => parameters[key] != null) - .map((key) => '$key: ${parameters[key]}') - .join(', ') + - ')'; + var parameterString = parameters.keys + .where((key) => parameters[key] != null) + .map((key) => '$key: ${parameters[key]}') + .join(', '); + return 'DBusMethodCall($parameterString)'; } } diff --git a/lib/src/dbus_read_buffer.dart b/lib/src/dbus_read_buffer.dart index d4d290e..d498b2c 100644 --- a/lib/src/dbus_read_buffer.dart +++ b/lib/src/dbus_read_buffer.dart @@ -567,7 +567,7 @@ class DBusReadBuffer extends DBusBuffer { if (d >= 33 && d <= 126) { s += String.fromCharCode(d); } else { - s += '\\' + d.toRadixString(8); + s += '\\${d.toRadixString(8)}'; } } return "DBusReadBuffer('$s')"; diff --git a/lib/src/dbus_server.dart b/lib/src/dbus_server.dart index 67dd0cb..c9fb582 100644 --- a/lib/src/dbus_server.dart +++ b/lib/src/dbus_server.dart @@ -77,7 +77,7 @@ class _DBusRemoteClient { _DBusRemoteClient(this.serverSocket, this._socket, this.uniqueName) : _authServer = DBusAuthServer(serverSocket.uuid, unixFdSupported: true) { _authServer.responses - .listen((message) => _socket.write(utf8.encode(message + '\r\n'))); + .listen((message) => _socket.write(utf8.encode('$message\r\n'))); _socket.listen((event) { if (event == RawSocketEvent.read) { _readData(); diff --git a/lib/src/dbus_value.dart b/lib/src/dbus_value.dart index 6175529f..4dc7845 100644 --- a/lib/src/dbus_value.dart +++ b/lib/src/dbus_value.dart @@ -373,7 +373,7 @@ class DBusObjectPath extends DBusString { bool isInNamespace(DBusObjectPath namespace) { return namespace.value == '/' || value == namespace.value || - value.startsWith(namespace.value + '/'); + value.startsWith('${namespace.value}/'); } @override @@ -685,7 +685,7 @@ class DBusMaybe extends DBusValue { @override DBusSignature get signature { - return DBusSignature('m' + valueSignature.value); + return DBusSignature('m${valueSignature.value}'); } @override @@ -750,7 +750,7 @@ class DBusStruct extends DBusValue { for (var child in children) { signature += child.signature.value; } - return DBusSignature('(' + signature + ')'); + return DBusSignature('($signature)'); } @override @@ -883,7 +883,7 @@ class DBusArray extends DBusValue { @override DBusSignature get signature { - return DBusSignature('a' + childSignature.value); + return DBusSignature('a${childSignature.value}'); } @override @@ -951,59 +951,56 @@ class DBusArray extends DBusValue { String toString() { switch (childSignature.value) { case 'y': - return 'DBusArray.byte([' + - children.map((child) => (child as DBusByte).value).join(', ') + - '])'; + var values = + children.map((child) => (child as DBusByte).value).join(', '); + return 'DBusArray.byte([$values])'; case 'n': - return 'DBusArray.int16([' + - children.map((child) => (child as DBusInt16).value).join(', ') + - '])'; + var values = + children.map((child) => (child as DBusInt16).value).join(', '); + return 'DBusArray.int16([$values])'; case 'q': - return 'DBusArray.uint16([' + - children.map((child) => (child as DBusUint16).value).join(', ') + - '])'; + var values = + children.map((child) => (child as DBusUint16).value).join(', '); + return 'DBusArray.uint16([$values])'; case 'i': - return 'DBusArray.int32([' + - children.map((child) => (child as DBusInt32).value).join(', ') + - '])'; + var values = + children.map((child) => (child as DBusInt32).value).join(', '); + return 'DBusArray.int32([$values])'; case 'u': - return 'DBusArray.uint32([' + - children.map((child) => (child as DBusUint32).value).join(', ') + - '])'; + var values = + children.map((child) => (child as DBusUint32).value).join(', '); + return 'DBusArray.uint32([$values])'; case 'x': - return 'DBusArray.int64([' + - children.map((child) => (child as DBusInt64).value).join(', ') + - '])'; + var values = + children.map((child) => (child as DBusInt64).value).join(', '); + return 'DBusArray.int64([$values])'; case 't': - return 'DBusArray.uint64([' + - children.map((child) => (child as DBusUint64).value).join(', ') + - '])'; + var values = + children.map((child) => (child as DBusUint64).value).join(', '); + return 'DBusArray.uint64([$values])'; case 'd': - return 'DBusArray.double([' + - children.map((child) => (child as DBusDouble).value).join(', ') + - '])'; + var values = + children.map((child) => (child as DBusDouble).value).join(', '); + return 'DBusArray.double([$values])'; case 's': - return 'DBusArray.string([' + - children - .map((child) => "'" + (child as DBusString).value + "'") - .join(', ') + - '])'; + var values = children + .map((child) => "'${(child as DBusString).value}'") + .join(', '); + return 'DBusArray.string([$values])'; case 'o': - return 'DBusArray.objectPath([' + - children - .map((child) => (child as DBusObjectPath).toString()) - .join(', ') + - '])'; + var values = children + .map((child) => (child as DBusObjectPath).toString()) + .join(', '); + return 'DBusArray.objectPath([$values])'; case 'g': - return 'DBusArray.signature([' + - children - .map((child) => (child as DBusSignature).toString()) - .join(', ') + - '])'; + var values = children + .map((child) => (child as DBusSignature).toString()) + .join(', '); + return 'DBusArray.signature([$values])'; case 'v': - return 'DBusArray.variant([' + - children.map((child) => (child as DBusVariant).value).join(', ') + - '])'; + var values = + children.map((child) => (child as DBusVariant).value).join(', '); + return 'DBusArray.variant([$values])'; default: var childrenText = []; for (var child in children) { @@ -1098,23 +1095,20 @@ class DBusDict extends DBusValue { @override String toString() { if (keySignature.value == 's' && valueSignature.value == 'v') { - return 'DBusDict.stringVariant({' + - children.entries - .map((entry) => - "'${(entry.key as DBusString).value}': ${(entry.value as DBusVariant).value.toString()}") - .join(', ') + - '})'; + var values = children.entries + .map((entry) => + "'${(entry.key as DBusString).value}': ${(entry.value as DBusVariant).value.toString()}") + .join(', '); + return 'DBusDict.stringVariant({$values})'; } else { var childrenText = []; children.forEach((key, value) { childrenText.add('${key.toString()}: ${value.toString()}'); }); - return 'DBusDict($keySignature, $valueSignature, {' + - children.entries - .map((entry) => - '${entry.key.toString()}: ${entry.value.toString()}') - .join(', ') + - '})'; + var values = children.entries + .map((entry) => '${entry.key.toString()}: ${entry.value.toString()}') + .join(', '); + return 'DBusDict($keySignature, $valueSignature, {$values})'; } } } diff --git a/pubspec.yaml b/pubspec.yaml index a693b6b..25f01eb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,7 +21,7 @@ dependencies: xml: ^6.1.0 dev_dependencies: - lints: ^1.0.1 + lints: ^2.0.0 test: ^1.16.8 test_cov: ^1.0.1 diff --git a/test/dbus_test.dart b/test/dbus_test.dart index aec861e..7e2d45d 100644 --- a/test/dbus_test.dart +++ b/test/dbus_test.dart @@ -1044,10 +1044,10 @@ void main() { expect(() => DBusBusName(''), throwsFormatException); expect(() => DBusBusName('com'), throwsFormatException); expect(DBusBusName('com.example').value, equals('com.example')); - expect(DBusBusName('com.example.' + 'X' * 243).value, - equals('com.example.' + 'X' * 243)); + expect(DBusBusName('com.example.${'X' * 243}').value, + equals('com.example.${'X' * 243}')); expect( - () => DBusBusName('com.example.' + 'X' * 244), throwsFormatException); + () => DBusBusName('com.example.${'X' * 244}'), throwsFormatException); expect(() => DBusBusName('com.example.Test~1'), throwsFormatException); expect(DBusBusName('com.example.Test') == DBusBusName('com.example.Test'), isTrue); @@ -1063,9 +1063,9 @@ void main() { expect(() => DBusInterfaceName(''), throwsFormatException); expect(() => DBusInterfaceName('com'), throwsFormatException); expect(DBusInterfaceName('com.example').value, equals('com.example')); - expect(DBusInterfaceName('com.example.' + 'X' * 243).value, - equals('com.example.' + 'X' * 243)); - expect(() => DBusInterfaceName('com.example.' + 'X' * 244), + expect(DBusInterfaceName('com.example.${'X' * 243}').value, + equals('com.example.${'X' * 243}')); + expect(() => DBusInterfaceName('com.example.${'X' * 244}'), throwsFormatException); expect( () => DBusInterfaceName('com.example.Test~1'), throwsFormatException); @@ -1087,10 +1087,10 @@ void main() { expect(() => DBusErrorName(''), throwsFormatException); expect(() => DBusErrorName('com'), throwsFormatException); expect(DBusErrorName('com.example').value, equals('com.example')); - expect(DBusErrorName('com.example.' + 'X' * 243).value, - equals('com.example.' + 'X' * 243)); + expect(DBusErrorName('com.example.${'X' * 243}').value, + equals('com.example.${'X' * 243}')); expect( - () => DBusErrorName('com.example.' + 'X' * 244), throwsFormatException); + () => DBusErrorName('com.example.${'X' * 244}'), throwsFormatException); expect(() => DBusErrorName('com.example.Test~1'), throwsFormatException); expect( DBusErrorName('com.example.Test') == DBusErrorName('com.example.Test'),