Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch more types of search inputs in stripDiacritics #21174

Closed
wants to merge 1 commit into from

Conversation

silamon
Copy link
Contributor

@silamon silamon commented Jun 26, 2024

Proposed change

It was reported in the beta channel that the search in the "add integration" dialog no longer functions. Going through, it seems to throw in undefined values and string arrays in the stripDiacritics function as well. Adding support for this makes it work, but drops the performance of the search function.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@coderabbitai pause

Summary by CodeRabbit

  • New Features

    • Enhanced text processing functionality to accept both strings and arrays of strings for diacritic stripping.
  • Improvements

    • Improved input handling in text processing, enhancing flexibility and robustness.

@silamon silamon added this to the 2024.7 milestone Jun 26, 2024
Copy link
Contributor

coderabbitai bot commented Jun 26, 2024

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.
Walkthrough

Walkthrough

The functionality of the stripDiacritics function has been enhanced to handle different input types. It now accepts a string or an array of strings and processes each case accordingly. This enhancement provides greater flexibility for the function, making it more versatile in handling various inputs within the codebase.

Changes

File Change Summary
src/common/string/strip-diacritics.ts Modified stripDiacritics to accept string, readonly string[], or undefined and process each case appropriately. Updated function signature from an arrow function to a regular function.

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 4b7526c and 679ad1e.

Files selected for processing (1)
  • src/common/string/strip-diacritics.ts (1 hunks)
Additional context used
Biome
src/common/string/strip-diacritics.ts

[error] 3-3: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 8-8: Unexpected combined character in the character class. (lint/suspicious/noMisleadingCharacterClass)


[error] 10-10: Unexpected combined character in the character class. (lint/suspicious/noMisleadingCharacterClass)

Additional comments not posted (2)
src/common/string/strip-diacritics.ts (2)

4-6: Handle undefined input gracefully.

Returning the input directly when it's undefined is a clean and straightforward approach.


7-9: Optimize string diacritic removal.

Using normalize and a regular expression to remove diacritics is a standard approach in JavaScript/TypeScript.

Tools
Biome

[error] 8-8: Unexpected combined character in the character class. (lint/suspicious/noMisleadingCharacterClass)


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@silamon silamon changed the title Catch more types of search inputs Catch more types of search inputs in stripDiacritics Jun 26, 2024
@silamon

This comment was marked as off-topic.

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: 2

if (typeof str === "string") {
return str.normalize("NFD").replace(/[\u0300-\u036F]/g, "");
}
return str.map((s) => s.normalize("NFD").replace(/[\u0300-\u036F]/g, ""));
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a safer character class in regular expressions.

The current implementation may lead to issues due to a misleading character class.

- return str.map((s) => s.normalize("NFD").replace(/[\u0300-\u036F]/g, ""));
+ return str.map((s) => s.normalize("NFD").replace(/[\u0300-\u036f]/g, ""));

Committable suggestion was skipped due to low confidence.

Tools
Biome

[error] 10-10: Unexpected combined character in the character class. (lint/suspicious/noMisleadingCharacterClass)

Comment on lines +1 to +3
export function stripDiacritics(
str: string | readonly string[] | undefined
): any {
Copy link
Contributor

Choose a reason for hiding this comment

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

Specify a more appropriate return type instead of any.

Using any as a return type defeats the purpose of TypeScript's static type checking. Consider specifying a more precise type.

- export function stripDiacritics(
-   str: string | readonly string[] | undefined
- ): any {
+ export function stripDiacritics(
+   str: string | readonly string[] | undefined
+ ): string | string[] | undefined {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function stripDiacritics(
str: string | readonly string[] | undefined
): any {
export function stripDiacritics(
str: string | readonly string[] | undefined
): string | string[] | undefined {
Tools
Biome

[error] 3-3: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.

@piitaya
Copy link
Member

piitaya commented Jun 26, 2024

Thank @silamon, I did the same PR at the same time but by creating a special function for fuse to avoid useless checks when using the function in other contexts.
#21173

@silamon silamon closed this Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants