From 33e2d1171d26e5ffe1c5f78a365d451ec770edf7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 14:03:25 +0000 Subject: [PATCH 1/3] Initial plan From a12dfc4da964f591d3e5d6bb9cce579df07c15e4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 14:13:42 +0000 Subject: [PATCH 2/3] Add reproducing tests for MA0183 false positive with parenthesized arguments Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com> --- ...ringFormatShouldBeConstantAnalyzerTests.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/Meziantou.Analyzer.Test/Rules/StringFormatShouldBeConstantAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/StringFormatShouldBeConstantAnalyzerTests.cs index 05b9eb6c..e976d3f4 100644 --- a/tests/Meziantou.Analyzer.Test/Rules/StringFormatShouldBeConstantAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/StringFormatShouldBeConstantAnalyzerTests.cs @@ -734,4 +734,44 @@ void Method() """) .ValidateAsync(); } + + [Fact] + public async Task StringFormat_WithParenthesizedArgAndPlaceholder_ShouldNotReportDiagnostic() + { + await CreateProjectBuilder() + .WithSourceCode(""" + using System; + using System.Globalization; + + class Test + { + void Method(object obj) + { + _ = string.Format(CultureInfo.InvariantCulture, "Format string with placeholder: '{0}'.", (obj is null ? string.Empty : "X")); + } + } + """) + .WithTargetFramework(Helpers.TargetFramework.Net10_0) + .ValidateAsync(); + } + + [Fact] + public async Task StringFormat_WithParenthesizedArgAndNoPlaceholder_ShouldReportDiagnostic() + { + await CreateProjectBuilder() + .WithSourceCode(""" + using System; + using System.Globalization; + + class Test + { + void Method(object obj) + { + _ = [|string.Format(CultureInfo.InvariantCulture, "Format string without placeholder.", (obj is null ? string.Empty : "X"))|]; + } + } + """) + .WithTargetFramework(Helpers.TargetFramework.Net10_0) + .ValidateAsync(); + } } From c8ea7808c388010f86a6225eb6501e455d1b6476 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 14:15:26 +0000 Subject: [PATCH 3/3] Fix MA0183 false positive when argument is wrapped in parentheses Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com> --- .../Rules/StringFormatShouldBeConstantAnalyzer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Meziantou.Analyzer/Rules/StringFormatShouldBeConstantAnalyzer.cs b/src/Meziantou.Analyzer/Rules/StringFormatShouldBeConstantAnalyzer.cs index ec394a99..bcb1aa66 100644 --- a/src/Meziantou.Analyzer/Rules/StringFormatShouldBeConstantAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/StringFormatShouldBeConstantAnalyzer.cs @@ -143,8 +143,8 @@ private static bool HasFormattingArguments(IInvocationOperation operation, int f } #endif - // Skip other implicit arguments - if (arg.IsImplicit) + // Skip arguments that were not explicitly provided (e.g. default values) + if (arg.ArgumentKind is ArgumentKind.DefaultValue) continue; return true;