Skip to content

Commit 3ecbd10

Browse files
authored
Fix some (lots of) issues reported by analyzers. (#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>

0 commit comments

Comments
 (0)