Skip to content

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

@sliekens

Description

@sliekens

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)}[/]")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions