feat: support RegExp in ignore - #474
Conversation
🦋 Changeset detectedLatest commit: 7aa4640 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds support for passing RegExp objects in the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment Tip CodeRabbit can use oxc to improve the quality of JavaScript and TypeScript code reviews.Add a configuration file to your project to customize how CodeRabbit runs oxc. |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/utils/module-visitor.ts (1)
18-32:⚠️ Potential issue | 🟠 MajorHarden ignore normalization and make regex matching deterministic.
Now that
ignoreaccepts realRegExpvalues, using.test()on shared/gor/yregexes is stateful and can miss matches across imports. Also, with item schema loosened, non-string/RegExpvalues can be silently coerced bynew RegExp(...).🔧 Proposed fix
export function moduleVisitor(visitor: Visitor, options?: ModuleOptions) { const ignore = options?.ignore @@ - const ignoreRegExps = ignore == null ? [] : ignore.map(p => new RegExp(p)) + const ignoreRegExps = + ignore == null + ? [] + : ignore.map(pattern => { + if (pattern instanceof RegExp) { + return pattern + } + if (typeof pattern === 'string') { + return new RegExp(pattern) + } + throw new TypeError('`ignore` must contain only string or RegExp values') + }) @@ - if (ignoreRegExps.some(re => re.test(String(source.value)))) { + if ( + ignoreRegExps.some(re => { + re.lastIndex = 0 + return re.test(String(source.value)) + }) + ) { return }Applies to: lines 18-32, 49-50, 203-207
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/utils/module-visitor.ts` around lines 18 - 32, Normalize the options.ignore array in moduleVisitor by validating each item: accept RegExp instances and strings only, throw or skip invalid types; for RegExp items create a fresh RegExp using the original pattern and flags but strip stateful flags ('g' and 'y') so .test is deterministic, and for string items create a RegExp from the string (escaping or intended pattern per existing behavior) rather than passing through to new RegExp blindly; replace the current ignore.map -> ignoreRegExps logic to produce these clean, stateless regexes (used where ignoreRegExps and related matching at the places referenced) so matching no longer depends on shared regex state.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/utils/module-visitor.ts`:
- Around line 18-32: Normalize the options.ignore array in moduleVisitor by
validating each item: accept RegExp instances and strings only, throw or skip
invalid types; for RegExp items create a fresh RegExp using the original pattern
and flags but strip stateful flags ('g' and 'y') so .test is deterministic, and
for string items create a RegExp from the string (escaping or intended pattern
per existing behavior) rather than passing through to new RegExp blindly;
replace the current ignore.map -> ignoreRegExps logic to produce these clean,
stateless regexes (used where ignoreRegExps and related matching at the places
referenced) so matching no longer depends on shared regex state.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 41cf9077-5afd-4bf3-afb5-257e279484e7
📒 Files selected for processing (4)
README.mddocs/rules/no-unresolved.mdsrc/utils/module-visitor.tstest/rules/no-unresolved.spec.ts
commit: |
SukkaW
left a comment
There was a problem hiding this comment.
Please add a changeset via yarn changeset
Fix #464
Support
RegExpin theimport-x/ignoresetting and theignoreoption of theno-unresolvedrule.I removed the item type (as with the
ignoreoption in theunicorn/catch-error-namerule), because JSONSchema doesn't have a type forRegExp.I didn't change the
ignoretoignoreRegExpsconversion because theRegExpconstructor accepts anotherRegExpas a parameter.Summary by CodeRabbit
New Features
ignoreoption now accepts both RegExp objects and string patterns for more flexible module-ignore matching.Documentation
ignoreoption across relevant files.Tests
Chores