Skip to content

Commit

Permalink
Fix some (lots of) issues reported by analyzers. (#1125)
Browse files Browse the repository at this point in the history
Fix some (lots of) issues reported by analyzers.
  • Loading branch information
drieseng authored May 24, 2023
1 parent 072ba7e commit 3ecbd10
Show file tree
Hide file tree
Showing 251 changed files with 7,541 additions and 4,090 deletions.
1,235 changes: 1,235 additions & 0 deletions .editorconfig_soon

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<Project>
<Import Project="$(MSBuildThisFileFullPath).user" Condition="Exists('$(MSBuildThisFileFullPath).user')" />

<!--
Assembly Info properties that apply to all projects/assemblies.
-->
<PropertyGroup>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)src\Renci.SshNet.snk</AssemblyOriginatorKeyFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>
<!--
<WarningLevel>9999</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
-->
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
</PropertyGroup>

<!--
Code analysis properties.
-->
<PropertyGroup>
<EnableNETAnalyzers>false</EnableNETAnalyzers>
<AnalysisLevel>preview-All</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>

<!--
Add the stylecop config to each project.
-->
<ItemGroup>
<AdditionalFiles Include="..\..\stylecop.json" Link="stylecop.json" />
</ItemGroup>

<!--
Use fixed version of analyzers.
-->
<ItemGroup>
<!--
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0-preview1.23165.1" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.52" PrivateAssets="all" />
-->
<!--
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.55.0.65544" PrivateAssets="all" />
-->
</ItemGroup>
</Project>
Empty file modified README.md
100755 → 100644
Empty file.
39 changes: 25 additions & 14 deletions src/Renci.SshNet.Tests/Classes/Common/ObjectIdentifierTest.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;

