From e8cdfd6f6f8d529ac45600f60b77a7abb95b268d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Jun 2025 02:42:45 +0000 Subject: [PATCH 1/9] Initial plan for issue From b82695bc0f24c882f13fd1e901f7754f8aee8fe7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Jun 2025 02:48:19 +0000 Subject: [PATCH 2/9] Initial setup: Fix .NET SDK version for development environment Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com> --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index dba0cdca8..bcbfbe02f 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "9.0.300", + "version": "8.0.116", "rollForward": "patch", "allowPrerelease": false }, From 6e9b7dc30b7c4d46b184512d63eee44d31ed8aa9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Jun 2025 02:52:50 +0000 Subject: [PATCH 3/9] Implement VSTHRD103 AdditionalFiles support for excluding APIs - Add new file pattern for exclusion files in CommonInterest.cs - Modify VSTHRD103 analyzer to read additional files and check exclusions - Add comprehensive test cases for the new exclusion functionality - Update documentation to describe the new configuration option Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com> --- docfx/analyzers/VSTHRD103.md | 9 +++ docfx/analyzers/configuration.md | 13 ++++ .../VSTHRD103UseAsyncOptionAnalyzer.cs | 41 +++++++++--- .../CommonInterest.cs | 1 + ...yncMethodsToExcludeFromVSTHRD103.mocks.txt | 3 + .../VSTHRD103UseAsyncOptionAnalyzerTests.cs | 67 +++++++++++++++++++ 6 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 test/Microsoft.VisualStudio.Threading.Analyzers.Tests/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.mocks.txt diff --git a/docfx/analyzers/VSTHRD103.md b/docfx/analyzers/VSTHRD103.md index 348032057..120310cf3 100644 --- a/docfx/analyzers/VSTHRD103.md +++ b/docfx/analyzers/VSTHRD103.md @@ -27,3 +27,12 @@ async Task DoAsync() await file.ReadAsync(buffer, 0, 10); } ``` + +## Configuration + +This analyzer can be configured to exclude specific APIs from generating diagnostics. +Some APIs may have async versions that are less efficient or inappropriate for certain use cases. + +See our [configuration](configuration.md) topic to learn how to exclude specific methods +using the `vs-threading.SyncMethodsToExcludeFromVSTHRD103.txt` file. +``` diff --git a/docfx/analyzers/configuration.md b/docfx/analyzers/configuration.md index 75d63c693..77acf4d82 100644 --- a/docfx/analyzers/configuration.md +++ b/docfx/analyzers/configuration.md @@ -79,3 +79,16 @@ thread. **Line format:** `[Namespace.TypeName]::MethodName` **Sample:** `[System.Windows.Threading.Dispatcher]::Invoke` + +## Methods to exclude from VSTHRD103 checks + +The VSTHRD103 analyzer flags calls to synchronous methods where asynchronous equivalents exist, +when in an async context. Sometimes certain APIs have async versions but those async versions +are significantly slower, less efficient, or simply not preferred. These methods can be +excluded from VSTHRD103 analysis by specifying them in a configuration file. + +**Filename:** `vs-threading.SyncMethodsToExcludeFromVSTHRD103.txt` + +**Line format:** `[Namespace.TypeName]::MethodName` + +**Sample:** `[System.Data.SqlClient.SqlDataReader]::Read` diff --git a/src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/VSTHRD103UseAsyncOptionAnalyzer.cs b/src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/VSTHRD103UseAsyncOptionAnalyzer.cs index 46cde9c5a..51aa5526b 100644 --- a/src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/VSTHRD103UseAsyncOptionAnalyzer.cs +++ b/src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/VSTHRD103UseAsyncOptionAnalyzer.cs @@ -68,17 +68,30 @@ public override void Initialize(AnalysisContext context) context.EnableConcurrentExecution(); context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze); - context.RegisterCodeBlockStartAction(ctxt => + context.RegisterCompilationStartAction(compilationStartContext => { - ctxt.RegisterSyntaxNodeAction(Utils.DebuggableWrapper(MethodAnalyzer.AnalyzeInvocation), SyntaxKind.InvocationExpression); - ctxt.RegisterSyntaxNodeAction(Utils.DebuggableWrapper(MethodAnalyzer.AnalyzePropertyGetter), SyntaxKind.SimpleMemberAccessExpression); - ctxt.RegisterSyntaxNodeAction(Utils.DebuggableWrapper(MethodAnalyzer.AnalyzeConditionalAccessExpression), SyntaxKind.ConditionalAccessExpression); + var excludedMethods = CommonInterest.ReadMethods(compilationStartContext.Options, CommonInterest.FileNamePatternForSyncMethodsToExcludeFromVSTHRD103, compilationStartContext.CancellationToken).ToImmutableArray(); + + compilationStartContext.RegisterCodeBlockStartAction(ctxt => + { + var methodAnalyzer = new MethodAnalyzer(excludedMethods); + ctxt.RegisterSyntaxNodeAction(Utils.DebuggableWrapper(methodAnalyzer.AnalyzeInvocation), SyntaxKind.InvocationExpression); + ctxt.RegisterSyntaxNodeAction(Utils.DebuggableWrapper(methodAnalyzer.AnalyzePropertyGetter), SyntaxKind.SimpleMemberAccessExpression); + ctxt.RegisterSyntaxNodeAction(Utils.DebuggableWrapper(methodAnalyzer.AnalyzeConditionalAccessExpression), SyntaxKind.ConditionalAccessExpression); + }); }); } private class MethodAnalyzer { - internal static void AnalyzePropertyGetter(SyntaxNodeAnalysisContext context) + private readonly ImmutableArray excludedMethods; + + public MethodAnalyzer(ImmutableArray excludedMethods) + { + this.excludedMethods = excludedMethods; + } + + internal void AnalyzePropertyGetter(SyntaxNodeAnalysisContext context) { var memberAccessSyntax = (MemberAccessExpressionSyntax)context.Node; if (IsInTaskReturningMethodOrDelegate(context)) @@ -87,7 +100,7 @@ internal static void AnalyzePropertyGetter(SyntaxNodeAnalysisContext context) } } - internal static void AnalyzeConditionalAccessExpression(SyntaxNodeAnalysisContext context) + internal void AnalyzeConditionalAccessExpression(SyntaxNodeAnalysisContext context) { var conditionalAccessSyntax = (ConditionalAccessExpressionSyntax)context.Node; if (IsInTaskReturningMethodOrDelegate(context)) @@ -101,7 +114,7 @@ internal static void AnalyzeConditionalAccessExpression(SyntaxNodeAnalysisContex } } - internal static void AnalyzeInvocation(SyntaxNodeAnalysisContext context) + internal void AnalyzeInvocation(SyntaxNodeAnalysisContext context) { if (IsInTaskReturningMethodOrDelegate(context)) { @@ -134,6 +147,12 @@ internal static void AnalyzeInvocation(SyntaxNodeAnalysisContext context) && m.Name != invocationDeclaringMethod?.Identifier.Text && m.HasAsyncCompatibleReturnType()) { + // Check if this method is excluded from VSTHRD103 diagnostics + if (this.excludedMethods.Contains(methodSymbol)) + { + return; + } + // An async alternative exists. ImmutableDictionary? properties = ImmutableDictionary.Empty .Add(AsyncMethodKeyName, asyncMethodName); @@ -197,7 +216,7 @@ private static bool IsInTaskReturningMethodOrDelegate(SyntaxNodeAnalysisContext return methodSymbol?.HasAsyncCompatibleReturnType() is true; } - private static bool InspectMemberAccess(SyntaxNodeAnalysisContext context, ExpressionSyntax memberName, IEnumerable problematicMethods) + private bool InspectMemberAccess(SyntaxNodeAnalysisContext context, ExpressionSyntax memberName, IEnumerable problematicMethods) { ISymbol? memberSymbol = context.SemanticModel.GetSymbolInfo(memberName, context.CancellationToken).Symbol; if (memberSymbol is object) @@ -206,6 +225,12 @@ private static bool InspectMemberAccess(SyntaxNodeAnalysisContext context, Expre { if (item.Method.IsMatch(memberSymbol)) { + // Check if this method is excluded from VSTHRD103 diagnostics + if (this.excludedMethods.Contains(memberSymbol)) + { + return false; + } + Location? location = memberName.GetLocation(); ImmutableDictionary? properties = ImmutableDictionary.Empty .Add(ExtensionMethodNamespaceKeyName, item.ExtensionMethodNamespace is object ? string.Join(".", item.ExtensionMethodNamespace) : string.Empty); diff --git a/src/Microsoft.VisualStudio.Threading.Analyzers/CommonInterest.cs b/src/Microsoft.VisualStudio.Threading.Analyzers/CommonInterest.cs index ef21f9f90..82e17d2e5 100644 --- a/src/Microsoft.VisualStudio.Threading.Analyzers/CommonInterest.cs +++ b/src/Microsoft.VisualStudio.Threading.Analyzers/CommonInterest.cs @@ -25,6 +25,7 @@ public static class CommonInterest public static readonly Regex FileNamePatternForMembersRequiringMainThread = new Regex(@"^vs-threading\.MembersRequiringMainThread(\..*)?.txt$", FileNamePatternRegexOptions); public static readonly Regex FileNamePatternForMethodsThatAssertMainThread = new Regex(@"^vs-threading\.MainThreadAssertingMethods(\..*)?.txt$", FileNamePatternRegexOptions); public static readonly Regex FileNamePatternForMethodsThatSwitchToMainThread = new Regex(@"^vs-threading\.MainThreadSwitchingMethods(\..*)?.txt$", FileNamePatternRegexOptions); + public static readonly Regex FileNamePatternForSyncMethodsToExcludeFromVSTHRD103 = new Regex(@"^vs-threading\.SyncMethodsToExcludeFromVSTHRD103(\..*)?.txt$", FileNamePatternRegexOptions); public static readonly IEnumerable JTFSyncBlockers = new[] { diff --git a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.mocks.txt b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.mocks.txt new file mode 100644 index 000000000..570c8bfbd --- /dev/null +++ b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.mocks.txt @@ -0,0 +1,3 @@ +# Test exclusions for VSTHRD103 analyzer +[System.Data.SqlClient.SqlDataReader]::Read +[TestNamespace.TestClass]::SlowSyncMethod \ No newline at end of file diff --git a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs index b4ff2da62..14947d5f3 100644 --- a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs @@ -1339,6 +1339,73 @@ void Bar() {} await CSVerify.VerifyAnalyzerAsync(test); } + [Fact] + public async Task SyncMethodCallInAsyncMethod_ExcludedViaAdditionalFiles_GeneratesNoWarning() + { + var test = @" +using System.Threading.Tasks; + +class Test { + async Task T() { + TestNamespace.TestClass.SlowSyncMethod(); + } +} + +namespace TestNamespace { + class TestClass { + public static void SlowSyncMethod() { } + public static Task SlowSyncMethodAsync() => Task.CompletedTask; + } +} +"; + + // No diagnostic expected because SlowSyncMethod is excluded via AdditionalFiles + await CSVerify.VerifyAnalyzerAsync(test); + } + + [Fact] + public async Task SyncMethodCallInAsyncMethod_NotExcludedViaAdditionalFiles_GeneratesWarning() + { + var test = @" +using System.Threading.Tasks; + +class Test { + async Task T() { + TestNamespace.TestClass.NotExcludedMethod(); + } +} + +namespace TestNamespace { + class TestClass { + public static void NotExcludedMethod() { } + public static Task NotExcludedMethodAsync() => Task.CompletedTask; + } +} +"; + + DiagnosticResult expected = CSVerify.Diagnostic(Descriptor).WithSpan(6, 9, 6, 26).WithArguments("NotExcludedMethod", "NotExcludedMethodAsync"); + await CSVerify.VerifyAnalyzerAsync(test, expected); + } + + [Fact] + public async Task SqlDataReaderRead_ExcludedViaAdditionalFiles_GeneratesNoWarning() + { + var test = @" +using System.Threading.Tasks; + +class Test { + async Task T() { + System.Data.SqlClient.SqlDataReader reader = null; + reader.Read(); + } +} +"; + + // No diagnostic expected because SqlDataReader.Read is excluded via AdditionalFiles + // Note: This test might need additional setup for SqlClient references + await CSVerify.VerifyAnalyzerAsync(test); + } + private DiagnosticResult CreateDiagnostic(int line, int column, int length, string methodName) => CSVerify.Diagnostic(DescriptorNoAlternativeMethod).WithSpan(line, column, line, column + length).WithArguments(methodName); From dfec027eb105f7898bd77274e4fe050b6b949e94 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Jun 2025 02:54:50 +0000 Subject: [PATCH 4/9] Add additional test cases and configuration for VSTHRD103 exclusions - Add test for JoinableTaskFactory.Run exclusion - Include JTF.Run in test exclusion file - Add nuget.org as fallback package source for connectivity issues Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com> --- nuget.config | 1 + ...yncMethodsToExcludeFromVSTHRD103.mocks.txt | 3 ++- .../VSTHRD103UseAsyncOptionAnalyzerTests.cs | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/nuget.config b/nuget.config index 35d15c110..3e9104cd8 100644 --- a/nuget.config +++ b/nuget.config @@ -6,6 +6,7 @@ + diff --git a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.mocks.txt b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.mocks.txt index 570c8bfbd..4907330b4 100644 --- a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.mocks.txt +++ b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.mocks.txt @@ -1,3 +1,4 @@ # Test exclusions for VSTHRD103 analyzer [System.Data.SqlClient.SqlDataReader]::Read -[TestNamespace.TestClass]::SlowSyncMethod \ No newline at end of file +[TestNamespace.TestClass]::SlowSyncMethod +[Microsoft.VisualStudio.Threading.JoinableTaskFactory]::Run \ No newline at end of file diff --git a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs index 14947d5f3..98ed738bf 100644 --- a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs @@ -1406,6 +1406,25 @@ async Task T() { await CSVerify.VerifyAnalyzerAsync(test); } + [Fact] + public async Task JTFRun_ExcludedViaAdditionalFiles_GeneratesNoWarning() + { + var test = @" +using System.Threading.Tasks; +using Microsoft.VisualStudio.Threading; + +class Test { + async Task T() { + JoinableTaskFactory jtf = null; + jtf.Run(() => Task.CompletedTask); + } +} +"; + + // No diagnostic expected because JoinableTaskFactory.Run is excluded via AdditionalFiles + await CSVerify.VerifyAnalyzerAsync(test); + } + private DiagnosticResult CreateDiagnostic(int line, int column, int length, string methodName) => CSVerify.Diagnostic(DescriptorNoAlternativeMethod).WithSpan(line, column, line, column + length).WithArguments(methodName); From b2f644e0e8a7d4b5ace4895446ce0d276cce29de Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Jun 2025 03:07:08 +0000 Subject: [PATCH 5/9] Address PR feedback: revert global.json, use diagnostic markers, remove problematic test Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com> --- .../VSTHRD103UseAsyncOptionAnalyzerTests.cs | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs index 98ed738bf..56264fc05 100644 --- a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs @@ -1371,7 +1371,7 @@ public async Task SyncMethodCallInAsyncMethod_NotExcludedViaAdditionalFiles_Gene class Test { async Task T() { - TestNamespace.TestClass.NotExcludedMethod(); + [|TestNamespace.TestClass.NotExcludedMethod()|]; } } @@ -1383,26 +1383,6 @@ public static void NotExcludedMethod() { } } "; - DiagnosticResult expected = CSVerify.Diagnostic(Descriptor).WithSpan(6, 9, 6, 26).WithArguments("NotExcludedMethod", "NotExcludedMethodAsync"); - await CSVerify.VerifyAnalyzerAsync(test, expected); - } - - [Fact] - public async Task SqlDataReaderRead_ExcludedViaAdditionalFiles_GeneratesNoWarning() - { - var test = @" -using System.Threading.Tasks; - -class Test { - async Task T() { - System.Data.SqlClient.SqlDataReader reader = null; - reader.Read(); - } -} -"; - - // No diagnostic expected because SqlDataReader.Read is excluded via AdditionalFiles - // Note: This test might need additional setup for SqlClient references await CSVerify.VerifyAnalyzerAsync(test); } From 156d9eb148e13916525ea5e362bf5e16cafa25c2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Jun 2025 03:25:10 +0000 Subject: [PATCH 6/9] Address PR feedback: SDK version to 9.0.300, remove JTF test, clean up mock file Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com> --- global.json | 2 +- ...SyncMethodsToExcludeFromVSTHRD103.mocks.txt | 4 +--- .../VSTHRD103UseAsyncOptionAnalyzerTests.cs | 18 ------------------ 3 files changed, 2 insertions(+), 22 deletions(-) diff --git a/global.json b/global.json index bcbfbe02f..dba0cdca8 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.116", + "version": "9.0.300", "rollForward": "patch", "allowPrerelease": false }, diff --git a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.mocks.txt b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.mocks.txt index 4907330b4..491c94c55 100644 --- a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.mocks.txt +++ b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.mocks.txt @@ -1,4 +1,2 @@ # Test exclusions for VSTHRD103 analyzer -[System.Data.SqlClient.SqlDataReader]::Read -[TestNamespace.TestClass]::SlowSyncMethod -[Microsoft.VisualStudio.Threading.JoinableTaskFactory]::Run \ No newline at end of file +[TestNamespace.TestClass]::SlowSyncMethod \ No newline at end of file diff --git a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs index 56264fc05..b2bf4fe99 100644 --- a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs @@ -1386,24 +1386,6 @@ public static void NotExcludedMethod() { } await CSVerify.VerifyAnalyzerAsync(test); } - [Fact] - public async Task JTFRun_ExcludedViaAdditionalFiles_GeneratesNoWarning() - { - var test = @" -using System.Threading.Tasks; -using Microsoft.VisualStudio.Threading; - -class Test { - async Task T() { - JoinableTaskFactory jtf = null; - jtf.Run(() => Task.CompletedTask); - } -} -"; - - // No diagnostic expected because JoinableTaskFactory.Run is excluded via AdditionalFiles - await CSVerify.VerifyAnalyzerAsync(test); - } private DiagnosticResult CreateDiagnostic(int line, int column, int length, string methodName) => CSVerify.Diagnostic(DescriptorNoAlternativeMethod).WithSpan(line, column, line, column + length).WithArguments(methodName); From 20c57ede8515affaecee4ed75eff37d985472383 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Jun 2025 03:28:21 +0000 Subject: [PATCH 7/9] Remove nuget.org package source from nuget.config Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com> --- nuget.config | 1 - 1 file changed, 1 deletion(-) diff --git a/nuget.config b/nuget.config index 3e9104cd8..35d15c110 100644 --- a/nuget.config +++ b/nuget.config @@ -6,7 +6,6 @@ - From 4721136efce6f45dcb0d775dc33a29ef538491cb Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Wed, 11 Jun 2025 06:14:47 -0600 Subject: [PATCH 8/9] Fix stylecop issues --- .../VSTHRD103UseAsyncOptionAnalyzer.cs | 6 +++--- .../VSTHRD103UseAsyncOptionAnalyzerTests.cs | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/VSTHRD103UseAsyncOptionAnalyzer.cs b/src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/VSTHRD103UseAsyncOptionAnalyzer.cs index 51aa5526b..547ac2d81 100644 --- a/src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/VSTHRD103UseAsyncOptionAnalyzer.cs +++ b/src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/VSTHRD103UseAsyncOptionAnalyzer.cs @@ -96,7 +96,7 @@ internal void AnalyzePropertyGetter(SyntaxNodeAnalysisContext context) var memberAccessSyntax = (MemberAccessExpressionSyntax)context.Node; if (IsInTaskReturningMethodOrDelegate(context)) { - InspectMemberAccess(context, memberAccessSyntax.Name, CommonInterest.SyncBlockingProperties); + this.InspectMemberAccess(context, memberAccessSyntax.Name, CommonInterest.SyncBlockingProperties); } } @@ -110,7 +110,7 @@ internal void AnalyzeConditionalAccessExpression(SyntaxNodeAnalysisContext conte MemberBindingExpressionSyntax bindingExpr => bindingExpr.Name, _ => conditionalAccessSyntax.WhenNotNull, }; - InspectMemberAccess(context, rightSide, CommonInterest.SyncBlockingProperties); + this.InspectMemberAccess(context, rightSide, CommonInterest.SyncBlockingProperties); } } @@ -120,7 +120,7 @@ internal void AnalyzeInvocation(SyntaxNodeAnalysisContext context) { var invocationExpressionSyntax = (InvocationExpressionSyntax)context.Node; var memberAccessSyntax = invocationExpressionSyntax.Expression as MemberAccessExpressionSyntax; - if (memberAccessSyntax is not null && InspectMemberAccess(context, memberAccessSyntax.Name, CommonInterest.SyncBlockingMethods)) + if (memberAccessSyntax is not null && this.InspectMemberAccess(context, memberAccessSyntax.Name, CommonInterest.SyncBlockingMethods)) { // Don't return double-diagnostics. return; diff --git a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs index b2bf4fe99..56afb4baa 100644 --- a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs @@ -1386,7 +1386,6 @@ public static void NotExcludedMethod() { } await CSVerify.VerifyAnalyzerAsync(test); } - private DiagnosticResult CreateDiagnostic(int line, int column, int length, string methodName) => CSVerify.Diagnostic(DescriptorNoAlternativeMethod).WithSpan(line, column, line, column + length).WithArguments(methodName); From 173a6243ae35046a7ef775c7277dbe4f7ad1d526 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Wed, 11 Jun 2025 08:30:30 -0600 Subject: [PATCH 9/9] Fix test failure --- .../VSTHRD103UseAsyncOptionAnalyzerTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs index 56afb4baa..3e6413088 100644 --- a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs @@ -1371,7 +1371,7 @@ public async Task SyncMethodCallInAsyncMethod_NotExcludedViaAdditionalFiles_Gene class Test { async Task T() { - [|TestNamespace.TestClass.NotExcludedMethod()|]; + TestNamespace.TestClass.{|#0:NotExcludedMethod|}(); } } @@ -1383,7 +1383,7 @@ public static void NotExcludedMethod() { } } "; - await CSVerify.VerifyAnalyzerAsync(test); + await CSVerify.VerifyAnalyzerAsync(test, CSVerify.Diagnostic(Descriptor).WithLocation(0).WithArguments("NotExcludedMethod", "NotExcludedMethodAsync")); } private DiagnosticResult CreateDiagnostic(int line, int column, int length, string methodName)