Skip to content

Commit 3ecbd10

Browse files
authored
Fix some (lots of) issues reported by analyzers. (sshnet#1125)
Fix some (lots of) issues reported by analyzers.
1 parent 072ba7e commit 3ecbd10

File tree

251 files changed

+7541
-4090
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

251 files changed

+7541
-4090
lines changed

.editorconfig_soon

Lines changed: 1235 additions & 0 deletions
Large diffs are not rendered by default.

Directory.Build.props

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<Project>
2+
<Import Project="$(MSBuildThisFileFullPath).user" Condition="Exists('$(MSBuildThisFileFullPath).user')" />
3+
4+
<!--
5+
Assembly Info properties that apply to all projects/assemblies.
6+
-->
7+
<PropertyGroup>
8+
<SignAssembly>true</SignAssembly>
9+
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)src\Renci.SshNet.snk</AssemblyOriginatorKeyFile>
10+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
11+
<LangVersion>latest</LangVersion>
12+
<!--
13+
<WarningLevel>9999</WarningLevel>
14+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
15+
-->
16+
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
17+
</PropertyGroup>
18+
19+
<!--
20+
Code analysis properties.
21+
-->
22+
<PropertyGroup>
23+
<EnableNETAnalyzers>false</EnableNETAnalyzers>
24+
<AnalysisLevel>preview-All</AnalysisLevel>
25+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
26+
</PropertyGroup>
27+
28+
<!--
29+
Add the stylecop config to each project.
30+
-->
31+
<ItemGroup>
32+
<AdditionalFiles Include="..\..\stylecop.json" Link="stylecop.json" />
33+
</ItemGroup>
34+
35+
<!--
36+
Use fixed version of analyzers.
37+
-->
38+
<ItemGroup>
39+
<!--
40+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0-preview1.23165.1" PrivateAssets="all" />
41+
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all" />
42+
<PackageReference Include="Meziantou.Analyzer" Version="2.0.52" PrivateAssets="all" />
43+
-->
44+
<!--
45+
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.55.0.65544" PrivateAssets="all" />
46+
-->
47+
</ItemGroup>
48+
</Project>

README.md

100755100644
File mode changed.
Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
using System;
2+
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
24
using Renci.SshNet.Common;
35
using Renci.SshNet.Tests.Common;
46

57
namespace Renci.SshNet.Tests.Classes.Common
6-
{
7-
/// <summary>
8-
///This is a test class for ObjectIdentifierTest and is intended
9-
///to contain all ObjectIdentifierTest Unit Tests
10-
///</summary>
8+
{
119
[TestClass]
12-
[Ignore] // placeholder for actual test
1310
public class ObjectIdentifierTest : TestBase
1411
{
15-
/// <summary>
16-
///A test for ObjectIdentifier Constructor
17-
///</summary>
1812
[TestMethod]
19-
public void ObjectIdentifierConstructorTest()
13+
public void Constructor_IdentifiersIsNull()
2014
{
21-
ulong[] identifiers = null; // TODO: Initialize to an appropriate value
22-
ObjectIdentifier target = new ObjectIdentifier(identifiers);
23-
Assert.Inconclusive("TODO: Implement code to verify target");
15+
const ulong[] identifiers = null;
16+
17+
var actualException = Assert.ThrowsException<ArgumentNullException>(() => new ObjectIdentifier(identifiers));
18+
19+
Assert.AreEqual(typeof(ArgumentNullException), actualException.GetType());
20+
Assert.IsNull(actualException.InnerException);
21+
Assert.AreEqual(nameof(identifiers), actualException.ParamName);
22+
}
23+
24+
[TestMethod]
25+
public void Constructor_LengthOfIdentifiersIsLessThanTwo()
26+
{
27+
var identifiers = new[] { 5UL };
28+
29+
var actualException = Assert.ThrowsException<ArgumentException>(() => new ObjectIdentifier(identifiers));
30+
31+
Assert.AreEqual(typeof(ArgumentException), actualException.GetType());
32+
Assert.IsNull(actualException.InnerException);
33+
ArgumentExceptionAssert.MessageEquals("Must contain at least two elements.", actualException);
34+
Assert.AreEqual(nameof(identifiers), actualException.ParamName);
2435
}
2536
}
2637
}

src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ConnectionClosedByServer_NoDataSentByServer.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
2-
using Renci.SshNet.Common;
3-
using Renci.SshNet.Connection;
4-
using Renci.SshNet.Tests.Common;
5-
using System;
1+
using System;
62
using System.Collections.Generic;
73
using System.Net;
84
using System.Net.Sockets;
95
using System.Threading;
106

7+
using Microsoft.VisualStudio.TestTools.UnitTesting;
8+
9+
using Renci.SshNet.Common;
10+
using Renci.SshNet.Connection;
11+
using Renci.SshNet.Tests.Common;
12+
1113
namespace Renci.SshNet.Tests.Classes.Connection
1214
{
1315
[TestClass]

src/Renci.SshNet.Tests/Classes/MessageEventArgsTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Renci.SshNet.Tests.Classes
66
/// <summary>
77
/// Provides data for message events.
88
/// </summary>
9-
/// <typeparam name="T">Message type</typeparam>
109
[TestClass]
1110
public class MessageEventArgsTest : TestBase
1211
{

src/Renci.SshNet.Tests/Classes/Security/Cryptography/HMacTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace Renci.SshNet.Tests.Classes.Security.Cryptography
88
/// <summary>
99
/// Provides HMAC algorithm implementation.
1010
/// </summary>
11-
/// <typeparam name="T"></typeparam>
1211
[TestClass]
1312
public class HMacTest : TestBase
1413
{

src/Renci.SshNet.Tests/Classes/Sftp/SftpStatVfsResponseBuilder.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,17 @@ protected override void LoadData()
147147
base.LoadData();
148148

149149
Information = new SftpFileSytemInformation(ReadUInt64(), // FileSystemBlockSize
150-
ReadUInt64(), // BlockSize
151-
ReadUInt64(), // TotalBlocks
152-
ReadUInt64(), // FreeBlocks
153-
ReadUInt64(), // AvailableBlocks
154-
ReadUInt64(), // TotalNodes
155-
ReadUInt64(), // FreeNodes
156-
ReadUInt64(), // AvailableNodes
157-
ReadUInt64(), // Sid
158-
ReadUInt64(), // Flags
159-
ReadUInt64() // MaxNameLenght
160-
);
150+
ReadUInt64(), // BlockSize
151+
ReadUInt64(), // TotalBlocks
152+
ReadUInt64(), // FreeBlocks
153+
ReadUInt64(), // AvailableBlocks
154+
ReadUInt64(), // TotalNodes
155+
ReadUInt64(), // FreeNodes
156+
ReadUInt64(), // AvailableNodes
157+
ReadUInt64(), // Sid
158+
ReadUInt64(), // Flags
159+
ReadUInt64() // MaxNameLenght
160+
);
161161
}
162162

163163
protected override void SaveData()

src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public AsyncSocketListener(IPEndPoint endPoint)
4040
/// <value>
4141
/// <see langword="true"/> to invoke <see cref="Socket.Shutdown(SocketShutdown)"/> on the <see cref="Socket"/> that is used
4242
/// to handle the communication with the remote host, when the remote host has closed the connection; otherwise,
43-
/// <see langword="false""/>. The default is <see langword="true"/>.
43+
/// <see langword="false"/>. The default is <see langword="true"/>.
4444
/// </value>
4545
public bool ShutdownRemoteCommunicationSocket { get; set; }
4646

src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<LangVersion>7.3</LangVersion>
4-
<SignAssembly>true</SignAssembly>
5-
<AssemblyOriginatorKeyFile>..\Renci.SshNet.snk</AssemblyOriginatorKeyFile>
6-
<TargetFrameworks>net462;net6.0;net7.0</TargetFrameworks>
3+
<TargetFrameworks>net462;net6.0;net7.0</TargetFrameworks>
4+
<!--
5+
Even though we're not interested in producing XML docs for test projects, we have to enable this in order to have the .NET Compiler
6+
Platform analyzers produce the IDE0005 (Remove unnecessary import) diagnostic.
7+
8+
To avoid warnings for missing XML docs, we add CS1591 (Missing XML comment for publicly visible type or member) to the NoWarn property.
9+
10+
We can stop producing XML docs for test projects (and remove the NoWarn for CS1591) once the following issue is fixed:
11+
https://github.com/dotnet/roslyn/issues/41640.
12+
-->
13+
<NoWarn>$(NoWarn);CS1591</NoWarn>
714
</PropertyGroup>
815

916
<PropertyGroup>

src/Renci.SshNet.sln

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29521.150
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.33326.253
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{2D6CAE62-D053-476F-9BDD-2B1F27FA9C5D}"
77
ProjectSection(SolutionItems) = preProject
@@ -23,6 +23,25 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renci.SshNet", "Renci.SshNe
2323
EndProject
2424
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renci.SshNet.Tests", "Renci.SshNet.Tests\Renci.SshNet.Tests.csproj", "{C45379B9-17B1-4E89-BC2E-6D41726413E8}"
2525
EndProject
26+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{04E8CC26-116E-4116-9558-7ED542548E70}"
27+
ProjectSection(SolutionItems) = preProject
28+
..\.editorconfig = ..\.editorconfig
29+
..\.gitattributes = ..\.gitattributes
30+
..\.gitignore = ..\.gitignore
31+
..\appveyor.yml = ..\appveyor.yml
32+
..\CODEOWNERS = ..\CODEOWNERS
33+
..\Directory.Build.props = ..\Directory.Build.props
34+
..\LICENSE = ..\LICENSE
35+
..\README.md = ..\README.md
36+
..\THIRD-PARTY-NOTICES.TXT = ..\THIRD-PARTY-NOTICES.TXT
37+
EndProjectSection
38+
EndProject
39+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D21A4D03-0AC2-4613-BB6D-74D2D16A72CC}"
40+
ProjectSection(SolutionItems) = preProject
41+
..\test\.editorconfig = ..\test\.editorconfig
42+
..\test\Directory.Build.props = ..\test\Directory.Build.props
43+
EndProjectSection
44+
EndProject
2645
Global
2746
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2847
Debug|Any CPU = Debug|Any CPU
@@ -72,6 +91,7 @@ Global
7291
GlobalSection(NestedProjects) = preSolution
7392
{94EE3919-19FA-4D9B-8DA9-249050B15232} = {2D6CAE62-D053-476F-9BDD-2B1F27FA9C5D}
7493
{A6C3FFD3-16A5-44D3-8C1F-3613D6DD17D1} = {2D6CAE62-D053-476F-9BDD-2B1F27FA9C5D}
94+
{D21A4D03-0AC2-4613-BB6D-74D2D16A72CC} = {04E8CC26-116E-4116-9558-7ED542548E70}
7595
EndGlobalSection
7696
GlobalSection(ExtensibilityGlobals) = postSolution
7797
SolutionGuid = {BAD6019D-4AF7-4E15-99A0-8036E16FC0E5}

src/Renci.SshNet/.editorconfig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[*.cs]
2+
3+
### StyleCop Analyzers rules ###
4+
5+
# SA1202: Elements must be ordered by access
6+
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1202.md
7+
dotnet_diagnostic.SA1202.severity = none
8+
9+
#### .NET Compiler Platform analysers rules ####
10+
11+
# CA1031: Do not catch general exception types
12+
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1031
13+
dotnet_diagnostic.CA1031.severity = none
14+
15+
# CA2213: Disposable fields should be disposed
16+
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2213
17+
dotnet_diagnostic.CA2213.severity = none
18+
19+
# IDE0004: Types that own disposable fields should be disposable
20+
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0004
21+
dotnet_diagnostic.IDE0004.severity = none
22+
23+
# IDE0048: Add parentheses for clarity
24+
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0047
25+
dotnet_diagnostic.IDE0048.severity = none

src/Renci.SshNet/Abstractions/CryptoAbstraction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal static class CryptoAbstraction
88
private static readonly System.Security.Cryptography.RandomNumberGenerator Randomizer = CreateRandomNumberGenerator();
99

1010
/// <summary>
11-
/// Generates a <see cref="Byte"/> array of the specified length, and fills it with a
11+
/// Generates a <see cref="byte"/> array of the specified length, and fills it with a
1212
/// cryptographically strong random sequence of values.
1313
/// </summary>
1414
/// <param name="length">The length of the array generate.</param>

0 commit comments

Comments
 (0)