You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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?
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 ESLintSourceCode
, specificallygetTokenBefore
andgetTokenAfter
. 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
andJSONSourceCode
forces developers to implement complex workarounds or separate code paths.What do you think is the correct solution?
Add
getTokenBefore
andgetTokenAfter
methods toJSONSourceCode
to maintain API compatibility with standard ESLint'sSourceCode
. This would allow utilities and helpers to work with both JavaScript and JSON files without special handling.Ideally,
@eslint/json
would implement a similarTokenStore
class or inherit from the original one to ensure complete API compatibility.Participation
Additional comments
This change would significantly improve developer experience when:
The text was updated successfully, but these errors were encountered: