Skip to content
Permalink
Browse files

Introduce SonarAnalyzer

[changelog skip]
  • Loading branch information
earlbread committed Nov 11, 2019
1 parent b1265c7 commit ffe6ce1d6931d380eb1ce01650991b2c0226e2fa
Showing with 164 additions and 66 deletions.
  1. +4 −0 Libplanet.Stun.Tests/Libplanet.Stun.Tests.csproj
  2. +0 −1 Libplanet.Stun.Tests/Stun/Crc32Test.cs
  3. +0 −2 Libplanet.Stun.Tests/Stun/Messages/TestStunContext.cs
  4. +4 −0 Libplanet.Stun/Libplanet.Stun.csproj
  5. +0 −1 Libplanet.Stun/Stun/TurnClient.cs
  6. +41 −0 Libplanet.Tests.ruleset
  7. +1 −1 Libplanet.Tests/Blockchain/BlockChainTest.cs
  8. +0 −2 Libplanet.Tests/Blockchain/NullPolicy.cs
  9. +0 −1 Libplanet.Tests/Common/Action/BaseAction.cs
  10. +0 −1 Libplanet.Tests/Common/Action/BattleResult.cs
  11. +0 −3 Libplanet.Tests/Common/Action/Sleep.cs
  12. +0 −1 Libplanet.Tests/Crypto/SymmetricKeyTest.cs
  13. +4 −0 Libplanet.Tests/Libplanet.Tests.csproj
  14. +3 −3 Libplanet.Tests/Net/{FactOnlyTurnAvailable.cs → FactOnlyTurnAvailableAttribute.cs}
  15. +1 −1 Libplanet.Tests/Net/IceServerTest.cs
  16. +0 −1 Libplanet.Tests/Net/Messages/RecentStatesTest.cs
  17. +3 −4 Libplanet.Tests/Net/SwarmTest.cs
  18. +86 −0 Libplanet.ruleset
  19. +0 −2 Libplanet/Action/ActionContext.cs
  20. +2 −0 Libplanet/Action/ActionEvaluation.cs
  21. +0 −1 Libplanet/Action/ActionTypeAttribute.cs
  22. +0 −2 Libplanet/Action/IActionContext.cs
  23. +2 −0 Libplanet/Action/IRandom.cs
  24. +2 −0 Libplanet/Action/UnexpectedlyTerminatedActionException.cs
  25. +0 −1 Libplanet/Blockchain/BlockChain.cs
  26. +2 −0 Libplanet/Blockchain/IncompleteBlockStatesException.cs
  27. +0 −1 Libplanet/Blockchain/Policies/BlockPolicy.cs
  28. +0 −1 Libplanet/Blockchain/Policies/IBlockPolicy.cs
  29. +0 −1 Libplanet/Blocks/Block.cs
  30. +2 −2 Libplanet/Crypto/PrivateKey.cs
  31. +0 −1 Libplanet/Hashcash.cs
  32. +0 −2 Libplanet/KeyStore/InvalidKeyJsonException.cs
  33. +4 −0 Libplanet/Libplanet.csproj
  34. +0 −1 Libplanet/Net/ActionExecutionState.cs
  35. +0 −1 Libplanet/Net/BlockDownloadState.cs
  36. +0 −1 Libplanet/Net/BlockStateDownloadState.cs
  37. +0 −1 Libplanet/Net/BoundPeer.cs
  38. +0 −2 Libplanet/Net/IceServer.cs
  39. +0 −3 Libplanet/Net/Messages/Neighbors.cs
  40. +0 −1 Libplanet/Net/Protocols/IProtocol.cs
  41. +0 −11 Libplanet/Net/Protocols/KademliaProtocol.cs
  42. +0 −2 Libplanet/Net/StateReferenceDownloadState.cs
  43. +1 −3 Libplanet/Net/Swarm.cs
  44. +0 −1 Libplanet/Serialization/BencodexFormatterConverter.cs
  45. +0 −1 Libplanet/Serialization/SerializationInfoExtension.cs
  46. +0 −1 Libplanet/Store/BaseIndex.cs
  47. +0 −1 Libplanet/Store/IStore.cs
  48. +2 −0 Libplanet/Tx/InvalidTxNonceException.cs
