Skip to content

Commit

Permalink
Fix MA0120 doesn't report for IJSRuntime.InvokeAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou committed Oct 23, 2022
1 parent add8f70 commit 208c1dd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private sealed class AnalyzerContext
{
public AnalyzerContext(Compilation compilation)
{
IJSInProcessRuntimeSymbol = compilation.GetBestTypeByMetadataName("Microsoft.JSInterop.IJSRuntime");
IJSRuntimeSymbol = compilation.GetBestTypeByMetadataName("Microsoft.JSInterop.IJSRuntime");
JSRuntimeExtensionsSymbol = compilation.GetBestTypeByMetadataName("Microsoft.JSInterop.JSRuntimeExtensions");
IJSInProcessRuntimeSymbol = compilation.GetBestTypeByMetadataName("Microsoft.JSInterop.IJSInProcessRuntime");
JSInProcessRuntimeExtensionsSymbol = compilation.GetBestTypeByMetadataName("Microsoft.JSInterop.JSInProcessRuntimeExtensions");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,47 @@ async Task A()
await [||]js.InvokeAsync<string>(""dummy"");
}
}
")
.ValidateAsync();
}

[Fact]
public async Task IJSRuntime_InvokeAsyncExplicit_ReturnNotUsed()
{
await CreateProjectBuilder()
.WithSourceCode(@"
using System.Threading.Tasks;
using Microsoft.JSInterop;
class Sample
{
async Task A()
{
IJSRuntime js = null;
await [||]JSRuntimeExtensions.InvokeAsync<string>(js, """", System.Array.Empty<object>());
}
}
")
.ValidateAsync();
}

[Fact]
public async Task IJSRuntime_InvokeAsyncExplicitWithCancellationToken_ReturnNotUsed()
{
await CreateProjectBuilder()
.WithSourceCode(@"
using System.Threading;
using System.Threading.Tasks;
using Microsoft.JSInterop;
class Sample
{
async Task A()
{
IJSRuntime js = null;
await [||]js.InvokeAsync<string>(""dummy"", CancellationToken.None, new object?[1] { null });
}
}
")
.ValidateAsync();
}
Expand Down

0 comments on commit 208c1dd

Please sign in to comment.