Skip to content

feat: support RegExp in ignore - #474

Merged
SukkaW merged 1 commit into
un-ts:masterfrom
regseb:ignore-regexp
Mar 16, 2026
Merged

SukkaW merged 1 commit into
un-ts:masterfrom
regseb:ignore-regexp

Conversation

@regseb

@regseb regseb commented Mar 14, 2026 •

Copy link
Copy Markdown
Contributor

Fix #464

Support RegExp in the import-x/ignore setting and the ignore option of the no-unresolved rule.


I removed the item type (as with the ignore option in the unicorn/catch-error-name rule), because JSONSchema doesn't have a type for RegExp.

I didn't change the ignore to ignoreRegExps conversion because the RegExp constructor accepts another RegExp as a parameter.

Summary by CodeRabbit

  • New Features

    • The ignore option now accepts both RegExp objects and string patterns for more flexible module-ignore matching.
  • Documentation

    • Docs updated to clarify RegExp and string pattern support for the ignore option across relevant files.
  • Tests

    • Added tests covering RegExp-based ignores, including case-insensitive patterns and common file-type patterns.
  • Chores

    • Minor package version bump.

@changeset-bot

changeset-bot Bot commented Mar 14, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7aa4640

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-import-x Minor

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

@coderabbitai

coderabbitai Bot commented Mar 14, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a9978d3d-2879-4aef-9848-f88656862e4a

📥 Commits

Reviewing files that changed from the base of the PR and between 0368849 and 7aa4640.

📒 Files selected for processing (5)
  • .changeset/eight-oranges-lie.md
  • README.md
  • docs/rules/no-unresolved.md
  • src/utils/module-visitor.ts
  • test/rules/no-unresolved.spec.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • docs/rules/no-unresolved.md
  • test/rules/no-unresolved.spec.ts
  • README.md

📝 Walkthrough

Walkthrough

Adds support for passing RegExp objects in the ignore option for the importX/no-unresolved rule: type signature changed, docs updated to clarify RegExp or pattern-string usage, and tests extended to cover RegExp and case-insensitive patterns.

Changes

Cohort / File(s) Summary
Documentation
README.md, docs/rules/no-unresolved.md
Clarified ignore option accepts RegExp or RegExp pattern strings (wording only; no behavior change).
Runtime / Types
src/utils/module-visitor.ts
Expanded ModuleOptions.ignore from string[] to Array<RegExp | string> and relaxed schema item constraint accordingly.
Tests
test/rules/no-unresolved.spec.ts
Added test cases exercising RegExp ignores, including case-insensitive and combined extension patterns.
Release Metadata
.changeset/eight-oranges-lie.md
Minor version bump and notes about RegExp support in ignore settings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

enhancement

Suggested reviewers

  • JounQin
  • 43081j

Poem

🐰 I nibble patterns, sharp and small,
Now RegExp leaps within the hall.
Strings or slashes, both are fine,
My hops accept each matching line.
Rejoice — configs wear a brighter shine!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: support RegExp in ignore' accurately and concisely summarizes the main change - adding RegExp support to the ignore option.
Linked Issues check ✅ Passed The PR fully implements the requirements from issue #464: adds RegExp support to the ignore option, updates type signatures from string[] to Array<RegExp | string>, removes restrictive schema items constraint, and updates documentation.
Out of Scope Changes check ✅ Passed All changes are within scope - they relate to supporting RegExp in the ignore option. Test additions exercise the new RegExp functionality, and the changeset documents the feature addition.

✏️ 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
📝 Coding Plan
  • Generate coding plan for human review comments

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.

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.

@codesandbox-ci

codesandbox-ci Bot commented Mar 14, 2026 •

Copy link
Copy Markdown

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 | 🟠 Major

Harden ignore normalization and make regex matching deterministic.

Now that ignore accepts real RegExp values, using .test() on shared /g or /y regexes is stateful and can miss matches across imports. Also, with item schema loosened, non-string/RegExp values can be silently coerced by new 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

📥 Commits

Reviewing files that changed from the base of the PR and between 240ed58 and 0368849.

📒 Files selected for processing (4)
  • README.md
  • docs/rules/no-unresolved.md
  • src/utils/module-visitor.ts
  • test/rules/no-unresolved.spec.ts

@SukkaW SukkaW left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks!

@pkg-pr-new

pkg-pr-new Bot commented Mar 15, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/eslint-plugin-import-x@474

commit: 7aa4640

@SukkaW SukkaW left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add a changeset via yarn changeset

@regseb
regseb requested a review from SukkaW March 15, 2026 07:41
@SukkaW
SukkaW merged commit 4b2c0c5 into un-ts:master Mar 16, 2026
55 checks passed
@regseb
regseb deleted the ignore-regexp branch March 17, 2026 17:07
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.

Support RegExp in ignore option of no-unresolved

2 participants