Skip to content

feat: Allow multiple removes#745

Merged
Viren070 merged 2 commits intoViren070:mainfrom
Crunging:chainRemove
Mar 1, 2026
Merged

feat: Allow multiple removes#745
Viren070 merged 2 commits intoViren070:mainfrom
Crunging:chainRemove

Conversation

@Crunging
Copy link
Contributor

@Crunging Crunging commented Feb 18, 2026

Allows you to put multiple removes in one instead of chaining them.

Example:

::remove('1','2')

Summary by CodeRabbit

  • New Features

    • The remove modifier now accepts multiple quoted arguments, enabling removal of several specified values from strings and arrays in a single operation.
  • Bug Fixes / Behaviour Change

    • If no removal arguments are provided the modifier now returns undefined instead of leaving the input unchanged.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2026

Walkthrough

The remove(...) modifier now accepts multiple quoted arguments (e.g. remove("a","b")) and removes each from string or array targets; the hardcoded modifier registry replaces the previous single-argument literal keys with a pattern key remove(.*?). If no arguments found, the modifier returns undefined.

Changes

Cohort / File(s) Summary
Remove Modifier Enhancement
packages/core/src/formatters/base.ts
Extend remove(...) to parse multiple quoted arguments and iteratively remove each value from strings (via successive replaceAll) and arrays (via filtering); return undefined when no quoted args present. Replace literal hardcoded regex keys "remove('.*?')" and 'remove(".*?")' with pattern key 'remove(.*?)' in ModifierConstants.hardcodedModifiersForRegexMatching.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • Viren070

Poem

🐰 I nibbled through strings with relish and cheer,

I sniffed out the quotes and hopped them clear;
Now remove can munch many, not just one,
A tumble of tokens — all neatly undone. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: Allow multiple removes' accurately describes the main change: extending the remove modifier to support multiple arguments in a single call instead of requiring chained calls.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/core/src/formatters/base.ts`:
- Around line 889-907: The remove(...) modifier logic in base.ts currently
treats unquoted/malformed args like remove(foo) as having zero args and silently
no-ops; change the parsing in the block handling _mod (and the analogous array
branch around lines 954-968) to detect non-empty content that doesn't contain
any quoted arguments: after extracting content from _mod (const content =
_mod.substring(7, _mod.length - 1)), if content.trim() is non-empty but the
regex extraction produced args.length === 0, return undefined to signal an
invalid modifier; keep the existing behavior where an empty content (remove())
returns the original variable as a no-op. Ensure the same guard is added to both
the string and array branches that use regex, args, content, and _mod.

@Crunging Crunging changed the title Allow multiple removes feat: Allow multiple removes Mar 1, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
packages/core/src/formatters/base.ts (1)

895-912: ⚠️ Potential issue | 🟡 Minor

Require full-shape validation for remove(...) arguments.

The current extractor still accepts partially malformed content (for example, remove("a", foo)), because it pulls quoted tokens and ignores invalid leftovers. That can silently apply partial removals instead of surfacing an unknown modifier.

Proposed fix (apply in both string and array branches)
 const content = _mod.substring(7, _mod.length - 1);
+const validRemoveArgs =
+  /^\s*(?:"[^"]*"|'[^']*')\s*(?:,\s*(?:"[^"]*"|'[^']*')\s*)*$/;
+if (!validRemoveArgs.test(content)) return undefined;

 // Extract options from remove("...", "...", ...)
 const regex = /"([^"]*)"|'([^']*)'/g;
 const args: string[] = [];

Also applies to: 960-973

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/formatters/base.ts` around lines 895 - 912, The extractor
for remove(...) (using _mod, content, regex, args) accepts partially malformed
input because it extracts quoted tokens but ignores leftover invalid text;
update the logic to enforce full-shape validation by ensuring the entire content
matches only a comma-separated list of quoted strings (e.g. with a full-match
regex or by reconstructing the expected string and comparing lengths) before
proceeding to build args; if the full-shape check fails, return undefined (i.e.
treat as unknown modifier) instead of performing partial replacements. Apply the
same strict validation to both the string and array branches (the other block at
the 960-973 range) so malformed inputs like remove("a", foo) are rejected.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/core/src/formatters/base.ts`:
- Around line 895-912: The extractor for remove(...) (using _mod, content,
regex, args) accepts partially malformed input because it extracts quoted tokens
but ignores leftover invalid text; update the logic to enforce full-shape
validation by ensuring the entire content matches only a comma-separated list of
quoted strings (e.g. with a full-match regex or by reconstructing the expected
string and comparing lengths) before proceeding to build args; if the full-shape
check fails, return undefined (i.e. treat as unknown modifier) instead of
performing partial replacements. Apply the same strict validation to both the
string and array branches (the other block at the 960-973 range) so malformed
inputs like remove("a", foo) are rejected.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 07a625c and 1a29afe.

📒 Files selected for processing (1)
  • packages/core/src/formatters/base.ts

@Viren070 Viren070 merged commit c3609b9 into Viren070:main Mar 1, 2026
3 checks passed
@Viren070 Viren070 mentioned this pull request Mar 1, 2026
@Crunging Crunging deleted the chainRemove branch March 1, 2026 21:48
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.

2 participants