Skip to content

Commit 9be67c0

Browse files
jscarleRob-Hague
andauthored
Cleanup and muting of analyzer warnings (#1357)
* Fixed warnings in tests. * Fixed warnings in main project. * Fix public key. * Further warning cleanup. * Muted remaining warnings. * Final cleanup. * Fix warning. * Fix test classes. * Fix more internals. * Revert "internal" in test projects * Revert more internals. * Revert all non-analyzer changes. --------- Co-authored-by: Rob Hague <[email protected]>
1 parent db3d7e8 commit 9be67c0

36 files changed

+336
-332
lines changed

Renci.SshNet.sln

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2929
EndProject
3030
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D21A4D03-0AC2-4613-BB6D-74D2D16A72CC}"
3131
ProjectSection(SolutionItems) = preProject
32-
test\.editorconfig = test\.editorconfig
3332
test\Directory.Build.props = test\Directory.Build.props
3433
EndProjectSection
3534
EndProject

src/Renci.SshNet/.editorconfig

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,18 @@ MA0053.public_class_should_be_sealed = false
108108
# TODO: Remove exclusion when issues are fixed
109109
dotnet_diagnostic.MA0055.severity = none
110110

111+
# MA0089: Optimize string method usage
112+
# https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0089.md
113+
dotnet_diagnostic.MA0089.severity = none
114+
111115
# MA0110: Use the Regex source generator
112116
# https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0110.md
113117
dotnet_diagnostic.MA0110.severity = none
114118

119+
# MA0026: Fix TODO comment
120+
# https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md
121+
dotnet_diagnostic.MA0026.severity = none
122+
115123
#### .NET Compiler Platform analysers rules ####
116124

117125
# CA1030: Use events where appropriate
@@ -152,10 +160,30 @@ dotnet_diagnostic.CA3075.severity = none
152160
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0004
153161
dotnet_diagnostic.IDE0004.severity = none
154162

163+
# IDE0047: Remove unnecessary parentheses
164+
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0047-ide0048
165+
dotnet_diagnostic.IDE0047.severity = none
166+
155167
# IDE0048: Add parentheses for clarity
156-
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0047
168+
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0047-ide0048
157169
dotnet_diagnostic.IDE0048.severity = none
158170

159171
# IDE0305: Collection initialization can be simplified
160172
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0305
161173
dotnet_diagnostic.IDE0305.severity = none
174+
175+
# IDE0046: Use conditional expression for return
176+
# https://learn.microsoft.com/en-ca/dotnet/fundamentals/code-analysis/style-rules/ide0046
177+
dotnet_diagnostic.IDE0046.severity = none
178+
179+
# IDE0032: Use auto-implemented property
180+
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0032
181+
dotnet_diagnostic.IDE0032.severity = none
182+
183+
# CA5350: Do Not Use Weak Cryptographic Algorithms
184+
# https://learn.microsoft.com/en-ca/dotnet/fundamentals/code-analysis/quality-rules/ca5350
185+
dotnet_diagnostic.CA5350.severity = none
186+
187+
# CA5351: Do Not Use Broken Cryptographic Algorithms
188+
# https://learn.microsoft.com/en-ca/dotnet/fundamentals/code-analysis/quality-rules/ca5351
189+
dotnet_diagnostic.CA5351.severity = none

src/Renci.SshNet/Abstractions/CryptoAbstraction.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,12 @@ public static System.Security.Cryptography.RandomNumberGenerator CreateRandomNum
3939

4040
public static System.Security.Cryptography.MD5 CreateMD5()
4141
{
42-
#pragma warning disable CA5351 // Do not use broken cryptographic algorithms
4342
return System.Security.Cryptography.MD5.Create();
44-
#pragma warning restore CA5351 // Do not use broken cryptographic algorithms
4543
}
4644

4745
public static System.Security.Cryptography.SHA1 CreateSHA1()
4846
{
49-
#pragma warning disable CA5350 // Do not use weak cryptographic algorithms
5047
return System.Security.Cryptography.SHA1.Create();
51-
#pragma warning restore CA5350 // Do not use weak cryptographic algorithms
5248
}
5349

5450
public static System.Security.Cryptography.SHA256 CreateSHA256()
@@ -68,30 +64,22 @@ public static System.Security.Cryptography.SHA512 CreateSHA512()
6864

6965
public static System.Security.Cryptography.HMACMD5 CreateHMACMD5(byte[] key)
7066
{
71-
#pragma warning disable CA5351 // Do not use broken cryptographic algorithms
7267
return new System.Security.Cryptography.HMACMD5(key);
73-
#pragma warning restore CA5351 // Do not use broken cryptographic algorithms
7468
}
7569

7670
public static HMACMD5 CreateHMACMD5(byte[] key, int hashSize)
7771
{
78-
#pragma warning disable CA5351 // Do not use broken cryptographic algorithms
7972
return new HMACMD5(key, hashSize);
80-
#pragma warning restore CA5351 // Do not use broken cryptographic algorithms
8173
}
8274

8375
public static System.Security.Cryptography.HMACSHA1 CreateHMACSHA1(byte[] key)
8476
{
85-
#pragma warning disable CA5350 // Do not use weak cryptographic algorithms
8677
return new System.Security.Cryptography.HMACSHA1(key);
87-
#pragma warning restore CA5350 // Do not use weak cryptographic algorithms
8878
}
8979

