-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centralize all CodeAction.Create calls to centralize the RS1035 disab…
…lement
- Loading branch information
1 parent
1e0dae6
commit f6c256a
Showing
26 changed files
with
159 additions
and
134 deletions.
There are no files selected for viewing
This file contains 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
45 changes: 0 additions & 45 deletions
45
src/xunit.analyzers.fixes/Utility/UseDifferentMethodCodeAction.cs
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Microsoft.CodeAnalysis.Editing; | ||
|
||
namespace Microsoft.CodeAnalysis.CodeActions; | ||
|
||
internal static class XunitCodeAction | ||
{ | ||
public static CodeAction Create( | ||
Func<CancellationToken, Task<Document>> createChangedDocument, | ||
string equivalenceKey, | ||
string title) => | ||
CodeAction.Create( | ||
title, | ||
createChangedDocument, | ||
equivalenceKey | ||
); | ||
|
||
#pragma warning disable RS1035 // The prohibiton on CultureInfo.CurrentCulture does not apply to fixers | ||
|
||
public static CodeAction Create( | ||
Func<CancellationToken, Task<Document>> createChangedDocument, | ||
string equivalenceKey, | ||
string titleFormat, | ||
object? arg0) => | ||
CodeAction.Create( | ||
string.Format(CultureInfo.CurrentCulture, titleFormat, arg0), | ||
createChangedDocument, | ||
equivalenceKey | ||
); | ||
|
||
public static CodeAction Create( | ||
Func<CancellationToken, Task<Document>> createChangedDocument, | ||
string equivalenceKey, | ||
string titleFormat, | ||
object? arg0, | ||
object? arg1) => | ||
CodeAction.Create( | ||
string.Format(CultureInfo.CurrentCulture, titleFormat, arg0, arg1), | ||
createChangedDocument, | ||
equivalenceKey | ||
); | ||
|
||
public static CodeAction Create( | ||
Func<CancellationToken, Task<Document>> createChangedDocument, | ||
string equivalenceKey, | ||
string titleFormat, | ||
object? arg0, | ||
object? arg1, | ||
object? arg2) => | ||
CodeAction.Create( | ||
string.Format(CultureInfo.CurrentCulture, titleFormat, arg0, arg1, arg2), | ||
createChangedDocument, | ||
equivalenceKey | ||
); | ||
|
||
public static CodeAction Create( | ||
Func<CancellationToken, Task<Document>> createChangedDocument, | ||
string equivalenceKey, | ||
string titleFormat, | ||
params object?[] args) => | ||
CodeAction.Create( | ||
string.Format(CultureInfo.CurrentCulture, titleFormat, args), | ||
createChangedDocument, | ||
equivalenceKey | ||
); | ||
|
||
#pragma warning restore RS1035 | ||
|
||
public static CodeAction UseDifferentAssertMethod( | ||
string equivalenceKey, | ||
Document document, | ||
InvocationExpressionSyntax invocation, | ||
string replacementMethod) => | ||
CodeAction.Create( | ||
"Use Assert." + replacementMethod, | ||
async ct => | ||
{ | ||
var editor = await DocumentEditor.CreateAsync(document, ct).ConfigureAwait(false); | ||
|
||
if (invocation.Expression is MemberAccessExpressionSyntax memberAccess) | ||
if (editor.Generator.IdentifierName(replacementMethod) is SimpleNameSyntax replacementNameSyntax) | ||
editor.ReplaceNode(memberAccess, memberAccess.WithName(replacementNameSyntax)); | ||
|
||
return editor.GetChangedDocument(); | ||
}, | ||
equivalenceKey | ||
); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.