Skip to content

chore: use [GeneratedRegex] source generator (MODERN-001) - #453

Merged
laurentiu021 merged 1 commit into
mainfrom
chore/generated-regex
May 20, 2026
Merged

chore: use [GeneratedRegex] source generator (MODERN-001)#453
laurentiu021 merged 1 commit into
mainfrom
chore/generated-regex

Conversation

@laurentiu021

@laurentiu021 laurentiu021 commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replaced runtime Regex instantiation and static Regex.IsMatch/Regex.Replace calls with [GeneratedRegex] source-generated methods
  • Made MarkdownTextBlock and DiskHealthService classes partial to support source generation
  • Files changed:
    • Helpers/MarkdownTextBlock.cs — 1 regex (inline bold/code formatting)
    • Services/UninstallerService.cs — 3 regex (header detection, summary line, MSI switch replacement)
    • Services/WingetService.cs — 2 regex (upgrade header, summary line)
    • Services/DiskHealthService.cs — 1 regex (objectId format validation)
    • ViewModels/SystemHealthViewModel.cs — 1 regex (drive letter validation)
  • Skipped: Services/LogService.cs — uses dynamic runtime-interpolated pattern, cannot be source-generated

Test plan

  • CI build passes (source generator emits code at compile time)
  • Unit tests pass (parsing logic unchanged)
  • Verify regex behavior unchanged via existing tests

Summary by CodeRabbit

  • Refactor
    • Optimized internal code patterns across multiple services to improve performance and maintainability.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5284e68f-4b8f-45df-af78-dcaf2e04a039

📥 Commits

Reviewing files that changed from the base of the PR and between 0eb67a1 and f8e99c1.

📒 Files selected for processing (5)
  • SysManager/SysManager/Helpers/MarkdownTextBlock.cs
  • SysManager/SysManager/Services/DiskHealthService.cs
  • SysManager/SysManager/Services/UninstallerService.cs
  • SysManager/SysManager/Services/WingetService.cs
  • SysManager/SysManager/ViewModels/SystemHealthViewModel.cs
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build & unit tests
🔇 Additional comments (5)
SysManager/SysManager/Helpers/MarkdownTextBlock.cs (1)

22-22: LGTM!

Also applies to: 84-85, 97-97

SysManager/SysManager/Services/DiskHealthService.cs (1)

6-6: LGTM!

Also applies to: 18-18, 76-76, 217-219

SysManager/SysManager/ViewModels/SystemHealthViewModel.cs (1)

8-8: LGTM!

Also applies to: 202-202, 351-352

SysManager/SysManager/Services/UninstallerService.cs (1)

68-78: LGTM!

Also applies to: 86-86, 107-107, 349-349

SysManager/SysManager/Services/WingetService.cs (1)

53-53: LGTM!

Also applies to: 69-69, 115-119


📝 Walkthrough

Walkthrough

This PR systematically migrates inline Regex patterns to [GeneratedRegex]-backed partial methods across five classes, enabling compile-time pattern precompilation. The changes affect markdown text formatting, input validation, and external command output parsing without altering external behavior or public APIs.

Changes

Regex Source Generation Modernization

Layer / File(s) Summary
MarkdownTextBlock inline formatting modernization
SysManager/SysManager/Helpers/MarkdownTextBlock.cs
MarkdownTextBlock class becomes partial and replaces a precompiled static regex field with a [GeneratedRegex]-annotated InlineFormattingRegex() partial method for parsing bold and inline code spans.
Input validation regex modernization
SysManager/SysManager/Services/DiskHealthService.cs, SysManager/SysManager/ViewModels/SystemHealthViewModel.cs
DiskHealthService and SystemHealthViewModel become partial classes and replace Regex.IsMatch(...) calls with [GeneratedRegex] partial methods: ObjectIdFormatPattern() for WMI objectId validation and DriveLetterPattern() for drive-letter format validation.
Text parsing and table processing regex modernization
SysManager/SysManager/Services/UninstallerService.cs, SysManager/SysManager/Services/WingetService.cs
UninstallerService introduces four [GeneratedRegex] patterns for package-ID validation, winget list header detection, package summary line detection, and MsiExec /I/X switch replacement. WingetService introduces two patterns for winget upgrade table header and summary line detection. Parsing logic call sites are updated to use the generated pattern methods.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • laurentiu021/SystemManager#381: Directly overlapping changes to DiskHealthService objectId validation and UninstallerService winget package parsing logic.
  • laurentiu021/SystemManager#249: Modifies SystemHealthViewModel drive-letter validation regex pattern before this PR modernizes it to a [GeneratedRegex] factory.
  • laurentiu021/SystemManager#444: Also modifies MarkdownTextBlock.cs AddFormattedText method concurrently with this PR's regex modernization.

🐰 Patterns once bound by runtime now bloom in compile-time's light,
Five services march toward precompiled delight,
No behavior changed, just regex reborn—
From inline calls to source-gen morn.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adoption of [GeneratedRegex] source generator across multiple files for regex optimization.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/generated-regex

Comment @coderabbitai help to get the list of available commands and usage tips.

@laurentiu021
laurentiu021 merged commit 0324ce6 into main May 20, 2026
3 of 4 checks passed
@laurentiu021
laurentiu021 deleted the chore/generated-regex branch May 20, 2026 08:39
laurentiu021 added a commit that referenced this pull request May 22, 2026
Co-authored-by: laurentiu021 <laurentiu021@users.noreply.github.com>
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.

1 participant