Update analyzer versions and fix violations (#34041)
authorStephen Toub <stoub@microsoft.com>
Wed, 25 Mar 2020 02:00:45 +0000 (22:00 -0400)
committerGitHub <noreply@github.com>
Wed, 25 Mar 2020 02:00:45 +0000 (22:00 -0400)
eng/Analyzers.props
eng/CodeAnalysis.ruleset
src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/MsQuic/MsQuicConnection.cs
src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/MsQuic/MsQuicListener.cs
src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/MsQuic/MsQuicStream.cs
src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs
src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs
src/libraries/System.Security.Cryptography.Primitives/src/System/Security/Cryptography/CryptoStream.cs

index 534d38a..d822baf 100644 (file)
@@ -4,7 +4,7 @@
   </PropertyGroup>
   <ItemGroup Condition="'$(EnableAnalyzers)' == 'true'">
     <PackageReference Include="Microsoft.DotNet.CodeAnalysis" Version="$(MicrosoftDotNetCodeAnalysisVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
-    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8" PrivateAssets="all" />
-    <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.113" PrivateAssets="all" />
+    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0-beta2.final" PrivateAssets="all" />
+    <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164" PrivateAssets="all" />
   </ItemGroup>
 </Project>
index e2c3f71..0fccc15 100644 (file)
@@ -41,7 +41,7 @@
       <Rule Id="CA1066" Action="None" />             <!-- Type {0} should implement IEquatable<T> because it overrides Equals -->
       <Rule Id="CA1067" Action="None" />             <!-- Override Object.Equals(object) when implementing IEquatable<T> -->
       <Rule Id="CA1068" Action="None" />             <!-- CancellationToken parameters must come last -->
-      <Rule Id="CA1069" Action="Warning" />          <!-- Enums values should not be duplicated -->
+      <Rule Id="CA1069" Action="None" />             <!-- Enums values should not be duplicated -->
       <Rule Id="CA1200" Action="Warning" />          <!-- Avoid using cref tags with a prefix -->
       <Rule Id="CA1303" Action="None" />             <!-- Do not pass literals as localized parameters -->
       <Rule Id="CA1304" Action="None" />             <!-- Specify CultureInfo -->
@@ -98,6 +98,7 @@
       <Rule Id="CA2010" Action="None" />             <!-- Always consume the value returned by methods marked with PreserveSigAttribute -->
       <Rule Id="CA2011" Action="Warning" />          <!-- Avoid infinite recursion -->
       <Rule Id="CA2012" Action="Warning" />          <!-- Use ValueTasks correctly -->
+      <Rule Id="CA2013" Action="Warning" />          <!-- Do not use ReferenceEquals with value types -->
       <Rule Id="CA2100" Action="None" />             <!-- Review SQL queries for security vulnerabilities -->
       <Rule Id="CA2101" Action="None" />             <!-- Specify marshaling for P/Invoke string arguments -->
       <Rule Id="CA2119" Action="None" />             <!-- Seal methods that satisfy private interfaces -->
index 0fdecc6..b7bd07d 100644 (file)
@@ -89,7 +89,7 @@ namespace System.Net.Quic.Implementations.MsQuic
 
         internal async ValueTask SetSecurityConfigForConnection(X509Certificate cert, string? certFilePath, string? privateKeyFilePath)
         {
-            _securityConfig = await MsQuicApi.Api.CreateSecurityConfig(cert, certFilePath, privateKeyFilePath);
+            _securityConfig = await MsQuicApi.Api.CreateSecurityConfig(cert, certFilePath, privateKeyFilePath).ConfigureAwait(false);
             // TODO this isn't being set correctly
             MsQuicParameterHelpers.SetSecurityConfig(MsQuicApi.Api, _ptr, (uint)QUIC_PARAM_LEVEL.CONNECTION, (uint)QUIC_PARAM_CONN.SEC_CONFIG, _securityConfig!.NativeObjPtr);
         }
index e87126b..2418a71 100644 (file)
@@ -80,7 +80,7 @@ namespace System.Net.Quic.Implementations.MsQuic
 
             await connection.SetSecurityConfigForConnection(_sslOptions.ServerCertificate!,
                 _options.CertificateFilePath,
-                _options.PrivateKeyFilePath);
+                _options.PrivateKeyFilePath).ConfigureAwait(false);
 
             if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
             return connection;
index b8b6282..6eed08f 100644 (file)
@@ -129,9 +129,9 @@ namespace System.Net.Quic.Implementations.MsQuic
 
             ThrowIfDisposed();
 
-            using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken);
+            using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken).ConfigureAwait(false);
 
-            await SendReadOnlySequenceAsync(buffers, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE);
+            await SendReadOnlySequenceAsync(buffers, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE).ConfigureAwait(false);
 
             HandleWriteCompletedState();
 
@@ -149,9 +149,9 @@ namespace System.Net.Quic.Implementations.MsQuic
 
             ThrowIfDisposed();
 
-            using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken);
+            using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken).ConfigureAwait(false);
 
-            await SendReadOnlyMemoryListAsync(buffers, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE);
+            await SendReadOnlyMemoryListAsync(buffers, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE).ConfigureAwait(false);
 
             HandleWriteCompletedState();
 
@@ -164,9 +164,9 @@ namespace System.Net.Quic.Implementations.MsQuic
 
             ThrowIfDisposed();
 
