Skip to content

refactor: a little matcher readability cleanup#286

Merged
ioncache merged 1 commit into
mainfrom
refactor/matcher-readability-cleanup
May 17, 2026
Merged

refactor: a little matcher readability cleanup#286
ioncache merged 1 commit into
mainfrom
refactor/matcher-readability-cleanup

Conversation

@ioncache
Copy link
Copy Markdown
Owner

@ioncache ioncache commented May 17, 2026

Overview

Refactors matcher regular expression construction into named local fragments while preserving the existing matcher API and behavior.

Details

  • Adds a matcher readability cleanup plan documenting the behavior-preserving scope, capture group requirements, and parser-first JSON follow-up boundary.
  • Replaces repeated inline regex construction in src/matchers.ts with local field, value, removal, and masking fragments inside each matcher.
  • Preserves exported matcher names, function signatures, global case-insensitive flags, and replacement capture group ordering.
  • Verified with yarn test, yarn test:coverage, yarn lint, yarn format:check, yarn build, and workspace diagnostics.

Related Tickets and/or Pull Requests

N/A

Summary by CodeRabbit

  • Refactor

    • Improved internal code organization and maintainability of pattern matching logic while preserving all existing functionality.
  • Documentation

    • Added documentation plan outlining ongoing readability improvements to the codebase.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fb54ff80-23bc-4a85-aba0-25c73b6592bb

📥 Commits

Reviewing files that changed from the base of the PR and between d9547e5 and b8cc5fa.

📒 Files selected for processing (2)
  • docs/plans/006-matcher-readability-cleanup.md
  • src/matchers.ts

📝 Walkthrough

Walkthrough

This PR refactors regex construction in three data-sanitization matchers by centralizing flag management and extracting intermediate regex components for readability, while preserving masking and removal behaviour. A planning document outlines the approach and verification constraints.

Changes

Matcher Readability Cleanup

Layer / File(s) Summary
Refactoring plan documentation
docs/plans/006-matcher-readability-cleanup.md
Plan document details regex component extraction strategy, verification steps, and explicit decisions to preserve capture-group ordering and exported behaviour across the three matchers.
Matcher refactoring: flags and components
src/matchers.ts
Shared MATCHER_FLAGS = 'gi' constant replaces hardcoded 'gi' literals. formEncodedMatcher, jsonMatcher, and escapedJsonMatcher extract intermediate regex strings (fieldName, fieldPrefix, fieldValue, maskField, remove-pattern fragments) for clarity while maintaining masking and removal semantics.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • ioncache/data-sanitization#283: Modifies formEncodedMatcher form-encoded regex construction for masking mode and adds regression tests for that scenario.

Poem

A rabbit hops through matchers with care, 🐰
Extracting patterns, making them fair,
Flags gathered central, components aligned,
Same masked and removed, but cleaner designed,
Readability blooms in the regex grove! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: a little matcher readability cleanup' directly and accurately summarizes the main change: a readability refactor of matcher regex construction in src/matchers.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 refactor/matcher-readability-cleanup

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

@github-actions
Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 100% (🎯 100%) 127 / 127
🔵 Statements 100% (🎯 100%) 129 / 129
🔵 Functions 100% (🎯 100%) 14 / 14
🔵 Branches 100% (🎯 100%) 72 / 72
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/matchers.ts 100% 100% 100% 100%
Generated in workflow #144 for commit b8cc5fa by the Vitest Coverage Report Action

@ioncache ioncache merged commit 0500389 into main May 17, 2026
5 checks passed
@ioncache ioncache deleted the refactor/matcher-readability-cleanup branch May 17, 2026 21:31
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