Skip to content

Commit

Permalink
Handle trivia properly in PreferTestCleanupOverDisposeFixer (#4000)
Browse files Browse the repository at this point in the history
Co-authored-by: Youssef Fahmy <[email protected]>
  • Loading branch information
Youssef1313 and Youssef Fahmy authored Nov 4, 2024
1 parent b4d8c0a commit f6f2386
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
CodeAction.Create(
CodeFixResources.ReplaceWithTestCleanuFix,
c => ReplaceDisposeWithTestCleanupAsync(context.Document, methodDeclaration, c),
nameof(TestMethodShouldBeValidCodeFixProvider)),
nameof(PreferTestCleanupOverDisposeFixer)),
diagnostic);
}

Expand Down Expand Up @@ -83,7 +83,9 @@ private static async Task<Document> ReplaceDisposeWithTestCleanupAsync(Document
else
{
// If no interfaces left, remove the base list entirely
SyntaxTriviaList trailingTrivia = newParent.BaseList?.GetTrailingTrivia() ?? SyntaxTriviaList.Empty;
newParent = newParent.WithBaseList(null);
newParent = newParent.WithIdentifier(newParent.Identifier.WithTrailingTrivia(trailingTrivia));
}

editor.ReplaceNode(parentClass, newParent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public class MyTestClass : IAsyncDisposable
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class MyTestClass {
public class MyTestClass
{
[TestCleanup]
public ValueTask TestCleanup()
{
Expand Down

0 comments on commit f6f2386

Please sign in to comment.