[code-simplifier] Simplify Assert code-fix helpers: defer async root fetch, inline adapter lambda#8860
Closed
Evangelink wants to merge 1 commit into
Closed
Conversation
…ter lambda - AssertToAssertFixerHelpers.RegisterCodeFixAsync: move SyntaxNode root acquisition after the cheap synchronous diagnostic-property checks so the async round-trip is skipped on early returns. - StringAssertToAssertFixer.RegisterCodeFixesAsync: replace the pure FixAssertAsync adapter method (which ignored fixKind and just forwarded to FixStringAssertAsync) with an inline lambda; the _ discard makes the unused fixKind parameter explicit at the call site. - Remove two obvious comments from FixStringAssertAsync that described self-evident code. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR simplifies the MSTest analyzers’ Assert-migration code-fix scaffolding (introduced in #8848) by reducing unnecessary async work and removing a trivial adapter method, while preserving behavior.
Changes:
- Deferred
GetRequiredSyntaxRootAsyncinAssertToAssertFixerHelpers.RegisterCodeFixAsyncuntil after cheap diagnostic-property guard checks. - Inlined the
FixAssertAsyncadapter inStringAssertToAssertFixerwith a lambda that explicitly discards the unusedfixKindparameter. - Removed a few redundant comments in
FixStringAssertAsyncto reduce noise.
Show a summary per file
| File | Description |
|---|---|
| src/Analyzers/MSTest.Analyzers.CodeFixes/StringAssertToAssertFixer.cs | Removes the adapter method and inlines a non-capturing lambda (with _ discard) while keeping the same rewrite behavior. |
| src/Analyzers/MSTest.Analyzers.CodeFixes/AssertToAssertFixerHelpers.cs | Reorders async syntax-root acquisition to avoid doing it on code paths that return early due to missing diagnostic properties. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 0
Contributor
|
This pull request was automatically closed because it expired on 2026-06-06T14:15:14.790Z.
|
auto-merge was automatically disabled
June 6, 2026 15:01
Pull request was closed
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.
Code Simplification — 2026-06-05
This PR simplifies code introduced in #8848 (the String/Collection Assert code-fix scaffolding refactor) to improve clarity and code flow while preserving all functionality.
Files Simplified
src/Analyzers/MSTest.Analyzers.CodeFixes/AssertToAssertFixerHelpers.cs— defer async root acquisition until after cheap synchronous checkssrc/Analyzers/MSTest.Analyzers.CodeFixes/StringAssertToAssertFixer.cs— inline adapter lambda, remove obvious commentsImprovements Made
Deferred async work in
AssertToAssertFixerHelpers.RegisterCodeFixAsyncSyntaxNode root = await context.Document.GetRequiredSyntaxRootAsync(...)was fetched unconditionally at the top of the method, before two cheapDictionary.TryGetValuechecks that can cause early returns.Removed
FixAssertAsyncadapter method fromStringAssertToAssertFixerstring? fixKind) but immediately ignoredfixKindand forwarded toFixStringAssertAsync.(doc, expr, methodName, _, ct) => FixStringAssertAsync(doc, expr, methodName, ct)where the_discard explicitly signals thatfixKindis not used for this fixer. This removes 9 lines without any loss of clarity.Removed two obvious comments from
FixStringAssertAsync// Check if the invocation expression has a member access expression— the pattern match immediately below is self-explanatory.// Replace StringAssert with Assert in the member access expression/// Change StringAssert.MethodName to Assert.ProperMethodName— two lines saying the same thing about obvious code.Changes Based On
Testing
Func<Document, InvocationExpressionSyntax, string, string?, CancellationToken, Task<Document>>exactlyReview Focus
Please verify:
_discard in the lambda is idiomatic in this codebaseRegisterCodeFixAsyncstill makes logical senseAutomated by Code Simplifier Agent
Add this agentic workflows to your repo
To install this agentic workflow, run