@@ -33,6 +33,10 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.0.0.9566">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>
@@ -1,6 +1,5 @@
using System;
using System.Text;
using Libplanet.Stun;
using Xunit;

namespace Libplanet.Stun.Tests
@@ -1,5 +1,3 @@
using Libplanet.Stun;

namespace Libplanet.Stun.Tests.Messages
{
internal class TestStunContext : IStunContext
@@ -31,6 +31,10 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
</IncludeAssets>
</PackageReference>
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.0.0.9566">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>
@@ -145,7 +145,6 @@ public class TurnClient : IStunContext, IDisposable
catch (IOException e)
{
Log.Warning(e, "The connection seems to disconnect before parsing; ignored.");
continue;
}
}
}
@@ -46,4 +46,45 @@
<Rule Id="MEN010" Action="None" />
<Rule Id="MEN011" Action="None" />
</Rules>

<Rules AnalyzerId="SonarAnalyzer" RuleNamespace="SonarAnalyzer">
<!-- Either remove or fill this block of code. -->
<Rule Id="S108" Action="None" />
<!-- Add the default parameter value defined in the overridden method. -->
<Rule Id="S1006" Action="None" />
<!-- Take the required action to fix the issue indicated by this
'FIXME' comment. -->
<Rule Id="S1134" Action="None" />
<!-- Complete the task associated to this 'TODO' comment. -->
<Rule Id="S1135" Action="None" />
<!-- Add a nested comment explaining why this method is empty, throw a
'NotSupportedException' or complete the implementation. -->
<Rule Id="S1186" Action="None" />
<!-- Make field 'readonly'. -->
<Rule Id="S2933" Action="None" />
<!-- Return 'Task' instead. -->
<Rule Id="S3168" Action="None" />
<!-- Make this test method non-'async' or return 'Task'. -->
<Rule Id="S3433" Action="None" />
<!-- Fix this implementation of 'IDisposable' to conform to the dispose
pattern. -->
<Rule Id="S3881" Action="None" />

<!-- Rename parameter 'A' to 'B' to match the interface declaration. -->
<Rule Id="S927" Action="None" />
<!-- Add a 'protected' constructor or the 'static' keyword to the class
declaration. -->
<Rule Id="S1118" Action="None" />
<!-- Remove the unused local variable 'x'. -->
<Rule Id="S1481" Action="None" />
<!-- Parameters to 'Equal' have the same names but not the same order as
the method arguments. -->
<Rule Id="S2234" Action="None" />
<!-- Change the visibility of this constructor to 'protected'. -->
<Rule Id="S3442" Action="None" />
<!-- Seal class or implement 'IEqualityComparer<T>' instead. -->
<Rule Id="S4035" Action="None" />
<!-- Remove this unnecessary null check; 'is' returns false for nulls. -->
<Rule Id="S4201" Action="None" />
</Rules>
</RuleSet>
@@ -1420,7 +1420,7 @@ public void MakeTransaction()
.OrderBy(tx => tx.Nonce)
.ToList();

Assert.Equal(2, txs.Count());
Assert.Equal(2, txs.Count);

var transaction = txs[0];
Assert.Equal(0, transaction.Nonce);
@@ -1,5 +1,3 @@
using System.Collections.Generic;
using System.Linq;
using Libplanet.Action;
using Libplanet.Blockchain;
using Libplanet.Blockchain.Policies;
@@ -1,4 +1,3 @@
using System.Collections.Immutable;
using Bencodex.Types;
using Libplanet.Action;

@@ -3,7 +3,6 @@
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Runtime.Serialization;
using Bencodex.Types;
using Libplanet.Serialization;
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Numerics;
using Bencodex.Types;
using Libplanet.Action;

@@ -1,5 +1,4 @@
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using Libplanet.Crypto;
using Xunit;
@@ -39,6 +39,10 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.XUnit" Version="1.0.7" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.0.0.9566">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>
@@ -3,11 +3,11 @@