9080
public static HMACSHA1 CreateHMACSHA1(byte[] key, int hashSize)
9181
{
92-
#pragma warning disable CA5350 // Do not use weak cryptographic algorithms
9382
return new HMACSHA1(key, hashSize);
94-
#pragma warning restore CA5350 // Do not use weak cryptographic algorithms
9583
}
9684

9785
public static System.Security.Cryptography.HMACSHA256 CreateHMACSHA256(byte[] key)

src/Renci.SshNet/Abstractions/SocketExtensions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ public void SetCancelled()
5050
SetCompleted();
5151
}
5252

53-
#pragma warning disable S1144 // Unused private types or members should be removed
5453
public AwaitableSocketAsyncEventArgs GetAwaiter()
55-
#pragma warning restore S1144 // Unused private types or members should be removed
5654
{
5755
return this;
5856
}
@@ -68,9 +66,7 @@ void INotifyCompletion.OnCompleted(Action continuation)
6866
}
6967
}
7068

71-
#pragma warning disable S1144 // Unused private types or members should be removed
7269
public void GetResult()
73-
#pragma warning restore S1144 // Unused private types or members should be removed
7470
{
7571
if (_isCancelled)
7672
{

src/Renci.SshNet/Common/BigInteger.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma warning disable SA1028 // Code should not contain trailing whitespace
2-
#pragma warning disable SA1515 // Single-line comment should be preceded by blank line
32
//
43
// System.Numerics.BigInteger
54
//
@@ -46,7 +45,6 @@
4645
*
4746
*
4847
* ***************************************************************************/
49-
#pragma warning restore SA1515 // Single-line comment should be preceded by blank line
5048
#pragma warning restore SA1028 // Code should not contain trailing whitespace
5149

5250
using System;
@@ -4578,9 +4576,7 @@ public readonly byte[] ToByteArray()
45784576

45794577
if (needExtra)
45804578
{
4581-
#pragma warning disable S1854 // Unused assignments should be removed
45824579
res[j++] = 0xFF;
4583-
#pragma warning restore S1854 // Unused assignments should be removed
45844580
}
45854581
}
45864582
else
@@ -4590,9 +4586,7 @@ public readonly byte[] ToByteArray()
45904586
res[j++] = (byte)(word >> 8);
45914587
res[j++] = (byte)(word >> 16);
45924588
res[j++] = (byte)(word >> 24);
4593-
#pragma warning disable S1854 // Unused assignments should be removed
45944589
res[j++] = 0xFF;
4595-
#pragma warning restore S1854 // Unused assignments should be removed
45964590
}
45974591
}
45984592

src/Renci.SshNet/Compression/ZlibStream.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,4 @@ public void Write(byte[] buffer, int offset, int count)
5454
}
5555
}
5656

57-
#pragma warning restore SA1005 // Single line comments should begin with single space
5857
#pragma warning restore S125 // Sections of code should not be commented out

src/Renci.SshNet/ForwardedPort.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ public virtual void Start()
7171
/// <summary>
7272
/// Stops port forwarding.
7373
/// </summary>
74-
#pragma warning disable CA1716 // Identifiers should not match keywords
7574
public virtual void Stop()
76-
#pragma warning restore CA1716 // Identifiers should not match keywords
7775
{
7876
if (IsStarted)
7977
{

src/Renci.SshNet/ISftpClient.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,7 @@ public interface ISftpClient : IBaseClient
592592
/// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
593593
/// <exception cref="ArgumentNullException"><paramref name="path" /> is <see langword="null"/>.</exception>
594594
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
595-
#pragma warning disable CA1716 // Identifiers should not match keywords
596595
ISftpFile Get(string path);
597-
#pragma warning restore CA1716 // Identifiers should not match keywords
598596

599597
/// <summary>
600598
/// Gets the <see cref="SftpFileAttributes"/> of the file on the path.

src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Renci.SshNet
1515
/// </summary>
1616
public class KeyboardInteractiveAuthenticationMethod : AuthenticationMethod, IDisposable
1717
{
18-
private readonly RequestMessage _requestMessage;
18+
private readonly RequestMessageKeyboardInteractive _requestMessage;
1919
private AuthenticationResult _authenticationResult = AuthenticationResult.Failure;
2020
private Session _session;
2121
private EventWaitHandle _authenticationCompleted = new AutoResetEvent(initialState: false);

src/Renci.SshNet/Messages/Authentication/FailureMessage.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ protected override void LoadData()
6868
/// </summary>
6969
protected override void SaveData()
7070
{
71-
#pragma warning disable MA0025 // Implement the functionality instead of throwing NotImplementedException
7271
throw new NotImplementedException();
73-
#pragma warning restore MA0025 // Implement the functionality instead of throwing NotImplementedException
7472
}
7573

7674
internal override void Process(Session session)
@@ -81,9 +79,7 @@ internal override void Process(Session session)
8179
/// <inheritdoc/>
8280
public override string ToString()
8381
{
84-
#pragma warning disable MA0089 // Optimize string method usage
8582
return $"SSH_MSG_USERAUTH_FAILURE {string.Join(",", AllowedAuthentications)} ({nameof(PartialSuccess)}:{PartialSuccess})";
86-
#pragma warning restore MA0089 // Optimize string method usage
8783
}
8884
}
8985
}

0 commit comments

Comments
 (0)