Skip to content

Commit

Permalink
Merge branch 'main' into fix/cli-field-enum-value
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Oct 25, 2024
2 parents 47a71ba + f4e77da commit 74c4ad2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix analyzer [RCS1090](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1090) ([PR](https://github.com/dotnet/roslynator/pull/1566))
- [CLI] Fix command `generate-doc` ([PR](https://github.com/dotnet/roslynator/pull/1568))

### Change

- Update analyzer [RCS1077](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1077) ([PR](https://github.com/dotnet/roslynator/pull/1653))
Expand Down
10 changes: 9 additions & 1 deletion src/Analyzers/CSharp/Analysis/ConfigureAwaitAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Expand Down Expand Up @@ -87,7 +88,7 @@ private static void RemoveCallToConfigureAwait(SyntaxNodeAnalysisContext context
// ^^^^^^^^^^^^^^^^^^^^^^
SimpleMemberInvocationExpressionInfo invocationInfo = SyntaxInfo.SimpleMemberInvocationExpressionInfo(expression);

if (!IsConfigureAwait(invocationInfo))
if (!IsConfigureAwaitFalse(invocationInfo, context.SemanticModel, context.CancellationToken))
return;

ITypeSymbol awaitedType = context.SemanticModel.GetTypeSymbol(expression, context.CancellationToken);
Expand Down Expand Up @@ -133,6 +134,13 @@ private static bool IsConfigureAwait(SimpleMemberInvocationExpressionInfo invoca
&& invocationInfo.Arguments.Count == 1;
}

private static bool IsConfigureAwaitFalse(SimpleMemberInvocationExpressionInfo invocationInfo, SemanticModel semanticModel, CancellationToken cancellationToken)
{
return IsConfigureAwait(invocationInfo)
&& semanticModel.GetConstantValue(invocationInfo.Arguments[0].Expression, cancellationToken).Value is bool boolValue
&& !boolValue;
}

private static bool IsConfigureAwaitable(ITypeSymbol typeSymbol, SemanticModel semanticModel, int position)
{
return semanticModel.LookupSymbols(position, typeSymbol, "ConfigureAwait", includeReducedExtensionMethods: true)
Expand Down
1 change: 1 addition & 0 deletions src/Documentation/TextUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static string RemoveLeadingTrailingNewLine(
}

if (trailingNewLine
&& length > startIndex
&& s[length - 1] == '\n')
{
length--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,23 @@ public Awaitable ConfigureAwait(bool continueOnCapturedContext)
return default(Awaitable);
}
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ConfigureAwait)]
public async Task TestNoDiagnostic_ConfigureAwaitTrue()
{
await VerifyNoDiagnosticAsync(@"
using System.Threading.Tasks;
class C
{
async Task M()
{
Task task = default;
await task.ConfigureAwait(true);
}
}
");
}
}

0 comments on commit 74c4ad2

Please sign in to comment.