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 @@ -77,7 +77,20 @@ private static void Analyze(OperationAnalysisContext context)
{
var arg = operation.Arguments[i];

// Skip implicit arguments (e.g., empty params array)
// Check if this is a params array argument
if (arg.ArgumentKind == ArgumentKind.ParamArray && arg.Value is IArrayCreationOperation arrayCreation)
{
// Check if the array has any elements
if (arrayCreation.Initializer is not null && arrayCreation.Initializer.ElementValues.Length > 0)
{
hasFormattingArguments = true;
break;
}
// Skip empty params arrays
continue;
}

// Skip other implicit arguments
if (arg.IsImplicit)
continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,44 @@ void Method()
""")
.ValidateAsync();
}

[Fact]
public async Task StringFormat_WithIFormatProviderAndMultiplePlaceholders_ShouldNotReportDiagnostic()
{
await CreateProjectBuilder()
.WithSourceCode("""
using System;
using System.Globalization;

class Program
{
private static string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Column: {0}, Value: {1}, Invalid: {2}, Blank: {3}", "Column", "Value", true, false);

static void Main(string[] args)
{
Console.WriteLine(DebuggerDisplay);
}
}
""")
.ValidateAsync();
}

[Fact]
public async Task StringFormat_WithExplicitEmptyParamsArray_ShouldReportDiagnostic()
{
await CreateProjectBuilder()
.WithSourceCode("""
using System;
using System.Globalization;

class Test
{
void Method()
{
var result = [|string.Format(CultureInfo.InvariantCulture, "no placeholders", new object[0])|];
}
}
""")
.ValidateAsync();
}
}