Skip to content

Add UNT0044 - #490

Merged
Sebastien Lebreton (sailro) merged 2 commits into
mainfrom
unt-0044
Sep 9, 2026
Merged

Add UNT0044#490
Sebastien Lebreton (sailro) merged 2 commits into
mainfrom
unt-0044

Conversation

@sailro

Copy link
Copy Markdown
Member

Fixes #441

Checklist

  • I have read the Contribution Guide ;
  • There is an approved issue describing the change when contributing a new analyzer or suppressor ;
  • I have added tests that prove my fix is effective or that my feature works ;
  • I have added necessary documentation (if appropriate) ;

Short description of what this resolves:

Prefer TMPro.SetText(string) over .text=string

No automatic code fix is provided. Even changing an existing SetText(builder.ToString()) call to SetText(builder) can change observable behavior.

@sailro
Sebastien Lebreton (sailro) requested a review from a team as a code owner September 8, 2026 08:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It changes the shared Unity reference resolution used by the entire test infrastructure, which can have broad knock-on effects that should be validated via CI and/or human review.

Pull request overview

This PR adds a new Roslyn analyzer (UNT0044) to help Unity developers avoid allocating temporary strings when updating TextMeshPro text, along with supporting resources, documentation, and unit tests.

Changes:

  • Introduces TextMeshProSetTextAnalyzer (UNT0044) to detect temporary-string patterns (e.g., StringBuilder.ToString(), new string(char[]), simple numeric interpolations) and recommend appropriate TMP_Text.SetText(...) overloads when available.
  • Adds localized strings + generated designer updates for the new diagnostic.
  • Expands the test harness Unity reference set to include module assemblies and the TextMeshPro/UI package assemblies, and adds a comprehensive test suite for UNT0044.
File summaries
File Description
src/Microsoft.Unity.Analyzers/UnityStubs.cs Adds a minimal TMPro.TMP_Text stub so the analyzer can reference the metadata name without requiring TMP at build time.
src/Microsoft.Unity.Analyzers/TextMeshProSetText.cs New UNT0044 analyzer implementation detecting avoidable temporary string creation paths and suggesting more allocation-friendly SetText overloads.
src/Microsoft.Unity.Analyzers/Resources/Strings.resx Adds title/message/description resources for UNT0044.
src/Microsoft.Unity.Analyzers/Resources/Strings.Designer.cs Regenerates strongly-typed resource accessors to include UNT0044 strings.
src/Microsoft.Unity.Analyzers.Tests/TextMeshProSetTextTests.cs New unit tests validating detection and non-detection scenarios for UNT0044 across TMP types and edge cases.
src/Microsoft.Unity.Analyzers.Tests/Infrastructure/DiagnosticVerifier.cs Updates Unity reference assembly collection (modules + NetStandard + shims) and adds UI/TMP assemblies; caches metadata references for reuse.
doc/UNT0044.md New documentation page explaining the diagnostic scope, rationale, and why no code fix is provided.
doc/index.md Registers UNT0044 in the documentation index.
Review details

Files not reviewed (1)

  • src/Microsoft.Unity.Analyzers/Resources/Strings.Designer.cs: Generated file
  • Files reviewed: 7/8 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@sailro
Sebastien Lebreton (sailro) merged commit 62d3558 into main Sep 9, 2026
7 checks passed
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.

Prefer TMPro.SetText(string) over .text=string

3 participants