Skip to content

MA0011: suppress diagnostic when all AppendFormat template arguments are culture-insensitive#1085

Merged
meziantou merged 2 commits intomainfrom
copilot/fix-ma0011-case-insensitivity
Apr 2, 2026
Merged

MA0011: suppress diagnostic when all AppendFormat template arguments are culture-insensitive#1085
meziantou merged 2 commits intomainfrom
copilot/fix-ma0011-case-insensitivity

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

MA0011 was incorrectly flagged on StringBuilder.AppendFormat calls where every template argument is culture-insensitive (strings, chars, booleans, positive integers, etc.), because CultureSensitiveFormattingContext.IsCultureSensitiveOperation had no special handling for AppendFormat and defaulted to true.

Changes

  • CultureSensitiveFormattingContext.cs: Added AppendFormat handling on StringBuilder mirroring the existing string.Format logic — skips the format-string argument, then checks each template argument; returns false if none are culture-sensitive. Handles the params object[], collection-expression (Roslyn 4.14+), and individual-argument overload shapes.

  • UseIFormatProviderAnalyzerTests.cs: Updated the existing AppendFormat("{0}", 10) test (positive int → not culture-sensitive, no longer warrants a diagnostic; changed to -1); added no-diagnostic cases for "{0} / {1}", "X", "Y" and "{0}", 10.

Example

var sb = new StringBuilder();
sb.AppendFormat("{0} / {1}", "X", "Y");   // no longer reported
sb.AppendFormat("{0}", 10);               // no longer reported (positive int)
sb.AppendFormat("{0}", -1);              // still reported (negative int is culture-sensitive)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • st8vsblobprodcus339.vsblob.vsassets.io
    • Triggering command: /usr/share/dotnet/dotnet dotnet restore --no-dependencies /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/Meziantou.Analyzer.slnx --packages /tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /usr/share/dotnet/dotnet dotnet restore --no-dependencies /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/Meziantou.Analyzer.Test.csproj --packages /tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

…e culture-insensitive

Agent-Logs-Url: https://github.com/meziantou/Meziantou.Analyzer/sessions/cd874975-1da8-47b9-a17f-9bf3a890c81e

Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix MA0011 reporting for case-insensitive template arguments MA0011: suppress diagnostic when all AppendFormat template arguments are culture-insensitive Apr 2, 2026
Copilot AI requested a review from meziantou April 2, 2026 14:12
@meziantou meziantou marked this pull request as ready for review April 2, 2026 14:15
@meziantou meziantou merged commit 7e3fab3 into main Apr 2, 2026
13 checks passed
@meziantou meziantou deleted the copilot/fix-ma0011-case-insensitivity branch April 2, 2026 14:26
This was referenced Apr 2, 2026
IhateTrains added a commit to ParadoxGameConverters/ImperatorToCK3 that referenced this pull request Apr 3, 2026
Updated
[Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer)
from 3.0.29 to 3.0.44.

<details>
<summary>Release notes</summary>

_Sourced from [Meziantou.Analyzer's
releases](https://github.com/meziantou/Meziantou.Analyzer/releases)._

## 3.0.44

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.44>

## What's Changed
* MA0011: suppress diagnostic when all AppendFormat template arguments
are culture-insensitive by @​Copilot in
meziantou/Meziantou.Analyzer#1085


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.43...3.0.44

## 3.0.43

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.43>

## What's Changed
* Fix expression parenthesis in code fixers by @​meziantou in
meziantou/Meziantou.Analyzer#1083


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.42...3.0.43

## 3.0.42

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.42>

## What's Changed
* Cache IsAwaitable result for the no-SyntaxNode overload by @​meziantou
in meziantou/Meziantou.Analyzer#1082


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.41...3.0.42

## 3.0.41

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.41>

## What's Changed
* Improve MA0042 async overload matching coverage by @​meziantou in
meziantou/Meziantou.Analyzer#1065


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.40...3.0.41

## 3.0.40

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.40>

## What's Changed
* Add MA0191: Detect null! and default! usage by @​Copilot in
meziantou/Meziantou.Analyzer#1081


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.39...3.0.40

## 3.0.39

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.39>

## What's Changed
* Add code fixes for MA0094-MA0097 by @​meziantou in
meziantou/Meziantou.Analyzer#1078


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.38...3.0.39

## 3.0.38

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.38>

## What's Changed
* Fix typos and grammar across all 188 rule documentation files by
@​Copilot in meziantou/Meziantou.Analyzer#1076
* Add code fixers for MA0118, MA0161, and MA0186 by @​meziantou in
meziantou/Meziantou.Analyzer#1079
* Validate fix conditions in RegisterCodeFixesAsync before registering
code fixes by @​Copilot in
meziantou/Meziantou.Analyzer#1077


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.37...3.0.38

## 3.0.37

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.37>

## What's Changed
* docs: require updating rule docs when rules change by @​meziantou in
meziantou/Meziantou.Analyzer#1075
* Add code fixers for MA0138/44/46/52/56/57/58/60/69/73 by @​meziantou
in meziantou/Meziantou.Analyzer#1074


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.36...3.0.37

## 3.0.36

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.36>

## What's Changed
* Add missing code fixers for 10 analyzer rules by @​meziantou in
meziantou/Meziantou.Analyzer#1073


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.35...3.0.36

## 3.0.35

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.35>

## What's Changed
* Add missing code fixers for MA0088-MA0137 by @​meziantou in
meziantou/Meziantou.Analyzer#1072


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.34...3.0.35

## 3.0.34

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.34>

## What's Changed
* Add code fixer for MA0174 (Record should use explicit 'class' keyword)
by @​Copilot in
meziantou/Meziantou.Analyzer#1070


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.33...3.0.34

## 3.0.33

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.33>

## What's Changed
* Add code fixer for MA0173 (Use LazyInitializer.EnsureInitialized) by
@​Copilot in meziantou/Meziantou.Analyzer#1071


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.32...3.0.33

## 3.0.32

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.32>

## What's Changed
* Add code fixer for MA0175 (Remove explicit `class` keyword from record
declarations) by @​Copilot in
meziantou/Meziantou.Analyzer#1069


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.31...3.0.32

## 3.0.31

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.31>

## What's Changed
* Add code fixer for MA0137 and MA0138 (async suffix naming) by
@​Copilot in meziantou/Meziantou.Analyzer#1068


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.30...3.0.31

## 3.0.30

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.30>

## What's Changed
* MA0137: Add `exclude_test_methods` configuration option by @​Copilot
in meziantou/Meziantou.Analyzer#1067


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.29...3.0.30

Commits viewable in [compare
view](meziantou/Meziantou.Analyzer@3.0.29...3.0.44).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Meziantou.Analyzer&package-manager=nuget&previous-version=3.0.29&new-version=3.0.44)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>
This was referenced Apr 3, 2026
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

Successfully merging this pull request may close these issues.

MA0011 should not be reported when all "template arguments" are case-insensitive

2 participants