From 3d34f90e1d440c052df186727ad5d747cc9e578f Mon Sep 17 00:00:00 2001 From: Victor Uvarov Date: Fri, 27 Dec 2024 12:41:11 -0800 Subject: [PATCH] Fix/prefer is empty lint (#510) * make sure the session terminates * fix prefer_is_empty lint rule warnings --------- Co-authored-by: Victor Uvarov --- analysis_options.yaml | 1 - lib/src/config.dart | 2 +- lib/src/name_addr_header.dart | 2 +- lib/src/rtc_session/dtmf.dart | 2 +- lib/src/socket_transport.dart | 2 +- lib/src/transports/tcp_socket.dart | 2 +- lib/src/transports/web_socket.dart | 2 +- lib/src/uri.dart | 2 +- 8 files changed, 7 insertions(+), 8 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 9b708ede..93b8d111 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -45,7 +45,6 @@ analyzer: library_prefixes: ignore unused_field: ignore avoid_init_to_null: ignore - prefer_is_empty: ignore unused_element: ignore curly_braces_in_flow_control_structures: ignore unnecessary_null_in_if_null_operators: ignore diff --git a/lib/src/config.dart b/lib/src/config.dart index 102e7ef5..5caa5dd3 100644 --- a/lib/src/config.dart +++ b/lib/src/config.dart @@ -85,7 +85,7 @@ class Checks { * List of Objects and Socket: [{socket: socket1}, socket2] */ List copy = []; - if (sockets is List && sockets!.length > 0) { + if (sockets is List && sockets!.isNotEmpty) { for (SIPUASocketInterface socket in sockets) { copy.add(socket); } diff --git a/lib/src/name_addr_header.dart b/lib/src/name_addr_header.dart index a2924071..8e934490 100644 --- a/lib/src/name_addr_header.dart +++ b/lib/src/name_addr_header.dart @@ -89,7 +89,7 @@ class NameAddrHeader { @override String toString() { - String body = (_display_name != null && _display_name!.length > 0) + String body = (_display_name != null && _display_name!.isNotEmpty) ? '"${_quote(_display_name!)}" ' : ''; diff --git a/lib/src/rtc_session/dtmf.dart b/lib/src/rtc_session/dtmf.dart index 15f8de1a..60179beb 100644 --- a/lib/src/rtc_session/dtmf.dart +++ b/lib/src/rtc_session/dtmf.dart @@ -120,7 +120,7 @@ class DTMF extends EventManager { if (request.body != null) { List body = request.body!.split('\n'); - if (body.length >= 1) { + if (body.isNotEmpty) { if (body[0].contains(RegExp(reg_tone))) { _tone = body[0].replaceAll(reg_tone, '\$2'); } diff --git a/lib/src/socket_transport.dart b/lib/src/socket_transport.dart index 71a2f0b4..ea82046d 100644 --- a/lib/src/socket_transport.dart +++ b/lib/src/socket_transport.dart @@ -46,7 +46,7 @@ class SocketTransport { _recovery_options = recovery_options; // We must recieve at least 1 socket - if (sockets!.length == 0) { + if (sockets!.isEmpty) { throw Exceptions.TypeError( 'invalid argument: Must recieve atleast 1 web socket'); } diff --git a/lib/src/transports/tcp_socket.dart b/lib/src/transports/tcp_socket.dart index ce3832c7..59f67217 100644 --- a/lib/src/transports/tcp_socket.dart +++ b/lib/src/transports/tcp_socket.dart @@ -166,7 +166,7 @@ class SIPUATcpSocket extends SIPUASocketInterface { void _onMessage(dynamic data) { logger.d('Received TcpSocket data'); if (data != null) { - if (data.toString().trim().length > 0) { + if (data.toString().trim().isNotEmpty) { ondata!(data); } else { logger.d('Received and ignored empty packet'); diff --git a/lib/src/transports/web_socket.dart b/lib/src/transports/web_socket.dart index 57d610c8..9a7302bf 100644 --- a/lib/src/transports/web_socket.dart +++ b/lib/src/transports/web_socket.dart @@ -175,7 +175,7 @@ class SIPUAWebSocket extends SIPUASocketInterface { void _onMessage(dynamic data) { logger.d('Received WebSocket message'); if (data != null) { - if (data.toString().trim().length > 0) { + if (data.toString().trim().isNotEmpty) { ondata!(data); } else { logger.d('Received and ignored empty packet'); diff --git a/lib/src/uri.dart b/lib/src/uri.dart index 7996516f..66d30b93 100644 --- a/lib/src/uri.dart +++ b/lib/src/uri.dart @@ -181,7 +181,7 @@ class URI { }); }); - if (headers.length > 0) { + if (headers.isNotEmpty) { uri += '?${headers.join('&')}'; }