Skip to content

Fix/support parentheses in paths#337

Merged
yamadashy merged 4 commits intoyamadashy:mainfrom
matheuscoelhomalta:fix/support-parentheses-in-paths
Feb 7, 2025
Merged

Fix/support parentheses in paths#337
yamadashy merged 4 commits intoyamadashy:mainfrom
matheuscoelhomalta:fix/support-parentheses-in-paths

Conversation

@matheuscoelhomalta
Copy link
Contributor

@matheuscoelhomalta matheuscoelhomalta commented Feb 5, 2025

This PR adds support for paths containing special characters, specifically parentheses, in the include patterns. Previously, paths with characters like () were not correctly matched by the glob pattern matcher.

Example Use Case

When working with frameworks like Next.js, developers often use route groups. The following include pattern will now work as expected:

{
"include": ["src/(categories)/**/*"]
}

Changes

  • escapeGlobPattern function:

    • Added a utility to properly escape special characters within include patterns.
  • searchFiles modification:

    • Updated to apply the escaping logic to all include patterns before processing.
  • Special characters handled:

    • () (parentheses)
    • [] (square brackets)
    • {} (curly brackets)

Checklist

  • Run npm run test and ensure all tests pass
  • Run npm run lint and resolve any linting issues

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2025

Warning

Rate limit exceeded

@yamadashy has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 18 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b92fbac and 86de7c1.

📒 Files selected for processing (2)
  • src/core/file/fileSearch.ts (2 hunks)
  • tests/core/file/fileSearch.test.ts (2 hunks)
📝 Walkthrough

Walkthrough

This pull request introduces a new function, escapeGlobPattern, in the file search module. The function is responsible for escaping special characters in glob patterns, specifically targeting paths that include parentheses. Patterns in the config.include array are processed through escapeGlobPattern to ensure that characters like ( and ) are correctly escaped, which enhances the handling of special characters during file searching. While the overall control flow of the searchFiles function remains unchanged, the treatment of include patterns is now more robust, improving the accuracy of file matching.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant searchFiles
    participant escapeGlobPattern

    Caller->>searchFiles: Invoke searchFiles(config)
    searchFiles->>escapeGlobPattern: For each pattern in config.include
    escapeGlobPattern-->>searchFiles: Return escaped pattern
    searchFiles->>Caller: Return searched file list
Loading

Possibly related PRs

  • feat(website): Add include patterns support to web interface #249: The changes in the main PR, specifically the introduction of the escapeGlobPattern function and its application to the includePatterns variable, are directly related to the handling of patterns, which aligns with the modifications in the retrieved PR that also focus on managing user-defined patterns for inclusion.

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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
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: 0

🧹 Nitpick comments (1)
src/core/file/fileSearch.ts (1)

60-66: Consider enhancing the glob pattern escaping.

While the current implementation handles parentheses and brackets, consider extending it to handle other special glob characters like *, ?, !, +, @, and !.

Apply this diff to enhance the function:

 const escapeGlobPattern = (pattern: string): string => {
-  return pattern.replace(/[()[\]{}]/g, '\\$&');
+  if (typeof pattern !== 'string') {
+    throw new TypeError('Pattern must be a string');
+  }
+  return pattern.replace(/[()[\]{}*?!+@]/g, '\\$&');
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 836abcd and 317bd4d.

📒 Files selected for processing (1)
  • src/core/file/fileSearch.ts (2 hunks)
🔇 Additional comments (1)
src/core/file/fileSearch.ts (1)

80-81: LGTM!

The changes correctly apply the escapeGlobPattern function to each include pattern while maintaining the default behavior.

- Add escapeGlobPattern function to handle special characters
- Modify searchFiles to escape include patterns
- Handle (), [], and {} characters in paths
@yamadashy yamadashy force-pushed the fix/support-parentheses-in-paths branch from 317bd4d to aefed00 Compare February 7, 2025 16:02
@codecov
Copy link

codecov bot commented Feb 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.38%. Comparing base (b6dc403) to head (86de7c1).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #337      +/-   ##
==========================================
+ Coverage   90.36%   90.38%   +0.01%     
==========================================
  Files          48       48              
  Lines        2626     2631       +5     
  Branches      541      542       +1     
==========================================
+ Hits         2373     2378       +5     
  Misses        253      253              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

* Example: "src/(categories)" -> "src/\\(categories\\)"
*/
const escapeGlobPattern = (pattern: string): string => {
return pattern.replace(/[()[\]{}]/g, '\\$&');

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.
Copy link
Owner

Choose a reason for hiding this comment

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

fixed

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

🧹 Nitpick comments (1)
tests/core/file/fileSearch.test.ts (1)

347-376: Great test coverage! Consider adding a few more edge cases.

The test suite is well-structured and covers essential scenarios including basic escaping, multiple bracket types, nested brackets, and edge cases.

Consider adding test cases for:

  1. Invalid inputs (e.g., unmatched brackets)
  2. Paths with spaces (e.g., 'src/(my folder)/**/*.ts')

Example test cases:

test('should handle paths with spaces', () => {
  const pattern = 'src/(my folder)/**/*.ts';
  expect(escapeGlobPattern(pattern)).toBe('src/\\(my folder\\)/**/*.ts');
});

test('should handle unmatched brackets', () => {
  const pattern = 'src/(incomplete/**/*.ts';
  expect(escapeGlobPattern(pattern)).toBe('src/\\(incomplete/**/*.ts');
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aefed00 and b92fbac.

📒 Files selected for processing (2)
  • src/core/file/fileSearch.ts (2 hunks)
  • tests/core/file/fileSearch.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/core/file/fileSearch.ts
🔇 Additional comments (1)
tests/core/file/fileSearch.test.ts (1)

8-14: LGTM!

The import of escapeGlobPattern is properly organized with related functions.

@yamadashy
Copy link
Owner

Hi, @matheuscoelhomalta !
Thank you for your contribution!
I hadn't noticed this issue. Really appreciate you pointing it out.

The code with the added test cases looks perfect!

I'll merge this now.
Feel free to reach out if you have any other improvements or ideas!

@yamadashy yamadashy merged commit 091df27 into yamadashy:main Feb 7, 2025
53 checks passed
@yamadashy
Copy link
Owner

yamadashy commented Apr 19, 2025

I've made a change to prevent escaping curly braces {} in glob patterns, as it was causing issues with pattern matching.

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