Skip to content

Commit 779c137

Browse files
committed
Enable all .NET analyzers.
1 parent 7a069b3 commit 779c137

14 files changed

+34
-8
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ csharp_space_between_method_call_parameter_list_parentheses = false
6767
csharp_space_between_parentheses = false
6868
csharp_preserve_single_line_blocks = true
6969

70+
dotnet_diagnostic.CA1002.severity = none # Do not expose generic lists.
71+
dotnet_diagnostic.CA1003.severity = none # Use generic event handler instances.
72+
dotnet_diagnostic.CA1008.severity = none # Enums should have zero value.
73+
dotnet_diagnostic.CA1014.severity = none # Mark assemblies with CLSCompliantAttribute.
74+
dotnet_diagnostic.CA1031.severity = none # Do not catch general exception types.
75+
dotnet_diagnostic.CA1032.severity = none # Implement standard exception constructors.
76+
dotnet_diagnostic.CA1062.severity = silent # Validate arguments of public methods.
77+
dotnet_diagnostic.CA1307.severity = silent # Specify StringComparison for clarity.
78+
dotnet_diagnostic.CA1508.severity = silent # Avoid dead conditional code.
79+
dotnet_diagnostic.CA1849.severity = none # Call async methods when in an async method.
80+
dotnet_diagnostic.CA2000.severity = none # Use recommended Dispose pattern.
81+
dotnet_diagnostic.CA2100.severity = none # Review SQL queries for security vulnerabilities.
82+
dotnet_diagnostic.CA2213.severity = silent # Disposable fields should be disposed.
83+
dotnet_diagnostic.CA5398.severity = none # Avoid hardcoded SslProtocols values.
7084
dotnet_diagnostic.SA1003.severity = none # Operator must not be followed by whitespace.
7185
dotnet_diagnostic.SA1008.severity = none # Opening parenthesis must not be preceded by a space.
7286
dotnet_diagnostic.SA1009.severity = none # Closing parenthesis must not be followed by a space.

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<RepositoryUrl>https://github.com/mysql-net/MySqlConnector.git</RepositoryUrl>
1515
<DebugType>embedded</DebugType>
1616
<LangVersion>preview</LangVersion>
17-
<AnalysisLevel>latest-recommended</AnalysisLevel>
17+
<AnalysisLevel>latest-all</AnalysisLevel>
1818
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1919
<EmbedUntrackedSources>true</EmbedUntrackedSources>
2020
<GenerateDocumentationFile>true</GenerateDocumentationFile>

src/MySqlConnector/Core/ConnectionSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public ConnectionSettings(MySqlConnectionStringBuilder csb)
8484
throw new NotSupportedException("All specified TLS versions are incompatible with this platform.");
8585
}
8686

