Skip to content

Cleanup formatting and style and enforce it in CI #1380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 17, 2024
  •  
  •  
  •  
25 changes: 12 additions & 13 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ dotnet_diagnostic.S1125.severity = none
# This is a duplicate of MA0026.
dotnet_diagnostic.S1135.severity = none


# SA1137: Elements should have the same indentation
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1137.md
# duplicate of IDE0055
dotnet_diagnostic.SA1137.severity = none

# S1168: Empty arrays and collections should be returned instead of null
# https://rules.sonarsource.com/csharp/RSPEC-1168
#
Expand Down Expand Up @@ -339,6 +345,11 @@ dotnet_diagnostic.SA1008.severity = none
# var x = (int) z;
dotnet_diagnostic.SA1009.severity = none

# SA1025: Code should not contain multiple whitespace in a row
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1025.md
# duplicate of IDE0055
dotnet_diagnostic.SA1025.severity = none

# SA1101: Prefix local calls with this
dotnet_diagnostic.SA1101.severity = none

Expand Down Expand Up @@ -743,18 +754,6 @@ dotnet_diagnostic.IDE0046.severity = suggestion
# Removing "unnecessary" parentheses is not always a clear win for readability.
dotnet_diagnostic.IDE0047.severity = suggestion

# IDE0055: Fix formatting
#
# When enabled, diagnostics are reported for indented object initializers.
# For example:
# _content = new Person
# {
# Name = "\u13AAlarm"
# };
#
# There are no settings to configure this correctly, unless https://github.com/dotnet/roslyn/issues/63256 (or similar) is ever implemented.
dotnet_diagnostic.IDE0055.severity = none

# IDE0130: Namespace does not match folder structure
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0130
#
Expand Down Expand Up @@ -925,7 +924,7 @@ csharp_indent_block_contents = true

# Spacing options

csharp_space_after_cast = true
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
Expand Down
6 changes: 6 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ for:
matrix:
only:
- image: Ubuntu2204

init:
- git config --global core.autocrlf input

before_build:
- sh: mkdir artifacts -p
Expand All @@ -30,6 +33,9 @@ for:
only:
- image: Visual Studio 2022

init:
- git config --global core.autocrlf true

before_build:
- ps: mkdir artifacts -f

Expand Down
1 change: 1 addition & 0 deletions src/Renci.SshNet/Abstractions/CryptoAbstraction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;

using Renci.SshNet.Security.Cryptography;

namespace Renci.SshNet.Abstractions
Expand Down
12 changes: 6 additions & 6 deletions src/Renci.SshNet/Abstractions/SocketAbstraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ private static void ConnectCore(Socket socket, IPEndPoint remoteEndpoint, TimeSp
{
var connectCompleted = new ManualResetEvent(initialState: false);
var args = new SocketAsyncEventArgs
{
UserToken = connectCompleted,
RemoteEndPoint = remoteEndpoint
};
{
UserToken = connectCompleted,
RemoteEndPoint = remoteEndpoint
};
args.Completed += ConnectCompleted;

if (socket.ConnectAsync(args))
Expand Down Expand Up @@ -96,7 +96,7 @@ private static void ConnectCore(Socket socket, IPEndPoint remoteEndpoint, TimeSp

if (args.SocketError != SocketError.Success)
{
var socketError = (int) args.SocketError;
var socketError = (int)args.SocketError;

if (ownsSocket)
{
Expand Down Expand Up @@ -374,7 +374,7 @@ public static bool IsErrorResumable(SocketError socketError)

private static void ConnectCompleted(object sender, SocketAsyncEventArgs e)
{
var eventWaitHandle = (ManualResetEvent) e.UserToken;
var eventWaitHandle = (ManualResetEvent)e.UserToken;
_ = eventWaitHandle?.Set();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Renci.SshNet/Abstractions/SocketExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static async Task ConnectAsync(this Socket socket, IPEndPoint remoteEndpo
#if NET || NETSTANDARD2_1_OR_GREATER
await using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false).ConfigureAwait(continueOnCapturedContext: false))
#else
using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs) o).SetCancelled(), args, useSynchronizationContext: false))
using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false))
#endif // NET || NETSTANDARD2_1_OR_GREATER
{
await args.ExecuteAsync(socket.ConnectAsync);
Expand All @@ -113,9 +113,9 @@ public static async Task<int> ReceiveAsync(this Socket socket, byte[] buffer, in
args.SetBuffer(buffer, offset, length);

#if NET || NETSTANDARD2_1_OR_GREATER
await using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs) o).SetCancelled(), args, useSynchronizationContext: false).ConfigureAwait(continueOnCapturedContext: false))
await using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false).ConfigureAwait(continueOnCapturedContext: false))
#else
using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs) o).SetCancelled(), args, useSynchronizationContext: false))
using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false))
#endif // NET || NETSTANDARD2_1_OR_GREATER
{
await args.ExecuteAsync(socket.ReceiveAsync);
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/AuthenticationMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected AuthenticationMethod(string username)
/// </returns>
AuthenticationResult IAuthenticationMethod.Authenticate(ISession session)
{
return Authenticate((Session) session);
return Authenticate((Session)session);
}
}
}
6 changes: 3 additions & 3 deletions src/Renci.SshNet/Channels/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ private void OnChannelFailure(object sender, MessageEventArgs<ChannelFailureMess

private void AdjustDataWindow(byte[] messageData)
{
LocalWindowSize -= (uint) messageData.Length;
LocalWindowSize -= (uint)messageData.Length;

// Adjust window if window size is too low
if (LocalWindowSize < LocalPacketSize)
Expand Down Expand Up @@ -794,10 +794,10 @@ private int GetDataLengthThatCanBeSentInMessage(int messageLength)
}
else
{
var bytesThatCanBeSent = Math.Min(Math.Min(RemotePacketSize, (uint) messageLength),
var bytesThatCanBeSent = Math.Min(Math.Min(RemotePacketSize, (uint)messageLength),
serverWindowSize);
RemoteWindowSize -= bytesThatCanBeSent;
return (int) bytesThatCanBeSent;
return (int)bytesThatCanBeSent;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Renci.SshNet/Channels/ChannelDirectTcpip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Net;
using System.Net.Sockets;
using System.Threading;

using Renci.SshNet.Abstractions;
using Renci.SshNet.Common;
using Renci.SshNet.Messages.Connection;
Expand Down Expand Up @@ -59,13 +60,13 @@ public void Open(string remoteHost, uint port, IForwardedPort forwardedPort, Soc
_forwardedPort = forwardedPort;
_forwardedPort.Closing += ForwardedPort_Closing;

var ep = (IPEndPoint) socket.RemoteEndPoint;
var ep = (IPEndPoint)socket.RemoteEndPoint;

// Open channel
SendMessage(new ChannelOpenMessage(LocalChannelNumber,
LocalWindowSize,
LocalPacketSize,
new DirectTcpipChannelInfo(remoteHost, port, ep.Address.ToString(), (uint) ep.Port)));
new DirectTcpipChannelInfo(remoteHost, port, ep.Address.ToString(), (uint)ep.Port)));

// Wait for channel to open
WaitOnHandle(_channelOpen);
Expand Down
1 change: 1 addition & 0 deletions src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Net;
using System.Net.Sockets;

using Renci.SshNet.Abstractions;
using Renci.SshNet.Common;
using Renci.SshNet.Messages.Connection;
Expand Down
1 change: 1 addition & 0 deletions src/Renci.SshNet/Channels/ClientChannel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;

using Renci.SshNet.Common;
using Renci.SshNet.Messages.Connection;

Expand Down
1 change: 1 addition & 0 deletions src/Renci.SshNet/Channels/IChannel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;

using Renci.SshNet.Common;
using Renci.SshNet.Messages.Connection;

Expand Down
1 change: 1 addition & 0 deletions src/Renci.SshNet/Channels/IChannelDirectTcpip.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Net.Sockets;

using Renci.SshNet.Common;

namespace Renci.SshNet.Channels
Expand Down
1 change: 1 addition & 0 deletions src/Renci.SshNet/Channels/IChannelForwardedTcpip.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Net;

using Renci.SshNet.Common;

namespace Renci.SshNet.Channels
Expand Down
1 change: 1 addition & 0 deletions src/Renci.SshNet/Channels/IChannelSession.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;

using Renci.SshNet.Common;

namespace Renci.SshNet.Channels
Expand Down
1 change: 1 addition & 0 deletions src/Renci.SshNet/CipherInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;

using Renci.SshNet.Common;
using Renci.SshNet.Security.Cryptography;

Expand Down
Loading