Skip to content

Unify IndentedStringBuilder across MSTest source generators#9045

Merged
Evangelink merged 2 commits into
mainfrom
dev/copilot/issue-8987-unified-indentedsb
Jun 11, 2026
Merged

Unify IndentedStringBuilder across MSTest source generators#9045
Evangelink merged 2 commits into
mainfrom
dev/copilot/issue-8987-unified-indentedsb

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Fixes #8987

Summary

  • Kept src/Analyzers/MSTest.SourceGeneration/Helpers/IndentedStringBuilder.cs as the canonical helper.
  • Linked the canonical helper (and its deterministic Constants.NewLine dependency) into MSTest.AotReflection.SourceGeneration.
  • Removed the AotReflection-specific duplicate helper while preserving its fluent Append/AppendLine and Block style.

Validation

  • dotnet build src\Analyzers\MSTest.SourceGeneration\MSTest.SourceGeneration.csproj -v minimal -m:1 -bl:{}
  • dotnet build src\Analyzers\MSTest.AotReflection.SourceGeneration\MSTest.AotReflection.SourceGeneration.csproj -v minimal -m:1 -bl:{}
  • dotnet build src\Analyzers\MSTest.Analyzers\MSTest.Analyzers.csproj -v minimal -m:1 -bl:{}
  • dotnet test --project test\UnitTests\MSTest.SourceGeneration.UnitTests\MSTest.SourceGeneration.UnitTests.csproj --framework net8.0 --no-build -p:UsingDotNetTest=true -bl:{}
  • dotnet test --project test\UnitTests\MSTest.AotReflection.SourceGeneration.UnitTests\MSTest.AotReflection.SourceGeneration.UnitTests.csproj --framework net8.0 --no-build -p:UsingDotNetTest=true -bl:{}
  • dotnet test --project test\UnitTests\MSTest.Analyzers.UnitTests\MSTest.Analyzers.UnitTests.csproj --framework net8.0 --no-build -p:UsingDotNetTest=true -bl:{}

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 11, 2026 14:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the duplicated IndentedStringBuilder implementation from MSTest.AotReflection.SourceGeneration by reusing the canonical helper from MSTest.SourceGeneration (via linked Compile items), ensuring both generators share the same indentation/block API and deterministic newline behavior.

Changes:

  • Updated the canonical IndentedStringBuilder to support the fluent API shape and Block(...) pattern used by the AOT reflection generator.
  • Linked IndentedStringBuilder.cs and its Constants.NewLine dependency into MSTest.AotReflection.SourceGeneration.
  • Deleted the AOT reflection project’s duplicate helper and updated generator code to use the canonical helper’s namespace.
Show a summary per file
File Description
src/Analyzers/MSTest.SourceGeneration/Helpers/IndentedStringBuilder.cs Makes the canonical helper fluent and adds Block(...) to match both generators’ call patterns while keeping deterministic newlines.
src/Analyzers/MSTest.AotReflection.SourceGeneration/MSTest.AotReflection.SourceGeneration.csproj Links the canonical helper (and Constants.cs) into the AOT reflection generator project.
src/Analyzers/MSTest.AotReflection.SourceGeneration/Helpers/IndentedStringBuilder.cs Removes the duplicate, AOT-specific helper implementation.
src/Analyzers/MSTest.AotReflection.SourceGeneration/Generators/MetadataRegistryEmitter.cs Switches the generator to import the canonical helper namespace.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 0

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note

🤖 Automated review by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

# Dimension Verdict
15 Code Structure 🔵 1 NIT
16 Naming & Conventions 🔵 1 NIT

✅ 20/22 applicable dimensions clean (12 dimensions N/A for this change set).

  • AppendBlock is dead code with no callers — only Block is used. Two internal entry-points for the same operation is mildly confusing. (See inline comment.)

Overall assessment: The unification is well-executed. The file-linking approach (.csproj <Compile Link="..."/>) is the right mechanism, and switching from platform-specific StringBuilder.AppendLine() to the deterministic Constants.NewLine ("\n") is a genuine improvement for reproducible generator output. All behavioral semantics of the deleted AotReflection-specific IndentedStringBuilder are correctly preserved in the canonical version. The return-type promotion to IndentedStringBuilder (fluent style) is source-compatible with all existing void-discard call sites.

🤖 Automated content by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Expert Code Review (on PR ready) workflow. · 716.9 AIC · ⌖ 12.3 AIC ·

Comment thread src/Analyzers/MSTest.SourceGeneration/Helpers/IndentedStringBuilder.cs Outdated
AppendBlock had no remaining call sites: every consumer in
MetadataRegistryEmitter.cs goes through Block. Inline AppendBlock's
body into Block to leave a single, unambiguous entry point on this
internal helper.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink Evangelink merged commit 9e51a19 into main Jun 11, 2026
34 checks passed
@Evangelink Evangelink deleted the dev/copilot/issue-8987-unified-indentedsb branch June 11, 2026 19:16
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.

[duplicate-code] Duplicate Code: IndentedStringBuilder Duplicated Across MSTest Source Generator Projects

2 participants