namespace Renci.SshNet.Tests.Classes.Common
{
/// <summary>
///This is a test class for ObjectIdentifierTest and is intended
///to contain all ObjectIdentifierTest Unit Tests
///</summary>
{
[TestClass]
[Ignore] // placeholder for actual test
public class ObjectIdentifierTest : TestBase
{
/// <summary>
///A test for ObjectIdentifier Constructor
///</summary>
[TestMethod]
public void ObjectIdentifierConstructorTest()
public void Constructor_IdentifiersIsNull()
{
ulong[] identifiers = null; // TODO: Initialize to an appropriate value
ObjectIdentifier target = new ObjectIdentifier(identifiers);
Assert.Inconclusive("TODO: Implement code to verify target");
const ulong[] identifiers = null;

var actualException = Assert.ThrowsException<ArgumentNullException>(() => new ObjectIdentifier(identifiers));

Assert.AreEqual(typeof(ArgumentNullException), actualException.GetType());
Assert.IsNull(actualException.InnerException);
Assert.AreEqual(nameof(identifiers), actualException.ParamName);
}

[TestMethod]
public void Constructor_LengthOfIdentifiersIsLessThanTwo()
{
var identifiers = new[] { 5UL };

var actualException = Assert.ThrowsException<ArgumentException>(() => new ObjectIdentifier(identifiers));

Assert.AreEqual(typeof(ArgumentException), actualException.GetType());
Assert.IsNull(actualException.InnerException);
ArgumentExceptionAssert.MessageEquals("Must contain at least two elements.", actualException);
Assert.AreEqual(nameof(identifiers), actualException.ParamName);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Renci.SshNet.Common;
using Renci.SshNet.Connection;
using Renci.SshNet.Tests.Common;
using System;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Threading;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Renci.SshNet.Common;
using Renci.SshNet.Connection;
using Renci.SshNet.Tests.Common;

namespace Renci.SshNet.Tests.Classes.Connection
{
[TestClass]
Expand Down
1 change: 0 additions & 1 deletion src/Renci.SshNet.Tests/Classes/MessageEventArgsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Renci.SshNet.Tests.Classes
/// <summary>
/// Provides data for message events.
/// </summary>
/// <typeparam name="T">Message type</typeparam>
[TestClass]
public class MessageEventArgsTest : TestBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Renci.SshNet.Tests.Classes.Security.Cryptography
/// <summary>
/// Provides HMAC algorithm implementation.
/// </summary>
/// <typeparam name="T"></typeparam>
[TestClass]
public class HMacTest : TestBase
{
Expand Down
22 changes: 11 additions & 11 deletions src/Renci.SshNet.Tests/Classes/Sftp/SftpStatVfsResponseBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ protected override void LoadData()
base.LoadData();

Information = new SftpFileSytemInformation(ReadUInt64(), // FileSystemBlockSize
ReadUInt64(), // BlockSize
ReadUInt64(), // TotalBlocks
ReadUInt64(), // FreeBlocks
ReadUInt64(), // AvailableBlocks
ReadUInt64(), // TotalNodes
ReadUInt64(), // FreeNodes
ReadUInt64(), // AvailableNodes
ReadUInt64(), // Sid
ReadUInt64(), // Flags
ReadUInt64() // MaxNameLenght
);
ReadUInt64(), // BlockSize
ReadUInt64(), // TotalBlocks
ReadUInt64(), // FreeBlocks
ReadUInt64(), // AvailableBlocks
ReadUInt64(), // TotalNodes
ReadUInt64(), // FreeNodes
ReadUInt64(), // AvailableNodes
ReadUInt64(), // Sid
ReadUInt64(), // Flags
ReadUInt64() // MaxNameLenght
);
}

protected override void SaveData()
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public AsyncSocketListener(IPEndPoint endPoint)
/// <value>
/// <see langword="true"/> to invoke <see cref="Socket.Shutdown(SocketShutdown)"/> on the <see cref="Socket"/> that is used
/// to handle the communication with the remote host, when the remote host has closed the connection; otherwise,
/// <see langword="false""/>. The default is <see langword="true"/>.
/// <see langword="false"/>. The default is <see langword="true"/>.
/// </value>
public bool ShutdownRemoteCommunicationSocket { get; set; }

Expand Down
15 changes: 11 additions & 4 deletions src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<LangVersion>7.3</LangVersion>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\Renci.SshNet.snk</AssemblyOriginatorKeyFile>
<TargetFrameworks>net462;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net462;net6.0;net7.0</TargetFrameworks>
<!--
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
Platform analyzers produce the IDE0005 (Remove unnecessary import) diagnostic.
To avoid warnings for missing XML docs, we add CS1591 (Missing XML comment for publicly visible type or member) to the NoWarn property.
We can stop producing XML docs for test projects (and remove the NoWarn for CS1591) once the following issue is fixed:
https://github.com/dotnet/roslyn/issues/41640.
-->
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>

<PropertyGroup>
Expand Down
24 changes: 22 additions & 2 deletions src/Renci.SshNet.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29521.150
# Visual Studio Version 17
VisualStudioVersion = 17.5.33326.253
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{2D6CAE62-D053-476F-9BDD-2B1F27FA9C5D}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -23,6 +23,25 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renci.SshNet", "Renci.SshNe
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renci.SshNet.Tests", "Renci.SshNet.Tests\Renci.SshNet.Tests.csproj", "{C45379B9-17B1-4E89-BC2E-6D41726413E8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{04E8CC26-116E-4116-9558-7ED542548E70}"
ProjectSection(SolutionItems) = preProject
..\.editorconfig = ..\.editorconfig
..\.gitattributes = ..\.gitattributes
..\.gitignore = ..\.gitignore
..\appveyor.yml = ..\appveyor.yml
..\CODEOWNERS = ..\CODEOWNERS
..\Directory.Build.props = ..\Directory.Build.props
..\LICENSE = ..\LICENSE
..\README.md = ..\README.md
..\THIRD-PARTY-NOTICES.TXT = ..\THIRD-PARTY-NOTICES.TXT
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D21A4D03-0AC2-4613-BB6D-74D2D16A72CC}"
ProjectSection(SolutionItems) = preProject
..\test\.editorconfig = ..\test\.editorconfig
..\test\Directory.Build.props = ..\test\Directory.Build.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -72,6 +91,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{94EE3919-19FA-4D9B-8DA9-249050B15232} = {2D6CAE62-D053-476F-9BDD-2B1F27FA9C5D}
{A6C3FFD3-16A5-44D3-8C1F-3613D6DD17D1} = {2D6CAE62-D053-476F-9BDD-2B1F27FA9C5D}
{D21A4D03-0AC2-4613-BB6D-74D2D16A72CC} = {04E8CC26-116E-4116-9558-7ED542548E70}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BAD6019D-4AF7-4E15-99A0-8036E16FC0E5}
Expand Down
25 changes: 25 additions & 0 deletions src/Renci.SshNet/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[*.cs]

### StyleCop Analyzers rules ###

# SA1202: Elements must be ordered by access
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1202.md
dotnet_diagnostic.SA1202.severity = none

#### .NET Compiler Platform analysers rules ####

# CA1031: Do not catch general exception types
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1031
dotnet_diagnostic.CA1031.severity = none

# CA2213: Disposable fields should be disposed
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2213
dotnet_diagnostic.CA2213.severity = none

# IDE0004: Types that own disposable fields should be disposable
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0004
dotnet_diagnostic.IDE0004.severity = none

# IDE0048: Add parentheses for clarity
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0047
dotnet_diagnostic.IDE0048.severity = none
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Abstractions/CryptoAbstraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static class CryptoAbstraction
private static readonly System.Security.Cryptography.RandomNumberGenerator Randomizer = CreateRandomNumberGenerator();

/// <summary>
/// Generates a <see cref="Byte"/> array of the specified length, and fills it with a
/// Generates a <see cref="byte"/> array of the specified length, and fills it with a
/// cryptographically strong random sequence of values.
/// </summary>
/// <param name="length">The length of the array generate.</param>
Expand Down
Loading

0 comments on commit 3ecbd10

Please sign in to comment.