Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ private static async Task<Document> UseNameof(Document document, SyntaxNode node
{
var editor = await DocumentEditor.CreateAsync(document, cancellationToken).ConfigureAwait(false);
var newExpression = (ExpressionSyntax)editor.Generator.NameOfExpression(enumMemberSyntax);
if (nodeToFix is InterpolationSyntax)
if (nodeToFix is InterpolationSyntax interpolationSyntax)
{
editor.ReplaceNode(nodeToFix, SyntaxFactory.Interpolation(newExpression));
// Keep the alignment clause as it pads the value. The format clause is removed as the reported formats (G, F) already produce the name of the value.
editor.ReplaceNode(interpolationSyntax, interpolationSyntax.WithExpression(newExpression).WithFormatClause(null));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,48 @@ enum MyEnum

return test.RunAsync();
}

[Fact]
public Task InterpolatedString_Alignment()
{
var test = CreateTest();
test.TestCode = """
class Test
{
void A()
{
_ = $"[{|MA0052:{MyEnum.A,10}|}]";
_ = $"[{|MA0052:{MyEnum.A,-10}|}]";
_ = $"[{|MA0052:{MyEnum.A,10:G}|}]";
_ = $"[{|MA0052:{MyEnum.A,-10:f}|}]";
_ = $"[{MyEnum.A,10:D}]";
}
}

enum MyEnum
{
A,
}
""";
test.FixedCode = """
class Test
{
void A()
{
_ = $"[{nameof(MyEnum.A),10}]";
_ = $"[{nameof(MyEnum.A),-10}]";
_ = $"[{nameof(MyEnum.A),10}]";
_ = $"[{nameof(MyEnum.A),-10}]";
_ = $"[{MyEnum.A,10:D}]";
}
}

enum MyEnum
{
A,
}
""";

return test.RunAsync();
}
}