Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Analyzer idea] warn against using MarkupLine with string interpolation #1

Open
sliekens opened this issue Aug 12, 2024 · 0 comments
Open

Comments

@sliekens
Copy link

sliekens commented Aug 12, 2024

I encountered the following bug in a real application:

void WarningLine(string message, params object[] args) => AnsiConsole.MarkupLine($"[yellow]{message}[/]", args);

WarningLine("Are you sure you want to continue? [y/n]");
Exception thrown: 'System.InvalidOperationException' in Spectre.Console.dll: 'Could not find color or style 'y/n'.'

So I think it would be good to have an analyzer to warn against using MarkupLine with interpolated strings, and suggest the following fixes:

-AnsiConsole.MarkupLine($"[yellow]{message}[/]");
+AnsiConsole.MarkupLineInterpolated($"[yellow]{message}[/]");

-AnsiConsole.MarkupLine($"[yellow]{message}[/]", args);
+AnsiConsole.MarkupLineInterpolated($"[yellow]{string.Format(message, args)}[/]")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant