From 9f6ef59f329b69788a888eaf5f710b0b8b485469 Mon Sep 17 00:00:00 2001 From: Peter Giacomo Lombardo Date: Thu, 4 Apr 2024 12:20:58 +0200 Subject: [PATCH] Linter: Fix IDE0028 and others (#143) --- .editorconfig | 10 +--------- .../Client/Events/BeforeDisconnectEventArgs.cs | 1 - Source/HiveMQtt/Client/HiveMQClient.cs | 1 - .../Client/HiveMQClientOptionsBuilder.cs | 2 +- .../Client/HiveMQClientTrafficProcessor.cs | 16 +++++++--------- .../Client/LastWillAndTestamentBuilder.cs | 2 +- .../HiveMQtt/Client/Options/SubscribeOptions.cs | 2 +- Source/HiveMQtt/Client/internal/Validator.cs | 2 -- Source/HiveMQtt/MQTT5/ControlPacket.cs | 1 - Source/HiveMQtt/MQTT5/Packets/ConnectPacket.cs | 9 ++++++++- Source/HiveMQtt/MQTT5/Packets/PublishPacket.cs | 4 ++-- 11 files changed, 21 insertions(+), 29 deletions(-) diff --git a/.editorconfig b/.editorconfig index cade6374..1aa0f584 100644 --- a/.editorconfig +++ b/.editorconfig @@ -186,15 +186,7 @@ csharp_style_unused_value_expression_statement_preference = discard_variable:sug dotnet_diagnostic.IDE0058.severity = suggestion csharp_style_unused_value_assignment_preference = discard_variable:suggestion dotnet_diagnostic.IDE0059.severity = suggestion -dotnet_diagnostic.IDE0002.severity = none -dotnet_diagnostic.IDE0010.severity = none -dotnet_diagnostic.IDE0028.severity = none -dotnet_diagnostic.IDE0049.severity = none -dotnet_diagnostic.IDE0053.severity = none -dotnet_diagnostic.IDE0090.severity = none -dotnet_diagnostic.IDE0300.severity = none -dotnet_diagnostic.IDE0290.severity = none -dotnet_diagnostic.SA1508.severity = none +# dotnet_diagnostic.IDE0290.severity = none # FIXME: CLS Compliance dotnet_diagnostic.CS3001.severity = none diff --git a/Source/HiveMQtt/Client/Events/BeforeDisconnectEventArgs.cs b/Source/HiveMQtt/Client/Events/BeforeDisconnectEventArgs.cs index b43c637b..53fa3ec2 100644 --- a/Source/HiveMQtt/Client/Events/BeforeDisconnectEventArgs.cs +++ b/Source/HiveMQtt/Client/Events/BeforeDisconnectEventArgs.cs @@ -24,5 +24,4 @@ public class BeforeDisconnectEventArgs : EventArgs public BeforeDisconnectEventArgs() { } - } diff --git a/Source/HiveMQtt/Client/HiveMQClient.cs b/Source/HiveMQtt/Client/HiveMQClient.cs index dc72de5d..c8afdc4e 100644 --- a/Source/HiveMQtt/Client/HiveMQClient.cs +++ b/Source/HiveMQtt/Client/HiveMQClient.cs @@ -480,5 +480,4 @@ public async Task UnsubscribeAsync(UnsubscribeOptions unsubOp this.AfterUnsubscribeEventLauncher(unsubscribeResult); return unsubscribeResult; } - } diff --git a/Source/HiveMQtt/Client/HiveMQClientOptionsBuilder.cs b/Source/HiveMQtt/Client/HiveMQClientOptionsBuilder.cs index 597fee84..76731bf2 100644 --- a/Source/HiveMQtt/Client/HiveMQClientOptionsBuilder.cs +++ b/Source/HiveMQtt/Client/HiveMQClientOptionsBuilder.cs @@ -59,7 +59,7 @@ namespace HiveMQtt.Client; public class HiveMQClientOptionsBuilder { private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger(); - private readonly HiveMQClientOptions options = new HiveMQClientOptions(); + private readonly HiveMQClientOptions options = new(); /// /// Sets the address of the broker to connect to. diff --git a/Source/HiveMQtt/Client/HiveMQClientTrafficProcessor.cs b/Source/HiveMQtt/Client/HiveMQClientTrafficProcessor.cs index 2be66d5c..51bd6b87 100644 --- a/Source/HiveMQtt/Client/HiveMQClientTrafficProcessor.cs +++ b/Source/HiveMQtt/Client/HiveMQClientTrafficProcessor.cs @@ -37,7 +37,7 @@ public partial class HiveMQClient : IDisposable, IHiveMQClient // Transactional packets indexed by packet identifier private readonly ConcurrentDictionary> transactionQueue = new(); - private readonly Stopwatch lastCommunicationTimer = new Stopwatch(); + private readonly Stopwatch lastCommunicationTimer = new(); /// /// Asynchronous background task that monitors the connection state and sends PingReq packets when @@ -196,7 +196,6 @@ private Task ConnectionWriterAsync(CancellationToken cancellationToken) => default: Logger.Trace($"{this.Options.ClientId}-(W)- --> Unknown packet type {packet}"); break; - } // switch if (writeResult.IsCanceled) @@ -303,7 +302,6 @@ private Task ConnectionReaderAsync(CancellationToken cancellationToken) => Logger.Trace($"{this.Options.ClientId}-(R)- <-- Received {decodedPacket.GetType().Name}. Adding to receivedQueue."); this.ReceivedQueue.Add(decodedPacket); } // while (buffer.Length > 0 - } // while (this.ConnectState is ConnectState.Connecting or ConnectState.Connected) Logger.Trace($"{this.Options.ClientId}-(R)- ConnectionReader Exiting...{this.ConnectState}"); @@ -435,7 +433,6 @@ internal void HandleIncomingPubAckPacket(PubAckPacket pubAckPacket) { Logger.Warn($"QoS1: Received PubAck with an unknown packet identifier {pubAckPacket.PacketIdentifier}. Discarded."); } - } /// @@ -456,10 +453,12 @@ internal void HandleIncomingPubRecPacket(PubRecPacket pubRecPacket) var pubRelResponsePacket = new PubRelPacket(pubRecPacket.PacketIdentifier, PubRelReasonCode.Success); // Create an updated transaction chain - var newPublishQoS2Chain = new List(); - newPublishQoS2Chain.Add(originalPublishPacket); - newPublishQoS2Chain.Add(pubRecPacket); - newPublishQoS2Chain.Add(pubRelResponsePacket); + var newPublishQoS2Chain = new List + { + originalPublishPacket, + pubRecPacket, + pubRelResponsePacket, + }; // Update the chain in the queue if (this.transactionQueue.TryUpdate(pubRecPacket.PacketIdentifier, newPublishQoS2Chain, originalPublishQoS2Chain) == false) @@ -476,7 +475,6 @@ internal void HandleIncomingPubRecPacket(PubRecPacket pubRecPacket) var pubRelResponsePacket = new PubRelPacket(pubRecPacket.PacketIdentifier, PubRelReasonCode.PacketIdentifierNotFound); this.SendQueue.Add(pubRelResponsePacket); } - } /// diff --git a/Source/HiveMQtt/Client/LastWillAndTestamentBuilder.cs b/Source/HiveMQtt/Client/LastWillAndTestamentBuilder.cs index c537cffa..b299006f 100644 --- a/Source/HiveMQtt/Client/LastWillAndTestamentBuilder.cs +++ b/Source/HiveMQtt/Client/LastWillAndTestamentBuilder.cs @@ -22,7 +22,7 @@ namespace HiveMQtt.Client; public class LastWillAndTestamentBuilder { - private readonly Dictionary userProperties = new Dictionary(); + private readonly Dictionary userProperties = new(); private string? topic; private byte[]? payload; private QualityOfService qos = QualityOfService.AtMostOnceDelivery; diff --git a/Source/HiveMQtt/Client/Options/SubscribeOptions.cs b/Source/HiveMQtt/Client/Options/SubscribeOptions.cs index 2943e010..8d6c3d8b 100644 --- a/Source/HiveMQtt/Client/Options/SubscribeOptions.cs +++ b/Source/HiveMQtt/Client/Options/SubscribeOptions.cs @@ -50,7 +50,7 @@ public SubscribeOptions() /// List<TopicFilters>, the handler will not be registered for that subscription. /// /// - public Dictionary> Handlers { get; set; } = new Dictionary>(); + public Dictionary> Handlers { get; set; } = new(); /// /// Validate that the options in this instance are valid. diff --git a/Source/HiveMQtt/Client/internal/Validator.cs b/Source/HiveMQtt/Client/internal/Validator.cs index 84c3a535..ff3d5237 100644 --- a/Source/HiveMQtt/Client/internal/Validator.cs +++ b/Source/HiveMQtt/Client/internal/Validator.cs @@ -81,7 +81,6 @@ public static void ValidateTopicName(string topic) { throw new HiveMQttClientException("A topic name cannot contain any null characters."); } - } /// @@ -110,5 +109,4 @@ public static void ValidateTopicFilter(string topic) throw new HiveMQttClientException("A topic name cannot contain any null characters."); } } - } diff --git a/Source/HiveMQtt/MQTT5/ControlPacket.cs b/Source/HiveMQtt/MQTT5/ControlPacket.cs index 6809ffd5..8f6e2341 100644 --- a/Source/HiveMQtt/MQTT5/ControlPacket.cs +++ b/Source/HiveMQtt/MQTT5/ControlPacket.cs @@ -666,5 +666,4 @@ protected bool DecodeProperties(ref SequenceReader reader, int length) return true; } - } diff --git a/Source/HiveMQtt/MQTT5/Packets/ConnectPacket.cs b/Source/HiveMQtt/MQTT5/Packets/ConnectPacket.cs index b7c84af4..46387f5c 100644 --- a/Source/HiveMQtt/MQTT5/Packets/ConnectPacket.cs +++ b/Source/HiveMQtt/MQTT5/Packets/ConnectPacket.cs @@ -392,6 +392,14 @@ internal static int RangeValidate(int value, MQTT5DataType type) result = 268435455; } + break; + case MQTT5DataType.Byte: + break; + case MQTT5DataType.UTF8EncodedString: + break; + case MQTT5DataType.UTF8EncodedStringPair: + break; + case MQTT5DataType.BinaryData: break; default: result = value; @@ -400,5 +408,4 @@ internal static int RangeValidate(int value, MQTT5DataType type) return result; } - } diff --git a/Source/HiveMQtt/MQTT5/Packets/PublishPacket.cs b/Source/HiveMQtt/MQTT5/Packets/PublishPacket.cs index 2d22c4c9..246265b9 100644 --- a/Source/HiveMQtt/MQTT5/Packets/PublishPacket.cs +++ b/Source/HiveMQtt/MQTT5/Packets/PublishPacket.cs @@ -62,7 +62,7 @@ public PublishPacket(ReadOnlySequence packetData) /// /// Valid for outgoing Publish messages QoS 1. An event that is fired after the the QoS 1 publish transaction is complete. /// - public event EventHandler OnPublishQoS1Complete = new EventHandler((client, e) => { }); + public event EventHandler OnPublishQoS1Complete = new((client, e) => { }); internal virtual void OnPublishQoS1CompleteEventLauncher(PubAckPacket packet) { @@ -74,7 +74,7 @@ internal virtual void OnPublishQoS1CompleteEventLauncher(PubAckPacket packet) /// /// Valid for outgoing Publish messages QoS 2. An event that is fired after the the QoS 2 PubComp is received. /// - public event EventHandler OnPublishQoS2Complete = new EventHandler((client, e) => { }); + public event EventHandler OnPublishQoS2Complete = new((client, e) => { }); internal virtual void OnPublishQoS2CompleteEventLauncher(List packetList) {