Skip to content

Commit 5e7d01d

Browse files
committed
disable CA2000
1 parent 327e6c6 commit 5e7d01d

File tree

14 files changed

+6
-48
lines changed

14 files changed

+6
-48
lines changed

.editorconfig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ dotnet_diagnostic.S2699.severity = none
177177
# S2930: "IDisposables" should be disposed
178178
# https://rules.sonarsource.com/csharp/RSPEC-2930/
179179
#
180-
# Duplicate of CA2000.
180+
# too noisy.
181181
dotnet_diagnostic.S2930.severity = none
182182

183183
# S2933: Fields that are only assigned in the constructor should be "readonly"
@@ -733,6 +733,11 @@ dotnet_code_quality.CA1859.api_surface = private,internal
733733
# CA1873: Evaluation of this argument may be expensive and unnecessary if logging is disabled
734734
dotnet_diagnostic.CA1873.severity = suggestion
735735

736+
# CA2000: Dispose objects before losing scope
737+
#
738+
# too noisy.
739+
dotnet_diagnostic.CA2000.severity = suggestion
740+
736741
# CA2208: Instantiate argument exceptions correctly
737742
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2208
738743
#

src/Renci.SshNet/ForwardedPortDynamic.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,7 @@ private void StartAccept(SocketAsyncEventArgs e)
182182
{
183183
if (e is null)
184184
{
185-
#pragma warning disable CA2000 // Dispose objects before losing scope
186185
e = new SocketAsyncEventArgs();
187-
#pragma warning restore CA2000 // Dispose objects before losing scope
188186
e.Completed += AcceptCompleted;
189187
}
190188
else

src/Renci.SshNet/ForwardedPortLocal.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,7 @@ private void StartAccept(SocketAsyncEventArgs e)
212212
{
213213
if (e is null)
214214
{
215-
#pragma warning disable CA2000 // Dispose objects before losing scope
216215
e = new SocketAsyncEventArgs();
217-
#pragma warning restore CA2000 // Dispose objects before losing scope
218216
e.Completed += AcceptCompleted;
219217
}
220218
else

src/Renci.SshNet/NetConfClient.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#nullable enable
22
using System;
3-
using System.Diagnostics.CodeAnalysis;
43
using System.Net;
54
using System.Threading;
65
using System.Xml;
@@ -73,7 +72,6 @@ public NetConfClient(ConnectionInfo connectionInfo)
7372
/// <exception cref="ArgumentNullException"><paramref name="password"/> is <see langword="null"/>.</exception>
7473
/// <exception cref="ArgumentException"><paramref name="host"/> is invalid, or <paramref name="username"/> is <see langword="null"/> or contains only whitespace characters.</exception>
7574
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception>
76-
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
7775
public NetConfClient(string host, int port, string username, string password)
7876
: this(new PasswordConnectionInfo(host, port, username, password), ownsConnectionInfo: true)
7977
{
@@ -102,7 +100,6 @@ public NetConfClient(string host, string username, string password)
102100
/// <exception cref="ArgumentNullException"><paramref name="keyFiles"/> is <see langword="null"/>.</exception>
103101
/// <exception cref="ArgumentException"><paramref name="host"/> is invalid, -or- <paramref name="username"/> is <see langword="null"/> or contains only whitespace characters.</exception>
104102
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception>
105-
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
106103
public NetConfClient(string host, int port, string username, params IPrivateKeySource[] keyFiles)
107104
: this(new PrivateKeyConnectionInfo(host, port, username, keyFiles), ownsConnectionInfo: true)
108105
{

src/Renci.SshNet/PrivateKeyFile.OpenSSH.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ public Key Parse()
200200

201201
// k || ENC(A)
202202
unencryptedPrivateKey = privateKeyReader.ReadBinary();
203-
#pragma warning disable CA2000 // Dispose objects before losing scope
204203
parsedKey = new ED25519Key(unencryptedPrivateKey);
205-
#pragma warning restore CA2000 // Dispose objects before losing scope
206204
break;
207205
case "ecdsa-sha2-nistp256":
208206
case "ecdsa-sha2-nistp384":
@@ -212,9 +210,7 @@ public Key Parse()
212210
publicKey = privateKeyReader.ReadBinary();
213211

214212
unencryptedPrivateKey = privateKeyReader.ReadBinary();
215-
#pragma warning disable CA2000 // Dispose objects before losing scope
216213
parsedKey = new EcdsaKey(curve, publicKey, unencryptedPrivateKey.TrimLeadingZeros());
217-
#pragma warning restore CA2000 // Dispose objects before losing scope
218214
break;
219215
case "ssh-rsa":
220216
var modulus = privateKeyReader.ReadBigInt();
@@ -223,9 +219,7 @@ public Key Parse()
223219
var inverseQ = privateKeyReader.ReadBigInt();
224220
var p = privateKeyReader.ReadBigInt();
225221
var q = privateKeyReader.ReadBigInt();
226-
#pragma warning disable CA2000 // Dispose objects before losing scope
227222
parsedKey = new RsaKey(modulus, exponent, d, p, q, inverseQ);
228-
#pragma warning restore CA2000 // Dispose objects before losing scope
229223
break;
230224
default:
231225
throw new SshException("OpenSSH key type '" + keyType + "' is not supported.");

src/Renci.SshNet/PrivateKeyFile.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,8 @@ private void Open(Stream privateKey, string? passPhrase)
370370
if (_key is RsaKey rsaKey)
371371
{
372372
_hostAlgorithms.Add(new KeyHostAlgorithm("ssh-rsa", _key));
373-
#pragma warning disable CA2000 // Dispose objects before losing scope
374373
_hostAlgorithms.Add(new KeyHostAlgorithm("rsa-sha2-512", _key, new RsaDigitalSignature(rsaKey, HashAlgorithmName.SHA512)));
375374
_hostAlgorithms.Add(new KeyHostAlgorithm("rsa-sha2-256", _key, new RsaDigitalSignature(rsaKey, HashAlgorithmName.SHA256)));
376-
#pragma warning restore CA2000 // Dispose objects before losing scope
377375
}
378376
else
379377
{
@@ -420,7 +418,6 @@ private void OpenCertificate(Stream certificate)
420418

421419
_hostAlgorithms.Insert(0, new CertificateHostAlgorithm("[email protected]", Key, Certificate));
422420

423-
#pragma warning disable CA2000 // Dispose objects before losing scope
424421
_hostAlgorithms.Insert(0, new CertificateHostAlgorithm(
425422
426423
Key,
@@ -432,7 +429,6 @@ private void OpenCertificate(Stream certificate)
432429
Key,
433430
Certificate,
434431
new RsaDigitalSignature(rsaKey, HashAlgorithmName.SHA512)));
435-
#pragma warning restore CA2000 // Dispose objects before losing scope
436432
}
437433
else
438434
{

src/Renci.SshNet/ScpClient.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5-
using System.Diagnostics.CodeAnalysis;
65
using System.Globalization;
76
using System.IO;
87
using System.Net;
@@ -152,7 +151,6 @@ public ScpClient(ConnectionInfo connectionInfo)
152151
/// <exception cref="ArgumentNullException"><paramref name="password"/> is <see langword="null"/>.</exception>
153152
/// <exception cref="ArgumentException"><paramref name="host"/> is invalid, or <paramref name="username"/> is <see langword="null"/> or contains only whitespace characters.</exception>
154153
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception>
155-
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
156154
public ScpClient(string host, int port, string username, string password)
157155
: this(new PasswordConnectionInfo(host, port, username, password), ownsConnectionInfo: true)
158156
{
@@ -181,7 +179,6 @@ public ScpClient(string host, string username, string password)
181179
/// <exception cref="ArgumentNullException"><paramref name="keyFiles"/> is <see langword="null"/>.</exception>
182180
/// <exception cref="ArgumentException"><paramref name="host"/> is invalid, -or- <paramref name="username"/> is <see langword="null"/> or contains only whitespace characters.</exception>
183181
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception>
184-
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
185182
public ScpClient(string host, int port, string username, params IPrivateKeySource[] keyFiles)
186183
: this(new PrivateKeyConnectionInfo(host, port, username, keyFiles), ownsConnectionInfo: true)
187184
{

src/Renci.SshNet/Sftp/SftpFileStream.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ internal static SftpFileStream Open(
164164
int bufferSize,
165165
bool isDownloadFile = false)
166166
{
167-
#pragma warning disable CA2000 // Dispose objects before losing scope
168167
return Open(session, path, mode, access, bufferSize, isDownloadFile, isAsync: false, CancellationToken.None).GetAwaiter().GetResult();
169-
#pragma warning restore CA2000 // Dispose objects before losing scope
170168
}
171169

172170
internal static Task<SftpFileStream> OpenAsync(

src/Renci.SshNet/SftpClient.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Buffers;
44
using System.Collections.Generic;
55
using System.Diagnostics;
6-
using System.Diagnostics.CodeAnalysis;
76
using System.Globalization;
87
using System.IO;
98
using System.Linq;
@@ -202,7 +201,6 @@ public SftpClient(ConnectionInfo connectionInfo)
202201
/// <exception cref="ArgumentNullException"><paramref name="password"/> is <see langword="null"/>.</exception>
203202
/// <exception cref="ArgumentException"><paramref name="host"/> is invalid. <para>-or-</para> <paramref name="username"/> is <see langword="null"/> or contains only whitespace characters.</exception>
204203
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception>
205-
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
206204
public SftpClient(string host, int port, string username, string password)
207205
: this(new PasswordConnectionInfo(host, port, username, password), ownsConnectionInfo: true)
208206
{
@@ -231,7 +229,6 @@ public SftpClient(string host, string username, string password)
231229
/// <exception cref="ArgumentNullException"><paramref name="keyFiles"/> is <see langword="null"/>.</exception>
232230
/// <exception cref="ArgumentException"><paramref name="host"/> is invalid. <para>-or-</para> <paramref name="username"/> is <see langword="null"/> or contains only whitespace characters.</exception>
233231
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception>
234-
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
235232
public SftpClient(string host, int port, string username, params IPrivateKeySource[] keyFiles)
236233
: this(new PrivateKeyConnectionInfo(host, port, username, keyFiles), ownsConnectionInfo: true)
237234
{
@@ -2173,7 +2170,6 @@ private List<FileInfo> InternalSynchronizeDirectories(string sourcePath, string
21732170
var remoteFileName = string.Format(CultureInfo.InvariantCulture, @"{0}/{1}", destinationPath, localFile.Name);
21742171
try
21752172
{
2176-
#pragma warning disable CA2000 // Dispose objects before losing scope
21772173
using (var file = File.OpenRead(localFile.FullName))
21782174
{
21792175
#pragma warning disable CA2025 // Do not pass 'IDisposable' instances into unawaited tasks
@@ -2187,7 +2183,6 @@ private List<FileInfo> InternalSynchronizeDirectories(string sourcePath, string
21872183
CancellationToken.None).GetAwaiter().GetResult();
21882184
#pragma warning restore CA2025 // Do not pass 'IDisposable' instances into unawaited tasks
21892185
}
2190-
#pragma warning restore CA2000 // Dispose objects before losing scope
21912186

21922187
uploadedFiles.Add(localFile);
21932188

src/Renci.SshNet/SshClient.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#nullable enable
22
using System;
33
using System.Collections.Generic;
4-
using System.Diagnostics.CodeAnalysis;
54
using System.IO;
65
using System.Net;
76
using System.Text;
@@ -58,9 +57,7 @@ public SshClient(ConnectionInfo connectionInfo)
5857
/// <exception cref="ArgumentException"><paramref name="host"/> is invalid, or <paramref name="username"/> is <see langword="null"/> or contains only whitespace characters.</exception>
5958
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception>
6059
public SshClient(string host, int port, string username, string password)
61-
#pragma warning disable CA2000 // Dispose objects before losing scope
6260
: this(new PasswordConnectionInfo(host, port, username, password), ownsConnectionInfo: true)
63-
#pragma warning restore CA2000 // Dispose objects before losing scope
6461
{
6562
}
6663

@@ -87,7 +84,6 @@ public SshClient(string host, string username, string password)
8784
/// <exception cref="ArgumentNullException"><paramref name="keyFiles"/> is <see langword="null"/>.</exception>
8885
/// <exception cref="ArgumentException"><paramref name="host"/> is invalid, -or- <paramref name="username"/> is <see langword="null"/> or contains only whitespace characters.</exception>
8986
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception>
90-
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
9187
public SshClient(string host, int port, string username, params IPrivateKeySource[] keyFiles)
9288
: this(new PrivateKeyConnectionInfo(host, port, username, keyFiles), ownsConnectionInfo: true)
9389
{

0 commit comments

Comments
 (0)