From 2020604958dfc3ebc7d7605fdc3ba2d4f6c1dab5 Mon Sep 17 00:00:00 2001 From: Marius Thesing Date: Sat, 14 Sep 2024 10:54:57 +0200 Subject: [PATCH] fix S2325: Methods and properties that don't access instance data should be static This one is pretty redundant with CA1822 (which is also disabled in the tests). It caught a few more cases in the library itself, most of which can't be changed because they are public API. https://rules.sonarsource.com/csharp/RSPEC-2325/ --- src/Renci.SshNet/Security/Cryptography/Bcrypt.cs | 3 ++- src/Renci.SshNet/Session.cs | 2 ++ src/Renci.SshNet/ShellStream.cs | 2 ++ test/Renci.SshNet.IntegrationBenchmarks/.editorconfig | 3 +++ test/Renci.SshNet.IntegrationTests/.editorconfig | 3 +++ test/Renci.SshNet.TestTools.OpenSSH/.editorconfig | 5 +++++ test/Renci.SshNet.Tests/.editorconfig | 3 +++ 7 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Renci.SshNet/Security/Cryptography/Bcrypt.cs b/src/Renci.SshNet/Security/Cryptography/Bcrypt.cs index 40ab0695..f097b277 100644 --- a/src/Renci.SshNet/Security/Cryptography/Bcrypt.cs +++ b/src/Renci.SshNet/Security/Cryptography/Bcrypt.cs @@ -15,6 +15,7 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. using Renci.SshNet.Abstractions; + using System; using System.Diagnostics; using System.Security.Cryptography; @@ -902,7 +903,7 @@ namespace Renci.SshNet.Security.Cryptography /// /// /// - private byte[] AppendArrays(byte[] b1, params byte[][] others) + private static byte[] AppendArrays(byte[] b1, params byte[][] others) { //from https://stackoverflow.com/questions/46534429/how-to-convert-java-messagedigest-with-two-update-statements-to-c-sharp int n = b1.Length; diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 19bee9d6..517ba6af 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -316,7 +316,9 @@ namespace Renci.SshNet /// /// The client version. /// +#pragma warning disable S2325 // Methods and properties that don't access instance data should be static public string ClientVersion +#pragma warning restore S2325 // Methods and properties that don't access instance data should be static { get { diff --git a/src/Renci.SshNet/ShellStream.cs b/src/Renci.SshNet/ShellStream.cs index d7228229..ac12cd2c 100644 --- a/src/Renci.SshNet/ShellStream.cs +++ b/src/Renci.SshNet/ShellStream.cs @@ -605,7 +605,9 @@ namespace Renci.SshNet /// /// The text available in the shell up to and including the expected expression. /// +#pragma warning disable S2325 // Methods and properties that don't access instance data should be static public string? EndExpect(IAsyncResult asyncResult) +#pragma warning restore S2325 // Methods and properties that don't access instance data should be static { return TaskToAsyncResult.End(asyncResult); } diff --git a/test/Renci.SshNet.IntegrationBenchmarks/.editorconfig b/test/Renci.SshNet.IntegrationBenchmarks/.editorconfig index 3e3e6d5e..13a8fc84 100644 --- a/test/Renci.SshNet.IntegrationBenchmarks/.editorconfig +++ b/test/Renci.SshNet.IntegrationBenchmarks/.editorconfig @@ -14,6 +14,9 @@ dotnet_diagnostic.S1118.severity = suggestion # https://rules.sonarsource.com/csharp/RSPEC-1450/ dotnet_diagnostic.S1450.severity = suggestion +# S2325: Methods and properties that don't access instance data should be static +dotnet_diagnostic.S2325.severity = silent + # S4144: Methods should not have identical implementations # https://rules.sonarsource.com/csharp/RSPEC-4144/ dotnet_diagnostic.S4144.severity = suggestion diff --git a/test/Renci.SshNet.IntegrationTests/.editorconfig b/test/Renci.SshNet.IntegrationTests/.editorconfig index ecfbce76..d8f9762e 100644 --- a/test/Renci.SshNet.IntegrationTests/.editorconfig +++ b/test/Renci.SshNet.IntegrationTests/.editorconfig @@ -22,6 +22,9 @@ dotnet_diagnostic.S1155.severity = silent # https://rules.sonarsource.com/csharp/RSPEC-1607/ dotnet_diagnostic.S1607.severity = silent +# S2325: Methods and properties that don't access instance data should be static +dotnet_diagnostic.S2325.severity = silent + # S2925: "Thread.Sleep" should not be used in tests # https://rules.sonarsource.com/csharp/RSPEC-2925/ dotnet_diagnostic.S2925.severity = silent diff --git a/test/Renci.SshNet.TestTools.OpenSSH/.editorconfig b/test/Renci.SshNet.TestTools.OpenSSH/.editorconfig index f09ad633..76c9dc31 100644 --- a/test/Renci.SshNet.TestTools.OpenSSH/.editorconfig +++ b/test/Renci.SshNet.TestTools.OpenSSH/.editorconfig @@ -1,5 +1,10 @@ [*.cs] +#### Sonar rules #### + +# S2325: Methods and properties that don't access instance data should be static +dotnet_diagnostic.S2325.severity = silent + #### Meziantou.Analyzer rules #### # MA0001: StringComparison is missing diff --git a/test/Renci.SshNet.Tests/.editorconfig b/test/Renci.SshNet.Tests/.editorconfig index ae7f4921..bd4039b5 100644 --- a/test/Renci.SshNet.Tests/.editorconfig +++ b/test/Renci.SshNet.Tests/.editorconfig @@ -34,6 +34,9 @@ dotnet_diagnostic.S2187.severity = silent # https://rules.sonarsource.com/csharp/RSPEC-2292/ dotnet_diagnostic.S2292.severity = silent +# S2325: Methods and properties that don't access instance data should be static +dotnet_diagnostic.S2325.severity = silent + # S2925: "Thread.Sleep" should not be used in tests # https://rules.sonarsource.com/csharp/RSPEC-2925/ dotnet_diagnostic.S2925.severity = silent