87-
if (csb.TlsCipherSuites != "")
87+
if (csb.TlsCipherSuites.Length != 0)
8888
{
8989
#if NETCOREAPP3_0_OR_GREATER
9090
var tlsCipherSuites = new List<TlsCipherSuite>();

src/MySqlConnector/Core/ILoadBalancer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal sealed class RandomLoadBalancer : ILoadBalancer
2626

2727
public IEnumerable<string> LoadBalance(IReadOnlyList<string> hosts)
2828
{
29+
#pragma warning disable CA5394 // Do not use insecure randomness
2930
// from https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
3031
var shuffled = new List<string>(hosts);
3132
for (var i = hosts.Count - 1; i >= 1; i--)

src/MySqlConnector/Core/NormalizedSchema.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ internal sealed class NormalizedSchema
66
{
77
private const string ReQuoted = @"`((?:[^`]|``)+)`";
88
private const string ReUnQuoted = @"([^\.`]+)";
9-
private static readonly string ReEither = $@"(?:{ReQuoted}|{ReUnQuoted})";
9+
private const string ReEither = $@"(?:{ReQuoted}|{ReUnQuoted})";
1010

1111
private static readonly Regex NameRe = new(
1212
$@"^\s*{ReEither}\s*(?:\.\s*{ReEither}\s*)?$",

src/MySqlConnector/Logging/MySqlConnectorLogManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static class MySqlConnectorLogManager
99
/// Allows the <see cref="IMySqlConnectorLoggerProvider"/> to be set for this library. <see cref="Provider"/> can
1010
/// be set once, and must be set before any other library methods are used.
1111
/// </summary>
12+
#pragma warning disable CA1044 // Properties should not be write only
1213
public static IMySqlConnectorLoggerProvider Provider
1314
{
1415
internal get

src/MySqlConnector/MySqlBatch.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ namespace MySqlConnector;
4949
/// </code>
5050
/// </summary>
5151
/// <remarks>The proposed ADO.NET API that <see cref="MySqlBatch"/> is based on is not finalized. This API is experimental and may change in the future.</remarks>
52+
#if NET6_0_OR_GREATER
53+
#pragma warning disable CA1063 // Implement IDisposable Correctly
54+
#endif
5255
public sealed class MySqlBatch :
5356
#if NET6_0_OR_GREATER
5457
DbBatch,
@@ -120,7 +123,7 @@ public MySqlDataReader ExecuteReader(CommandBehavior commandBehavior = CommandBe
120123
#else
121124
public async Task<MySqlDataReader> ExecuteReaderAsync(CancellationToken cancellationToken = default) =>
122125
#endif
123-
(MySqlDataReader) await ExecuteDbDataReaderAsync(CommandBehavior.Default, cancellationToken);
126+
(MySqlDataReader) await ExecuteDbDataReaderAsync(CommandBehavior.Default, cancellationToken).ConfigureAwait(false);
124127

125128
//// TODO: new ExecuteReaderAsync(CommandBehavior)
126129

@@ -340,7 +343,7 @@ private bool NeedsPrepare(out Exception? exception)
340343
exception = new InvalidOperationException("Connection must be Open; current state is {0}".FormatInvariant(Connection.State));
341344
else if (BatchCommands.Count == 0)
342345
exception = new InvalidOperationException("BatchCommands must contain a command");
343-
else if (Connection?.HasActiveReader ?? false)
346+
else if (Connection.HasActiveReader)
344347
exception = new InvalidOperationException("Cannot call Prepare when there is an open DataReader for this command; it must be closed first.");
345348
else
346349
exception = GetExceptionForInvalidCommands();

src/MySqlConnector/MySqlCommand.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,6 @@ private bool IsValid([NotNullWhen(false)] out Exception? exception)
446446
MySqlParameterCollection? IMySqlCommand.OutParameters { get; set; }
447447
MySqlParameter? IMySqlCommand.ReturnParameter { get; set; }
448448

449-
private static readonly IMySqlConnectorLogger Log = MySqlConnectorLogManager.CreateLogger(nameof(MySqlCommand));
450-
451449
private readonly int m_commandId;
452450
private bool m_isDisposed;
453451
private MySqlConnection? m_connection;

src/MySqlConnector/MySqlConnectionProtocol.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace MySqlConnector;
22

3+
#pragma warning disable CA1027 // Mark enums with FlagsAttribute
34
#pragma warning disable CA1069 // Enum values should not be duplicated
45
/// <summary>
56
/// Specifies the type of connection to make to the server.

src/MySqlConnector/MySqlConnectionStringBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,8 @@ private static void AddOption(MySqlConnectionStringOption option)
962962
s_options.Add(key, option);
963963
}
964964

965+
#pragma warning disable CA1065 // Do not raise exceptions in unexpected locations
966+
#pragma warning disable CA1810 // Initialize reference type static fields inline
965967
static MySqlConnectionStringOption()
966968
{
967969
s_options = new(StringComparer.OrdinalIgnoreCase);

0 commit comments

Comments
 (0)