namespace Libplanet.Tests.Net
{
public sealed class FactOnlyTurnAvailable : FactAttribute
public sealed class FactOnlyTurnAvailableAttribute : FactAttribute
{
public const string TurnUrlVarName = "TURN_SERVER_URL";

static FactOnlyTurnAvailable()
static FactOnlyTurnAvailableAttribute()
{
string turnUrlStr =
Environment.GetEnvironmentVariable(TurnUrlVarName);
@@ -25,7 +25,7 @@ static FactOnlyTurnAvailable()
}
}

public FactOnlyTurnAvailable()
public FactOnlyTurnAvailableAttribute()
{
if (TurnUri == null)
{
@@ -15,7 +15,7 @@ public async Task CreateTurnClient()
{
var turnUri = new Uri(
Environment.GetEnvironmentVariable(
FactOnlyTurnAvailable.TurnUrlVarName));
FactOnlyTurnAvailableAttribute.TurnUrlVarName));
var userInfo = turnUri.UserInfo.Split(':');
await Assert.ThrowsAsync<ArgumentException>(
async () =>
@@ -4,7 +4,6 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Cryptography;
using Bencodex.Types;
using Libplanet.Crypto;
@@ -24,7 +24,6 @@
using Serilog;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace Libplanet.Tests.Net
{
@@ -1535,9 +1534,9 @@ public async Task AsPeer()
[FactOnlyTurnAvailable(Timeout = Timeout)]
public async Task ExchangeWithIceServer()
{
Uri turnUrl = FactOnlyTurnAvailable.TurnUri;
string username = FactOnlyTurnAvailable.Username;
string password = FactOnlyTurnAvailable.Password;
Uri turnUrl = FactOnlyTurnAvailableAttribute.TurnUri;
string username = FactOnlyTurnAvailableAttribute.Username;
string password = FactOnlyTurnAvailableAttribute.Password;

IEnumerable<IceServer> iceServers = new[]
{
@@ -40,4 +40,90 @@
<Rule Id="MEN010" Action="None" />
<Rule Id="MEN011" Action="None" />
</Rules>

<Rules AnalyzerId="SonarAnalyzer" RuleNamespace="SonarAnalyzer">
<!-- Either remove or fill this block of code. -->
<Rule Id="S108" Action="None" />
<!-- 'System.NullReferenceException' should not be thrown by user code. -->
<Rule Id="S112" Action="None" />
<!-- Rename parameter 'A' to 'B' to match the interface declaration. -->
<Rule Id="S927" Action="None" />
<!-- Add the default parameter value defined in the overridden method. -->
<Rule Id="S1006" Action="None" />
<!-- Add a 'protected' constructor or the 'static' keyword to the class
declaration. -->
<Rule Id="S1118" Action="None" />
<!-- Add an explanation -->
<Rule Id="S1123" Action="None" />
<!-- Take the required action to fix the issue indicated by this
'FIXME' comment. -->
<Rule Id="S1134" Action="None" />
<!-- Complete the task associated to this 'TODO' comment. -->
<Rule Id="S1135" Action="None" />
<!-- Return an empty collection instead of null. -->
<Rule Id="S1168" Action="None" />
<!-- Remove this unused method parameter 'cancellationToken'. -->
<Rule Id="S1172" Action="None" />
<!-- This struct overrides 'GetHashCode' and should therefore also override
'Equals'. -->
<Rule Id="S1206" Action="None" />
<!-- When implementing IComparable<T> or IComparable, you should also
override Equals, <, >, <=, >=, ==, !=. -->
<Rule Id="S1210" Action="None" />
<!-- Use a StringBuilder instead. -->
<Rule Id="S1643" Action="None" />
<!-- Use a 'null' check instead. -->
<Rule Id="S2219" Action="None" />
<!-- variable is null on at least one execution path. -->
<Rule Id="S2259" Action="None" />
<!-- Combine this 'try' with the one starting on line x. -->
<Rule Id="S2327" Action="None" />
<!-- Refactor property into a method, properties should not copy
collections. -->
<Rule Id="S2365" Action="None" />
<!-- Replace the control character at position 1 by its escape sequence
'\n'. -->
<Rule Id="S2479" Action="None" />
<!-- A static field in a generic type is not shared among instances of
different close constructed types. -->
<Rule Id="S2743" Action="None" />
<!-- Make field 'readonly'. -->
<Rule Id="S2933" Action="None" />
<!-- Change the visibility of this constructor to 'protected'. -->
<Rule Id="S3442" Action="None" />
<!-- Fix this implementation of 'IDisposable' to conform to the dispose
pattern. -->
<Rule Id="S3881" Action="None" />
<!-- Update this implementation of 'ISerializable' to conform to the
recommended serialization pattern. -->
<Rule Id="S3925" Action="None" />
<!-- Use a constructor overloads that allows a more meaningful exception
message to be provided. -->
<Rule Id="S3928" Action="None" />
<!-- Initialize all 'static fields' inline and remove the
'static constructor'. -->
<Rule Id="S3963" Action="None" />
<!-- Update this implementation of 'ISerializable' to conform to the
recommended serialization pattern. -->
<Rule Id="S3925" Action="None" />
<!-- Split this method into two, one handling parameters check and the
other handling the asynchronous code. -->
<Rule Id="S4457" Action="None" />

<!-- Merge this if statement with the enclosing one. -->
<Rule Id="S1066" Action="None" />
<!-- Remove the unnecessary Boolean literal(s). -->
<Rule Id="S1125" Action="None" />
<!-- Remove the field '_bucketSize' and declare it as a local variable
in the relevant methods. -->
<Rule Id="S1450" Action="None" />
<!-- Remove the unused local variable 'x'. -->
<Rule Id="S1481" Action="None" />
<!-- Extract this nested ternary operation into an independent
statement. -->
<Rule Id="S3358" Action="None" />
<!-- Seal class 'Transaction' or implement 'IEqualityComparer<T>'
instead. -->
<Rule Id="S4035" Action="None" />
</Rules>
</RuleSet>
@@ -1,5 +1,3 @@
using System;

namespace Libplanet.Action
{
internal class ActionContext : IActionContext
@@ -3,8 +3,10 @@
using System.Collections.Immutable;
using System.Linq;
using System.Security.Cryptography;
#pragma warning disable S1128 // Remove this unnecessary 'using'
using Libplanet.Blockchain.Policies;
using Libplanet.Blocks;
#pragma warning restore S1128 // Remove this unnecessary 'using'
using Libplanet.Tx;

namespace Libplanet.Action
@@ -1,7 +1,6 @@
using System;
using System.Linq;
using System.Reflection;
using Libplanet.Tx;

namespace Libplanet.Action
{
@@ -1,5 +1,3 @@
using System;

namespace Libplanet.Action
{
/// <summary>
@@ -1,4 +1,6 @@
#pragma warning disable S1128 // Remove this unnecessary 'using'
using System;
#pragma warning restore S1128 // Remove this unnecessary 'using'

namespace Libplanet.Action
{
@@ -1,7 +1,9 @@
using System;
using System.Security.Cryptography;
#pragma warning disable S1128 // Remove this unnecessary 'using'
using Libplanet.Blockchain.Policies;
using Libplanet.Blocks;
#pragma warning restore S1128 // Remove this unnecessary 'using'
using Libplanet.Tx;

namespace Libplanet.Action
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
@@ -1,6 +1,8 @@
using System;
using System.Security.Cryptography;
#pragma warning disable S1128
using Libplanet.Blocks;
#pragma warning restore S1128

namespace Libplanet.Blockchain
{
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using Libplanet.Action;
using Libplanet.Blocks;
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using Libplanet.Action;
using Libplanet.Blocks;

@@ -11,7 +11,6 @@
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Libplanet.Action;
using Libplanet.Serialization;
using Libplanet.Tx;
@@ -273,9 +273,9 @@ private static ECPrivateKeyParameters GenerateKeyFromBytes(byte[] privateKey)
);

// For sanity check.
#pragma warning disable SA1312
#pragma warning disable SA1312, S1481
var _ = new PrivateKey(param).PublicKey;
#pragma warning restore SA1312
#pragma warning restore SA1312, S1481
return param;
}

@@ -1,7 +1,6 @@
using System;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;

namespace Libplanet
{

0 comments on commit ffe6ce1

Please sign in to comment.
You can’t perform that action at this time.