Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Add flags to replaceAll #167

Merged
merged 1 commit into from
Aug 30, 2024
Merged

Add flags to replaceAll #167

merged 1 commit into from
Aug 30, 2024

Conversation

jonathankap
Copy link
Contributor

@jonathankap jonathankap commented Aug 29, 2024

Fixes MOC-241
Fixes MOC-242
Fixes MOC-239

Added flags to find/replace - the form is now:
/find/replace/flags
Where flags are:

  • i - case insensitive
  • w - whole word
  • p - plural
    For example:
    /Train/brain/wp
    Would match 'Train' with 'Brain' and 'Trains' with 'Brains', but not 'train' or 'sTrain'

Summary by CodeRabbit

  • New Features

    • Enhanced find-and-replace functionality with the addition of regex flags for more flexible operations.
    • Improved text replacement logic to support pluralization and word boundaries based on user-defined flags.
  • Bug Fixes

    • Updated test cases to reflect changes in regex patterns, ensuring accurate functionality and case-insensitive matching.
  • Tests

    • Modified various test cases to incorporate new regex patterns and flags, enhancing test coverage for replacement operations.

   i - case insensitive
   w - whole word
   p - plural
@jonathankap jonathankap requested a review from fitzk August 29, 2024 23:24
Copy link

coderabbitai bot commented Aug 29, 2024

Walkthrough

Walkthrough

The changes involve modifications to functions related to text replacement and regular expression handling in a codebase. Key updates include the addition of a flags parameter to various functions, enhancing their ability to manage regex flags for more flexible text processing. Additionally, test cases have been updated to reflect these changes, ensuring that the new functionality is adequately validated.

Changes

Files Change Summary
apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx Updated findReplaceAll function to include a flags parameter for regex operations.
packages/reactor/modifications/replaceAll.ts Modified replaceText, replaceFirstLetterCaseAndPlural, and toRegExpPattern to incorporate a flags parameter, enhancing regex handling. Introduced PatternFlag enum.
packages/reactor/tests/main.test.ts Changed test case content from "/train/brain/" to "/train/brain/i" for case-insensitive matching.
packages/reactor/tests/modifications.test.ts Updated content properties in various test cases to include new flags or characters for regex patterns.
packages/reactor/tests/mutation.test.ts Altered test case content from "/train/brain/" to "/train/brain/wip" to change expected output.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ContentScript
    participant ReplaceFunction

    User->>ContentScript: Send find/replace request with flags
    ContentScript->>ReplaceFunction: Call findReplaceAll(find, replace, flags, highlight)
    ReplaceFunction->>ReplaceFunction: Process regex with flags
    ReplaceFunction-->>ContentScript: Return modified content
    ContentScript-->>User: Display modified content
Loading

🐰 In the meadow, I hop with glee,
New flags in regex, oh what a spree!
With each little change, my heart takes flight,
Text dancing and twirling, oh what a sight!
So let’s celebrate with a joyful cheer,
For changes in code bring us all near! 🐇✨


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fc9ba5e and a020627.

Files selected for processing (5)
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (2 hunks)
  • packages/reactor/modifications/replaceAll.ts (3 hunks)
  • packages/reactor/tests/main.test.ts (1 hunks)
  • packages/reactor/tests/modifications.test.ts (6 hunks)
  • packages/reactor/tests/mutation.test.ts (1 hunks)
Additional comments not posted (17)
packages/reactor/tests/mutation.test.ts (1)

32-32: LGTM!

The change to the content field in the test case is consistent with the PR objective of adding flags to the replaceAll function.

apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (3)

81-81: LGTM!

The change to the findReplaceAll function signature is consistent with the PR objective of adding flags to the replaceAll function.


89-89: LGTM!

The change to the content field in the findReplaceAll function is consistent with the PR objective of adding flags to the replaceAll function.


122-123: LGTM!

The change to pass the flags parameter from the request.data object to the findReplaceAll function is consistent with the PR objective of adding flags to the replaceAll function.

packages/reactor/modifications/replaceAll.ts (6)

162-162: LGTM!

The change to include the flags parameter in the call to toRegExpPattern is consistent with the PR objective of adding flags to the replaceAll function.


216-216: LGTM!

The change to the replaceFirstLetterCaseAndPlural function signature is consistent with the PR objective of adding flags to the replaceAll function.


228-228: LGTM!

The change to use the flags parameter to conditionally append an 's' to the replacement string is consistent with the PR objective of adding flags to the replaceAll function.


236-240: LGTM!

The addition of the PatternFlag enum improves code readability and maintainability by providing a structured way to manage the regex flags.


246-246: LGTM!

The change to the toRegExpPattern function signature is consistent with the PR objective of adding flags to the replaceAll function.


248-273: LGTM!

The change to parse the flags from the input pattern string and incorporate them into the regex construction is consistent with the PR objective of adding flags to the replaceAll function.

packages/reactor/tests/main.test.ts (1)

39-39: Ensure consistency with the new flag functionality.

The content property has been updated to include the i flag, indicating case-insensitive matching. Ensure that all related test cases and documentation are updated to reflect this change.

Ensure that the modifyHtml function correctly handles the new flag functionality.

packages/reactor/tests/modifications.test.ts (6)

48-48: Ensure consistency with the new flag functionality.

The content property has been updated to include the i flag, indicating case-insensitive matching. Ensure that all related test cases and documentation are updated to reflect this change.

Ensure that the applyModification function correctly handles the new flag functionality.


77-77: Ensure consistency with the new flag functionality.

The content property has been updated to include the i flag, indicating case-insensitive matching. Ensure that all related test cases and documentation are updated to reflect this change.

Ensure that the applyModification function correctly handles the new flag functionality.


91-91: Ensure consistency with the new flag functionality.

The content property has been updated to include the ip flags, indicating case-insensitive and plural matching. Ensure that all related test cases and documentation are updated to reflect this change.

Ensure that the applyModification function correctly handles the new flag functionality.


107-107: Ensure consistency with the new flag functionality.

The content property has been updated to include the wip flags, indicating whole word, case-insensitive, and plural matching. Ensure that all related test cases and documentation are updated to reflect this change.

Ensure that the applyModification function correctly handles the new flag functionality.


124-124: Ensure consistency with the new flag functionality.

The content property has been updated to include the wip flags, indicating whole word, case-insensitive, and plural matching. Ensure that all related test cases and documentation are updated to reflect this change.

Ensure that the applyModification function correctly handles the new flag functionality.


159-159: Ensure consistency with the new flag functionality.

The content property has been updated to include the wip flags, indicating whole word, case-insensitive, and plural matching. Ensure that all related test cases and documentation are updated to reflect this change.

Ensure that the applyModification function correctly handles the new flag functionality.

Copy link
Contributor

@fitzk fitzk left a comment

Choose a reason for hiding this comment

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

looks good to me

@fitzk fitzk merged commit 29f4a63 into main Aug 30, 2024
3 checks passed
@fitzk fitzk deleted the MOC-241_replaceall-flags branch August 30, 2024 17:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants