Skip to content

Use raw literals throughout analyzer tests - #56069

Merged
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-fix-analyzer-test-conventions
Sep 2, 2026
Merged

Use raw literals throughout analyzer tests#56069
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-fix-analyzer-test-conventions

Conversation

@tannergooding

@tannergooding tannergooding commented Sep 1, 2026

Copy link
Copy Markdown
Member

Converts multiline embedded C# and Visual Basic source throughout the analyzer tests from verbatim literals to raw string literals. Statically owned source templates now use raw interpolation instead of escaped braces or string.Format, while runtime-selected composite formats remain unchanged.

Removes leading and trailing blank lines and trailing whitespace where they are not required by diagnostic locations, code fixes, or trivia-sensitive coverage. Single-line fragments remain single-line, and the analyzer test guidance now records the convention.

Follow-up to #55901 (comment).

Note

This pull request was drafted with GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 1, 2026 14:17
@tannergooding
tannergooding requested a review from a team as a code owner September 1, 2026 14:17
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@eiriktsarpalis eiriktsarpalis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. Would it make sense to have the agent do this across all analyzer tests in the repo? I found success doing the same with the STJ suite recently.

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.

Copilot review overview

🟢 Approval recommended

Review tier: Lite
Findings: None

What changed in this PR

This PR refactors the CA1878 unit tests’ embedded C# sources to use C# raw string literals and raw string interpolation, improving readability by removing brace/quote escaping and string.Format scaffolding.

Changes:

  • Replaces string.Format(CultureInfo.InvariantCulture, ...)-based source templates with $$""" ... """ raw interpolated string helpers.
  • Converts embedded test source fragments to raw string literals while keeping single-line fragments single-line.
  • Removes the now-unused System.Globalization import.
File Description
src/​Microsoft.CodeAnalysis.NetAnalyzers/​tests/​Microsoft.CodeAnalysis.NetAnalyzers.UnitTests/​Microsoft.NetCore.Analyzers/​Runtime/​PreferReadOnlySpanPropertiesOverReadOnlyArrayFieldsTests.cs Switches embedded C# test sources to raw string literals/interpolation for readability and removes string.Format/CultureInfo usage.

@tannergooding

Copy link
Copy Markdown
Member Author

Yeah, was just having it do that. It found a lot of them.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding

Copy link
Copy Markdown
Member Author

@eiriktsarpalis was definitely "a lot", some 185k lines 😂

@tannergooding tannergooding changed the title Use readable C# literals in CA1878 tests Use raw literals throughout analyzer tests Sep 1, 2026
@tannergooding
tannergooding requested a lite review from Copilot September 1, 2026 19:42

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.

Copilot review overview

🔵 Needs a closer look

Review tier: Lite
Findings: None

@tannergooding
tannergooding merged commit 1d20019 into dotnet:main Sep 2, 2026
22 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 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.

4 participants