Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task
azat-io opened this issue Mar 2, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@azat-io
Copy link

azat-io commented Mar 2, 2025

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
@nzakas
Copy link
Member

nzakas commented Mar 3, 2025

Fundamentally, there is no guarantee that any given language will implement the same methods as the JS SourceCode object, nor is there any guarantee that any one rule can work across multiple languages, so I'm not sure I understand the use case here. Can you give a concrete example?

@nzakas nzakas added this to Triage Mar 3, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Mar 3, 2025
@nzakas nzakas moved this from Needs Triage to Triaging in Triage Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Triaging
Development

No branches or pull requests

2 participants