Skip to content

fix: type compatibility issue between JSON v2 and ESLint v9#248

Open
lumirlumir wants to merge 15 commits into
mainfrom
fix/type-compatibility-issue-between-json-v2-and-eslint-9
Open

fix: type compatibility issue between JSON v2 and ESLint v9#248
lumirlumir wants to merge 15 commits into
mainfrom
fix/type-compatibility-issue-between-json-v2-and-eslint-9

Conversation

@lumirlumir

@lumirlumir lumirlumir commented Jun 19, 2026

Copy link
Copy Markdown
Member

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request?

This PR fixes an issue where JSON v2 and ESLint v9 are not type-compatible, as mentioned in #213.

What changes did you make? (Give an overview)

This PR follows the same strategy determined in eslint/markdown#648. That said, a few parts differ from the Markdown implementation, as follows:

  1. For JSON, the type compatibility range is 9.15.0 or above, not 9.39.0. This is because the Markdown plugin has a processor, and the blocker for compatibility with lower ESLint v9 versions was that processor. Since CSS does not have a processor configured, broader type compatibility can be achieved.
  2. As the type compatibility range is now 9.15.0 or above, I intentionally didn’t mention in README.md that type compatibility is ensured for v9.15.0 or above, since the current type compatibility range is the same as the one we already support.

Related Issues

Refs: eslint/markdown#648, eslint/css#473
Fixes: #213

Is there anything you'd like reviewers to focus on?

N/A

@eslint-github-bot eslint-github-bot Bot added the bug Something isn't working label Jun 19, 2026
@eslintbot eslintbot added this to Triage Jun 19, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Jun 19, 2026
@lumirlumir lumirlumir moved this from Needs Triage to Implementing in Triage Jun 19, 2026
let keys;

return {
return /** @type {JSONRuleVisitor} */ ({

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unlike the CSS implementation, if we don’t type-cast the return type with JSONRuleVisitor, a portable type error occurs:

The inferred type of 'create' cannot be named without a reference to 'MemberNode' from '../../node_modules/@humanwhocodes/momoa/dist/typedefs.js'. This is likely not portable. A type annotation is necessary.

This was also why only the JSON plugin used the following snippet:

const rule = { /* ... */ };

export default rule;

Instead of:

export default { /* ... */ };

I’ve tried to find an easy way to resolve it, but I couldn’t find one we could handle on our own.

I think this issue lies with @humanwhocodes/momoa, since the package still uses a dual CJS/ESM setup and type resolution seems to have broken at some point.

Sending a PR to @humanwhocodes/momoa to make it ESM-only may resolve the type issue, since the portable error seems to come from typedefs.ts not being exported directly from the main entry point ./dist/momoa.js, but instead being exported indirectly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure how to export dist/typedefs.ts directly from dist/momoa.js. Do you have an idea?

@lumirlumir lumirlumir marked this pull request as ready for review June 28, 2026 07:21
@lumirlumir lumirlumir moved this from Implementing to Needs Triage in Triage Jun 28, 2026
@lumirlumir lumirlumir requested a review from fasttime June 28, 2026 07:24
@fasttime fasttime moved this from Needs Triage to Triaging in Triage Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted bug Something isn't working

Projects

Status: Triaging

Development

Successfully merging this pull request may close these issues.

Bug: JSON v1.0.1 is not backward-compatible with ESLint v9.39.2

3 participants