Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Dec 1, 2024
1 parent 6897a29 commit c7855d1
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions src/xunit.analyzers.fixes/X1000/UseCancellationTokenFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
var arguments = invocation.ArgumentList.Arguments;

for (var argumentIndex = 0; argumentIndex < arguments.Count; argumentIndex++)
{
if (arguments[argumentIndex].NameColon?.Name.Identifier.Text == parameterName)
{
parameterIndex = argumentIndex;
break;
}
}

context.RegisterCodeFix(
XunitCodeAction.Create(
Expand All @@ -82,27 +80,17 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)

var args = new List<ArgumentSyntax>(arguments);

if (
invocationOperation.Arguments.FirstOrDefault(arg =>
arg.ArgumentKind == ArgumentKind.ParamArray
) is
{ } paramsArgument
)
{
if (invocationOperation.Arguments.FirstOrDefault(arg => arg.ArgumentKind == ArgumentKind.ParamArray) is { } paramsArgument)
TransformParamsArgument(args, paramsArgument, editor.Generator);
}

if (parameterIndex < args.Count)
{
args[parameterIndex] = args[parameterIndex].WithExpression(testContextCancellationTokenExpression);
}
else
{
var argument = Argument(testContextCancellationTokenExpression);
if (parameterIndex > args.Count || args.Any(arg => arg.NameColon is not null))
{
argument = argument.WithNameColon(NameColon(parameterName));
}

args.Add(argument);
}

Expand All @@ -121,24 +109,13 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
);
}

private static void TransformParamsArgument(
static void TransformParamsArgument(
List<ArgumentSyntax> arguments,
IArgumentOperation paramsOperation,
SyntaxGenerator generator
)
SyntaxGenerator generator)
{

if (paramsOperation is not
{
Value: IArrayCreationOperation
{
Type: IArrayTypeSymbol arrayTypeSymbol,
Initializer: { } initializer
}
})
{
if (paramsOperation is not { Value: IArrayCreationOperation { Type: IArrayTypeSymbol arrayTypeSymbol, Initializer: { } initializer } })
return;
}

// We know that the params arguments occupy the end of the list because the language
// does not allow regular arguments after params.
Expand Down

0 comments on commit c7855d1

Please sign in to comment.