-            using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken);
+            using CancellationTokenRegistration registration = await HandleWriteStartState(cancellationToken).ConfigureAwait(false);
 
-            await SendReadOnlyMemoryAsync(buffer, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE);
+            await SendReadOnlyMemoryAsync(buffer, endStream ? QUIC_SEND_FLAG.FIN : QUIC_SEND_FLAG.NONE).ConfigureAwait(false);
 
             HandleWriteCompletedState();
 
@@ -209,7 +209,7 @@ namespace System.Net.Quic.Implementations.MsQuic
             // Make sure start has completed
             if (!_started)
             {
-                await _sendResettableCompletionSource.GetTypelessValueTask();
+                await _sendResettableCompletionSource.GetTypelessValueTask().ConfigureAwait(false);
                 _started = true;
             }
 
@@ -277,7 +277,7 @@ namespace System.Net.Quic.Implementations.MsQuic
             // TODO there could potentially be a perf gain by storing the buffer from the inital read
             // This reduces the amount of async calls, however it makes it so MsQuic holds onto the buffers
             // longer than it needs to. We will need to benchmark this.
-            int length = (int)await _receiveResettableCompletionSource.GetValueTask();
+            int length = (int)await _receiveResettableCompletionSource.GetValueTask().ConfigureAwait(false);
 
             int actual = Math.Min(length, destination.Length);
 
index 3658c6d..fea7311 100644 (file)
@@ -170,8 +170,11 @@ namespace System.Data.Common
                     _connectionString = null;
                 }
                 catch (ArgumentException)
-                { // restore original string
+                {
+                    // restore original string
+#pragma warning disable CA2011 // avoid infinite recursion, but this isn't that; it's restoring the original string
                     ConnectionString = originalValue;
+#pragma warning restore CA2011
                     _connectionString = originalValue;
                     throw;
                 }
index 9221730..ee140ed 100644 (file)
@@ -426,7 +426,7 @@ namespace System.IO
             ValidateReadWriteArgs(array, offset, count);
             if (_useAsyncIO)
             {
-                WriteAsyncInternal(new ReadOnlyMemory<byte>(array, offset, count), CancellationToken.None).GetAwaiter().GetResult();
+                WriteAsyncInternal(new ReadOnlyMemory<byte>(array, offset, count), CancellationToken.None).AsTask().GetAwaiter().GetResult();
             }
             else
             {
index 5dc2df4..3334ff1 100644 (file)
@@ -404,7 +404,7 @@ namespace System.Security.Cryptography
                 while (_inputBufferIndex < _inputBlockSize)
                 {
                     amountRead = useAsync ?
-                        await _stream.ReadAsync(new Memory<byte>(_inputBuffer, _inputBufferIndex, _inputBlockSize - _inputBufferIndex), cancellationToken) : // ConfigureAwait not needed, as useAsync is only true if we're already on a TP thread
+                        await _stream.ReadAsync(new Memory<byte>(_inputBuffer, _inputBufferIndex, _inputBlockSize - _inputBufferIndex), cancellationToken).ConfigureAwait(false) :
                         _stream.Read(_inputBuffer, _inputBufferIndex, _inputBlockSize - _inputBufferIndex);
 
                     // first, check to see if we're at the end of the input stream
@@ -554,7 +554,7 @@ namespace System.Security.Cryptography
                 numOutputBytes = _transform.TransformBlock(_inputBuffer, 0, _inputBlockSize, _outputBuffer, 0);
                 // write out the bytes we just got
                 if (useAsync)
-                    await _stream.WriteAsync(new ReadOnlyMemory<byte>(_outputBuffer, 0, numOutputBytes), cancellationToken); // ConfigureAwait not needed, as useAsync is only true if we're already on a TP thread
+                    await _stream.WriteAsync(new ReadOnlyMemory<byte>(_outputBuffer, 0, numOutputBytes), cancellationToken).ConfigureAwait(false);
                 else
                     _stream.Write(_outputBuffer, 0, numOutputBytes);
 
@@ -584,7 +584,7 @@ namespace System.Security.Cryptography
 
                             if (useAsync)
                             {
-                                await _stream.WriteAsync(new ReadOnlyMemory<byte>(tempOutputBuffer, 0, numOutputBytes), cancellationToken); // ConfigureAwait not needed, as useAsync is only true if we're already on a TP thread
+                                await _stream.WriteAsync(new ReadOnlyMemory<byte>(tempOutputBuffer, 0, numOutputBytes), cancellationToken).ConfigureAwait(false);
                             }
                             else
                             {
@@ -611,7 +611,7 @@ namespace System.Security.Cryptography
                         numOutputBytes = _transform.TransformBlock(buffer, currentInputIndex, _inputBlockSize, _outputBuffer, 0);
 
                         if (useAsync)
-                            await _stream.WriteAsync(new ReadOnlyMemory<byte>(_outputBuffer, 0, numOutputBytes), cancellationToken); // ConfigureAwait not needed, as useAsync is only true if we're already on a TP thread
+                            await _stream.WriteAsync(new ReadOnlyMemory<byte>(_outputBuffer, 0, numOutputBytes), cancellationToken).ConfigureAwait(false);
                         else
                             _stream.Write(_outputBuffer, 0, numOutputBytes);