Skip to content

Change Request: Missing TokenStore methods in JSONSourceCode breaks compatibility with ESLint utilities #83

Open
@azat-io

Description

@azat-io

Environment

ESLint version: 9.21.0
@eslint/json version: 0.10.0
Node version: 22.14.0
npm version: 10.9.2
Operating System: MacOS

What problem do you want to solve?

The JSONSourceCode class in @eslint/json lacks important methods that exist in the standard ESLint SourceCode, specifically getTokenBefore and getTokenAfter. These methods are essential for many common ESLint rule utilities and helpers that manipulate tokens.

When trying to create utilities that work with both JavaScript/TypeScript (ESTree) and JSON (Momoa) ASTs, the difference in the API between SourceCode and JSONSourceCode forces developers to implement complex workarounds or separate code paths.

What do you think is the correct solution?

Add getTokenBefore and getTokenAfter methods to JSONSourceCode to maintain API compatibility with standard ESLint's SourceCode. This would allow utilities and helpers to work with both JavaScript and JSON files without special handling.

Ideally, @eslint/json would implement a similar TokenStore class or inherit from the original one to ensure complete API compatibility.

Participation

  • I am willing to submit a pull request for this change.

Additional comments

This change would significantly improve developer experience when:

  • Creating ESLint plugins that work with both JS/TS and JSON files
  • Reusing utility functions across JS/TS and JSON rules
  • Building tools that interact with both types of ASTs

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Implementing

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions