Skip to content

Commit

Permalink
Linter: Fix IDE0028 and others (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
pglombardo authored Apr 4, 2024
1 parent b5dd50e commit 9f6ef59
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 29 deletions.
10 changes: 1 addition & 9 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Source/HiveMQtt/Client/Events/BeforeDisconnectEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ public class BeforeDisconnectEventArgs : EventArgs
public BeforeDisconnectEventArgs()
{
}

}
1 change: 0 additions & 1 deletion Source/HiveMQtt/Client/HiveMQClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,5 +480,4 @@ public async Task<UnsubscribeResult> UnsubscribeAsync(UnsubscribeOptions unsubOp
this.AfterUnsubscribeEventLauncher(unsubscribeResult);
return unsubscribeResult;
}

}
2 changes: 1 addition & 1 deletion Source/HiveMQtt/Client/HiveMQClientOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/// <summary>
/// Sets the address of the broker to connect to.
Expand Down
16 changes: 7 additions & 9 deletions Source/HiveMQtt/Client/HiveMQClientTrafficProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public partial class HiveMQClient : IDisposable, IHiveMQClient
// Transactional packets indexed by packet identifier
private readonly ConcurrentDictionary<int, List<ControlPacket>> transactionQueue = new();

private readonly Stopwatch lastCommunicationTimer = new Stopwatch();
private readonly Stopwatch lastCommunicationTimer = new();

/// <summary>
/// Asynchronous background task that monitors the connection state and sends PingReq packets when
Expand Down Expand Up @@ -196,7 +196,6 @@ private Task<bool> ConnectionWriterAsync(CancellationToken cancellationToken) =>
default:
Logger.Trace($"{this.Options.ClientId}-(W)- --> Unknown packet type {packet}");
break;

} // switch

if (writeResult.IsCanceled)
Expand Down Expand Up @@ -303,7 +302,6 @@ private Task<bool> 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}");
Expand Down Expand Up @@ -435,7 +433,6 @@ internal void HandleIncomingPubAckPacket(PubAckPacket pubAckPacket)
{
Logger.Warn($"QoS1: Received PubAck with an unknown packet identifier {pubAckPacket.PacketIdentifier}. Discarded.");
}

}

/// <summary>
Expand All @@ -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<ControlPacket>();
newPublishQoS2Chain.Add(originalPublishPacket);
newPublishQoS2Chain.Add(pubRecPacket);
newPublishQoS2Chain.Add(pubRelResponsePacket);
var newPublishQoS2Chain = new List<ControlPacket>
{
originalPublishPacket,
pubRecPacket,
pubRelResponsePacket,
};

// Update the chain in the queue
if (this.transactionQueue.TryUpdate(pubRecPacket.PacketIdentifier, newPublishQoS2Chain, originalPublishQoS2Chain) == false)
Expand All @@ -476,7 +475,6 @@ internal void HandleIncomingPubRecPacket(PubRecPacket pubRecPacket)
var pubRelResponsePacket = new PubRelPacket(pubRecPacket.PacketIdentifier, PubRelReasonCode.PacketIdentifierNotFound);
this.SendQueue.Add(pubRelResponsePacket);
}

}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/HiveMQtt/Client/LastWillAndTestamentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace HiveMQtt.Client;

public class LastWillAndTestamentBuilder
{
private readonly Dictionary<string, string> userProperties = new Dictionary<string, string>();
private readonly Dictionary<string, string> userProperties = new();

Check warning on line 25 in Source/HiveMQtt/Client/LastWillAndTestamentBuilder.cs

View workflow job for this annotation

GitHub Actions / pipeline-ubuntu-latest-dotnet-6.0.x

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

Check warning on line 25 in Source/HiveMQtt/Client/LastWillAndTestamentBuilder.cs

View workflow job for this annotation

GitHub Actions / pipeline-ubuntu-latest-dotnet-7.0.x

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

Check warning on line 25 in Source/HiveMQtt/Client/LastWillAndTestamentBuilder.cs

View workflow job for this annotation

GitHub Actions / pipeline-ubuntu-latest-dotnet-8.0.x

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)
private string? topic;
private byte[]? payload;
private QualityOfService qos = QualityOfService.AtMostOnceDelivery;
Expand Down
2 changes: 1 addition & 1 deletion Source/HiveMQtt/Client/Options/SubscribeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public SubscribeOptions()
/// <c>List&lt;TopicFilters&gt;</c>, the handler will not be registered for that subscription.
/// </para>
/// </summary>
public Dictionary<string, EventHandler<OnMessageReceivedEventArgs>> Handlers { get; set; } = new Dictionary<string, EventHandler<OnMessageReceivedEventArgs>>();
public Dictionary<string, EventHandler<OnMessageReceivedEventArgs>> Handlers { get; set; } = new();

Check warning on line 53 in Source/HiveMQtt/Client/Options/SubscribeOptions.cs

View workflow job for this annotation

GitHub Actions / pipeline-ubuntu-latest-dotnet-6.0.x

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

Check warning on line 53 in Source/HiveMQtt/Client/Options/SubscribeOptions.cs

View workflow job for this annotation

GitHub Actions / pipeline-ubuntu-latest-dotnet-7.0.x

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

Check warning on line 53 in Source/HiveMQtt/Client/Options/SubscribeOptions.cs

View workflow job for this annotation

GitHub Actions / pipeline-ubuntu-latest-dotnet-8.0.x

Collection initialization can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028)

/// <summary>
/// Validate that the options in this instance are valid.
Expand Down
2 changes: 0 additions & 2 deletions Source/HiveMQtt/Client/internal/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public static void ValidateTopicName(string topic)
{
throw new HiveMQttClientException("A topic name cannot contain any null characters.");
}

}

/// <summary>
Expand Down Expand Up @@ -110,5 +109,4 @@ public static void ValidateTopicFilter(string topic)
throw new HiveMQttClientException("A topic name cannot contain any null characters.");
}
}

}
1 change: 0 additions & 1 deletion Source/HiveMQtt/MQTT5/ControlPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,5 +666,4 @@ protected bool DecodeProperties(ref SequenceReader<byte> reader, int length)

return true;
}

}
9 changes: 8 additions & 1 deletion Source/HiveMQtt/MQTT5/Packets/ConnectPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -400,5 +408,4 @@ internal static int RangeValidate(int value, MQTT5DataType type)

return result;
}

}
4 changes: 2 additions & 2 deletions Source/HiveMQtt/MQTT5/Packets/PublishPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public PublishPacket(ReadOnlySequence<byte> packetData)
/// <summary>
/// Valid for outgoing Publish messages QoS 1. An event that is fired after the the QoS 1 publish transaction is complete.
/// </summary>
public event EventHandler<OnPublishQoS1CompleteEventArgs> OnPublishQoS1Complete = new EventHandler<OnPublishQoS1CompleteEventArgs>((client, e) => { });
public event EventHandler<OnPublishQoS1CompleteEventArgs> OnPublishQoS1Complete = new((client, e) => { });

internal virtual void OnPublishQoS1CompleteEventLauncher(PubAckPacket packet)
{
Expand All @@ -74,7 +74,7 @@ internal virtual void OnPublishQoS1CompleteEventLauncher(PubAckPacket packet)
/// <summary>
/// Valid for outgoing Publish messages QoS 2. An event that is fired after the the QoS 2 PubComp is received.
/// </summary>
public event EventHandler<OnPublishQoS2CompleteEventArgs> OnPublishQoS2Complete = new EventHandler<OnPublishQoS2CompleteEventArgs>((client, e) => { });
public event EventHandler<OnPublishQoS2CompleteEventArgs> OnPublishQoS2Complete = new((client, e) => { });

internal virtual void OnPublishQoS2CompleteEventLauncher(List<ControlPacket> packetList)
{
Expand Down

0 comments on commit 9f6ef59

Please sign in to comment.