feat!: add meta.languages to JSON rules#238
Conversation
lumirlumir
left a comment
There was a problem hiding this comment.
After further investigation, I've found that this change could lead to a breaking change for end-users in a way different from what was mentioned in Markdown.
For instance, if we use the default setup described in the README.md as shown below, it works correctly.
// eslint.config.js
import { defineConfig } from "eslint/config";
import json from "@eslint/json";
export default defineConfig([
{
plugins: {
json,
},
},
// lint JSON files
{
files: ["**/*.json"],
language: "json/json",
rules: {
"json/no-duplicate-keys": "error",
},
},
// lint JSONC files
{
files: ["**/*.jsonc", ".vscode/*.json"],
language: "json/jsonc",
rules: {
"json/no-duplicate-keys": "error",
},
},
// lint JSON5 files
{
files: ["**/*.json5"],
language: "json/json5",
rules: {
"json/no-duplicate-keys": "error",
},
},
]);However, what if a user prefers a different namespace, such as eslintjson, instead of json?
Suppose we have a configuration like the one below, which uses the eslintjson namespace:
// eslint.config.js
import { defineConfig } from "eslint/config";
import eslintjson from "@eslint/json";
export default defineConfig([
{
plugins: {
eslintjson,
},
},
// lint JSON files
{
files: ["**/*.json"],
language: "eslintjson/json",
rules: {
"eslintjson/no-duplicate-keys": "error",
},
},
// lint JSONC files
{
files: ["**/*.jsonc", ".vscode/*.json"],
language: "eslintjson/jsonc",
rules: {
"eslintjson/no-duplicate-keys": "error",
},
},
// lint JSON5 files
{
files: ["**/*.json5"],
language: "eslintjson/json5",
rules: {
"eslintjson/no-duplicate-keys": "error",
},
},
]);The newly added languages: ["json/json", "json/jsonc", "json/json5"] field prevents the above configuration from working and throws an error like this:
Oops! Something went wrong! :(
ESLint: 10.3.0
The following rules do not support the language "eslintjson/json":
- "eslintjson/no-empty-keys"
To fix this error, either:
- Remove the rule from your configuration, or set its severity to "off".
- Use the "files" option to apply the rule only to files of the supported language, for example:
{
files: ["**/*.js"],
rules: { "eslintjson/no-empty-keys": "error" }
}
See https://eslint.org/docs/latest/use/configure/rules for more information.Before adding the languages field, this configuration worked correctly. It only fails after the addition of the languages field.
It seems this implies that the newly added languages field restricts the namespace to only those explicitly described. Previously, users were not restricted by the namespace used in the rule, allowing them to use eslintjson, eslintcorejson, or any other prefix they preferred instead of json.
For example, if a user uses two different JSON plugins, such as eslint-plugin-json, they might want to use distinct namespaces for each—like json1/rule-name for @eslint/json and json2/rule-name for eslint-plugin-json.
This change could potentially break that scenario.
|
The problem lumir mentioned could be solved if the core normalizes the language id by using |
|
Yes, this is a bug in the core implementation. It should normalize the namespace used for language resolution. Can you open a bug for that? |
|
It seems like an issue hasn't been opened yet. I can open one. |
fasttime
left a comment
There was a problem hiding this comment.
We need to add namespace: "json" in the plugin's meta object to avoid the problem described in #238 (review).
Lines 20 to 23 in 720c43d
lumirlumir
left a comment
There was a problem hiding this comment.
I think it would also be helpful to add an integration test in tests/plugin/eslint.test.js to verify the behavior mentioned in #238 (review) and prevent any potential regressions.
https://github.com/eslint/json/blob/main/tests/plugin/eslint.test.js
| "c8": "^11.0.0", | ||
| "dedent": "^1.5.3", | ||
| "eslint": "^10.0.0", | ||
| "eslint": "^10.4.0", |
There was a problem hiding this comment.
Updated ESLint so the test runs with meta.languages enforcement, which was added in 10.2.0.
fasttime
left a comment
There was a problem hiding this comment.
I think this PR should be considered a breaking change for this plugin and tagged as feat!, because it may break compatibility with existing configs, even if that's a desired effect. Other than that, the changes LGTM.
lumirlumir
left a comment
There was a problem hiding this comment.
LGTM, thanks!
I think this PR should be considered a breaking change for this plugin and tagged as feat!, because it may break compatibility with existing configs, even if that's a desired effect.
While I can no longer find a certain failure scenario with this setup, there might be some edge cases we’re all missing. I think it may make sense to defer this change to the next major version for safety.
meta.languages to JSON rulesmeta.languages to JSON rules
Prerequisites checklist
AI acknowledgment
What is the purpose of this pull request?
This PR adds
meta.languagesto rules, following the decision made during the TSC meeting on 16-Apr-2026.What changes did you make? (Give an overview)
Added
meta.languagesto rule definitions andmeta.docs.dialectsto their docs metadata.Related Issues
eslint/eslint#20716 (comment)
Is there anything you'd like reviewers to focus on?