Skip to content

refactor: first step toward ESLint 10 support#454

Merged
SukkaW merged 5 commits into
un-ts:masterfrom
SukkaW:eslint-10
Feb 20, 2026
Merged

refactor: first step toward ESLint 10 support#454
SukkaW merged 5 commits into
un-ts:masterfrom
SukkaW:eslint-10

Conversation

@SukkaW

@SukkaW SukkaW commented Feb 15, 2026

Copy link
Copy Markdown
Collaborator

Fixes #452 and #455 , and a step toward #438.


Important

Refactor for ESLint 10 support by updating sourceType determination and merging parser functions in parse.ts and source-type.ts.

  • Behavior:
    • sourceType in source-type.ts now prefers context.languageOptions over context.parserOptions for ESLint 10 compatibility.
    • Access to context.parserOptions is now guarded to prevent crashes with ESLint 10.
  • Refactor:
    • Merged getParser and getParserPath into getParserOrPath in parse.ts to streamline parser selection logic.
  • Misc:
    • Renamed path to nodePath in parse.ts to avoid conflicts.

This description was created by Ellipsis for 742e0d2. You can customize this summary. It will automatically update as commits are pushed.


Summary by CodeRabbit

  • Chores

    • Preparation for ESLint 10 compatibility.
  • Refactor

    • Improved parser resolution and selection to better honor alternate/custom parsers and avoid crashes with newer ESLint.
    • Source type detection now prioritizes modern configuration fields with backward-compatible fallbacks.
    • Internal parser helper logic consolidated for simpler, more reliable parsing behavior.

@SukkaW SukkaW requested review from JounQin and Copilot February 15, 2026 05:23
@changeset-bot

changeset-bot Bot commented Feb 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 742e0d2

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 Patch

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

@ellipsis-dev ellipsis-dev Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to a58501c in 6 seconds. Click for details.
  • Reviewed 101 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.

Workflow ID: wflow_TVOcxA287xjliOKs

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@coderabbitai

coderabbitai Bot commented Feb 15, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

A changeset adds a patch note for ESLint 10 support. Parser resolution in src/utils/parse.ts is consolidated into getParserOrPath with custom-parser and fallback logic. src/utils/source-type.ts now prioritizes languageOptions for sourceType resolution with a parserOptions fallback to avoid undefined access.

Changes

Cohort / File(s) Summary
Changeset
.changeset/some-moments-trade.md
Add patch release note documenting initial ESLint 10 support steps.
Parser resolution & parsing flow
src/utils/parse.ts
Merge getParser/getParserPath into getParserOrPath; resolve parsers from context.settings['import-x/parsers'], fall back to context.parserPath, update parse to call new resolver; adjust parser object checks and imports.
Source type resolution
src/utils/source-type.ts
Prioritize context.languageOptions.parserOptions?.sourceType then languageOptions.sourceType; retain fallback to context.parserOptions.sourceType to avoid undefined errors with older ESLint.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

refactor

Suggested reviewers

  • JounQin

Poem

🐰
A parser path I sniffed and shared,
Settings checked, no crash declared.
SourceType now finds its way,
ESLint ten inches closer today.
Hoppity hop — code neatly paired!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 'refactor: first step toward ESLint 10 support' accurately describes the main objective of the changeset, which involves refactoring code to improve ESLint 10 compatibility.
Linked Issues check ✅ Passed The PR addresses issue #452 by guarding sourceType access and preferring context.languageOptions to prevent TypeError crashes. It also implements the getParserOrPath consolidation described in the objectives.
Out of Scope Changes check ✅ Passed All changes are directly related to ESLint 10 support: refactoring sourceType resolution, consolidating parser resolution logic, and guarding against undefined context properties. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@codesandbox-ci

codesandbox-ci Bot commented Feb 15, 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.

@pkg-pr-new

pkg-pr-new Bot commented Feb 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 742e0d2

@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/parse.ts (1)

188-196: ⚠️ Potential issue | 🔴 Critical

Bug: typeof parse references the module-level export, not parser.parse.

On line 191, typeof parse === 'function' resolves to the parse function exported at line 71 of this file — it's always true. The intended check is typeof parser.parse === 'function', consistent with the parseForESLint check on line 193.

This means any object with a parse property (regardless of type) passes validation, which could lead to a runtime error later if parser.parse isn't actually callable.

🐛 Proposed fix
   if (
     parser &&
     typeof parser !== 'string' &&
-    (('parse' in parser && typeof parse === 'function') ||
+    (('parse' in parser && typeof parser.parse === 'function') ||
       ('parseForESLint' in parser &&
         typeof parser.parseForESLint === 'function'))
   ) {

Copilot AI 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.

Pull request overview

This PR takes the first step toward ESLint 10 support by refactoring how the plugin accesses parser configuration, specifically addressing a critical crash bug (#452) and preparing for the removal of context.parserPath in ESLint 10.

Changes:

  • Fixed TypeError crash when context.parserOptions is undefined by adding proper existence guards and prioritizing languageOptions (flat config) over legacy parserOptions
  • Consolidated getParser and getParserPath into a single getParserOrPath function with proper guards for context.parserPath access
  • Renamed path import to nodePath to avoid naming conflicts with function parameters

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/utils/source-type.ts Refactored to prioritize languageOptions over parserOptions with proper guards, fixing the crash from issue #452
src/utils/parse.ts Merged parser resolution logic into getParserOrPath, added guards for context.parserPath, and renamed path import to avoid conflicts
.changeset/some-moments-trade.md Added changeset documenting this as a patch release for ESLint 10 support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SukkaW SukkaW marked this pull request as draft February 15, 2026 14:23
@SukkaW SukkaW marked this pull request as ready for review February 20, 2026 02:05

@ellipsis-dev ellipsis-dev Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 742e0d2 in 9 seconds. Click for details.
  • Reviewed 122 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.

Workflow ID: wflow_9n1Cq20mQuklRvRV

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@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.

🧹 Nitpick comments (1)
src/utils/parse.ts (1)

186-196: Parser object validation looks correct but consider a small readability improvement.

The validation checks both parse and parseForESLint methods, matching the ESLint parser contract. The condition on lines 188–194 is somewhat dense with the mixed in checks and typeof guards.

Consider a minor restructuring for readability:

Optional: extract a helper for parser validation
+function isParserModule(
+  parser: unknown,
+): parser is TSESLint.Parser.ParserModule {
+  return (
+    parser != null &&
+    typeof parser !== 'string' &&
+    (('parse' in parser && typeof (parser as Record<string, unknown>).parse === 'function') ||
+      ('parseForESLint' in parser &&
+        typeof (parser as Record<string, unknown>).parseForESLint === 'function'))
+  )
+}

This would simplify the condition in getParserOrPath and could be reused if parser validation is needed elsewhere.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/utils/parse.ts` around lines 186 - 196, The parser validation condition
is dense and should be extracted for readability: create a helper function
(e.g., isValidParser) that accepts the parser value and returns true if it's a
non-string object implementing either a callable parse or parseForESLint method,
then replace the inlined conditional inside getParserOrPath (the block that
checks the parser const) with a call to isValidParser(parser) and cast/return as
TSESLint.Parser.ParserModule when true; keep the same runtime checks
(non-string, 'parse' in parser && typeof parse === 'function', or
'parseForESLint' in parser && typeof parseForESLint === 'function') so behavior
is unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/utils/parse.ts`:
- Around line 186-196: The parser validation condition is dense and should be
extracted for readability: create a helper function (e.g., isValidParser) that
accepts the parser value and returns true if it's a non-string object
implementing either a callable parse or parseForESLint method, then replace the
inlined conditional inside getParserOrPath (the block that checks the parser
const) with a call to isValidParser(parser) and cast/return as
TSESLint.Parser.ParserModule when true; keep the same runtime checks
(non-string, 'parse' in parser && typeof parse === 'function', or
'parseForESLint' in parser && typeof parseForESLint === 'function') so behavior
is unchanged.

@SukkaW SukkaW requested a review from 43081j February 20, 2026 03:13
@SukkaW SukkaW merged commit d3f8d67 into un-ts:master Feb 20, 2026
46 checks passed
@SukkaW SukkaW mentioned this pull request Feb 20, 2026
@SukkaW SukkaW deleted the eslint-10 branch March 1, 2026 15:10
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.

TypeError in @import/unambiguous crashes linter

3 participants