Add UNT0044 - #490
Merged
Merged
Conversation
Copilot started reviewing on behalf of
Sebastien Lebreton (sailro)
September 8, 2026 08:47
View session
There was a problem hiding this comment.
🔵 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 appropriateTMP_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.
Jb Evain (jbevain)
approved these changes
Sep 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #441
Checklist
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 toSetText(builder)can change observable behavior.