Exclude non-equivalent async alternatives from VSTHRD103 - #1665
Open
Andrew Arnott (AArnott) wants to merge 2 commits into
Open
Exclude non-equivalent async alternatives from VSTHRD103#1665Andrew Arnott (AArnott) wants to merge 2 commits into
Andrew Arnott (AArnott) wants to merge 2 commits into
Conversation
Ship default VSTHRD103 exclusions for xUnit assertions, NUnit assertions, and Entity Framework Core APIs whose async variants have different semantics or specialized use cases. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refines VSTHRD103 (“Use async methods when in an async method”) to avoid recommending Async-suffixed alternatives that are known to be non-equivalent for several common framework APIs (notably xUnit assertions, NUnit assertions, and EF Core change tracking APIs). It does this via a package-shipped AdditionalFiles exclusion list while keeping the approach extensible through the existing filename-pattern mechanism.
Changes:
- Add a buildTransitive AdditionalFiles exclusion list (
vs-threading.SyncMethodsToExcludeFromVSTHRD103.frameworks.txt) covering xUnit, NUnit, and EF Core methods with non-equivalent async counterparts. - Add a regression test to ensure the known framework exclusions suppress diagnostics while similarly-named methods on other types still produce diagnostics.
- Update analyzer documentation to describe the package-provided default exclusions.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs | Adds regression coverage for the new built-in exclusion cases and verifies type scoping. |
| src/Microsoft.VisualStudio.Threading.Analyzers.CodeFixes/buildTransitive/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.frameworks.txt | Introduces the package-shipped default exclusion list for VSTHRD103. |
| docfx/analyzers/VSTHRD103.md | Minor documentation formatting tweak in the analyzer page. |
| docfx/analyzers/configuration.md | Documents the built-in exclusions and how to extend exclusions via AdditionalFiles. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Document the optional suffix accepted for AdditionalFiles that contribute VSTHRD103 exclusions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
VSTHRD103 assumes an
Async-suffixed counterpart is generally preferable, but several framework APIs use the async variant for different semantics or specialized cases. This causes incorrect recommendations for synchronous assertions and Entity Framework Core change tracking APIs.Changes
Throws/ThrowsAny, NUnitAssert.That, and EF CoreDbContext/DbSet<TEntity>Add/AddRange.The task-flow case in #1662 is intentionally not addressed here because it is being fixed separately through semantic analysis.
Validation
net8.0.buildTransitive/AdditionalFiles.Fixes #1661
Fixes #1480