Skip to content

Commit

Permalink
Update analyzer versions and fix violations (#34041)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Mar 25, 2020
1 parent 379a3c1 commit d1006ce
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions eng/Analyzers.props
Original file line number Diff line number Diff line change
Expand Up @@ -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>
3 changes: 2 additions & 1 deletion eng/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down Expand Up @@ -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 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal override IPEndPoint LocalEndPoint

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal override async ValueTask<QuicConnectionProvider> AcceptConnectionAsync(

await connection.SetSecurityConfigForConnection(_sslOptions.ServerCertificate!,
_options.CertificateFilePath,
_options.PrivateKeyFilePath);
_options.PrivateKeyFilePath).ConfigureAwait(false);

if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
return connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ internal override async ValueTask WriteAsync(ReadOnlySequence<byte> buffers, boo

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();

Expand All @@ -149,9 +149,9 @@ internal override async ValueTask WriteAsync(ReadOnlyMemory<ReadOnlyMemory<byte>

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();

Expand All @@ -164,9 +164,9 @@ internal override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, bool e

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();

Expand Down Expand Up @@ -209,7 +209,7 @@ private async ValueTask<CancellationTokenRegistration> HandleWriteStartState(Can
// Make sure start has completed
if (!_started)
{
await _sendResettableCompletionSource.GetTypelessValueTask();
await _sendResettableCompletionSource.GetTypelessValueTask().ConfigureAwait(false);
_started = true;
}

Expand Down Expand Up @@ -277,7 +277,7 @@ internal override async ValueTask<int> ReadAsync(Memory<byte> destination, Cance
// 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,11 @@ public string ConnectionString
_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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public override void Write(byte[] array, int offset, int count)
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ await _stream.ReadAsync(new Memory<byte>(tempInputBuffer, _inputBufferIndex, num
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
Expand Down Expand Up @@ -554,7 +554,7 @@ private async ValueTask WriteAsyncCore(byte[] buffer, int offset, int count, Can
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);

Expand Down Expand Up @@ -584,7 +584,7 @@ private async ValueTask WriteAsyncCore(byte[] buffer, int offset, int count, Can

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
{
Expand All @@ -611,7 +611,7 @@ private async ValueTask WriteAsyncCore(byte[] buffer, int offset, int count, Can
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);

Expand Down

0 comments on commit d1006ce

Please sign in to comment.