Change Request: Expose the active language ID to rules
ESLint version
v10.9.1
What problem do you want to solve?
Rules can declare meta.languages but the active language ID is not available through the rule context.
For example, json/json, json/jsonc, and json/json5 normally have identical context.languageOptions and use the same SourceCode implementation. A rule therfore cannot reliably determine which JSON language is active.
The filename extension cannot identify the language reliably. Flat config can assign any language to any filename pattern, files can be linted from stdin using a virtual filename, processors can create virtual files, and .json files may intentionally use JSONC or JSON5. The configured language is the source of truth, not the filename.
This matters when behavior differs by language. An autofix may emit \v or \0 for JSON5, but those escapes are invalid in JSON and JSONC. Today, a rule must guess from the filename, require a redundant option, or omit otherwise valid behaviour.
What do you think is the correct solution?
Expose the active runtime language identifier as a read-only rule context property:
context.languageId === 'json/json5'This should use the same normalized identifier semantics as meta.languages, ideally using the plugin's meta.namespace so configuring a plugin under an alias does not change rule behavior.
A string identifier is preferable to exposing the resolved language object. This information should not be added to languageOptions because it describes ESLint's execution context rather than parser or language configuration.
Participation
- I am willing to submit a pull request for this change.
AI acknowledgment
- I did not use AI to generate this issue report.
- (If the above is not checked) I have reviewed the AI-generated content before submitting.
Additional comments
No response
Source: eslint/eslint