Skip to content

Commit

Permalink
MA0003 excludes ValueTask.FromResult (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou authored Jul 31, 2023
1 parent 8ba828c commit d3744b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Meziantou.Analyzer/Rules/NamedParameterAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ bool IsParams(SyntaxNode node)
if (IsMethod(invokedMethodSymbol, taskTokenType, nameof(Task.FromResult)))
return;
if (IsMethod(invokedMethodSymbol, valueTaskTokenType, nameof(Task.FromResult)))
return;
if (IsMethod(invokedMethodSymbol, taskCompletionSourceType, nameof(TaskCompletionSource<object>.SetResult)))
return;
Expand Down
18 changes: 18 additions & 0 deletions tests/Meziantou.Analyzer.Test/Rules/NamedParameterAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,24 @@ await CreateProjectBuilder()
.WithSourceCode(SourceCode)
.ValidateAsync();
}

[Fact]
public async Task ValueTask_FromResult_ShouldNotReportDiagnostic()
{
const string SourceCode = @"
class TypeName
{
public void Test()
{
_ = System.Threading.Tasks.ValueTask.FromResult<System.ReadOnlyMemory<byte>?>(null);
}
}
";
await CreateProjectBuilder()
.WithTargetFramework(TargetFramework.Net6_0)
.WithSourceCode(SourceCode)
.ValidateAsync();
}

[Fact]
public async Task Expression_ShouldNotReportDiagnostic()
Expand Down

0 comments on commit d3744b9

Please sign in to comment.