Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"@types/node": "^20.19.0",
"c8": "^11.0.0",
"dedent": "^1.5.3",
"eslint": "^10.0.0",
"eslint": "^10.4.0",
Copy link
Copy Markdown
Contributor Author

@Pixel998 Pixel998 May 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated ESLint so the test runs with meta.languages enforcement, which was added in 10.2.0.

"eslint-config-eslint": "^14.0.0",
"eslint-plugin-eslint-plugin": "^7.3.2",
"globals": "^17.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import rules from "./build/rules.js";
const plugin = {
meta: {
name: "@eslint/json",
namespace: "json",
version: "1.2.0", // x-release-please-version
},
languages: {
Expand Down
2 changes: 2 additions & 0 deletions src/rules/no-duplicate-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import { getKey, getRawKey } from "../util.js";
const rule = {
meta: {
type: "problem",
languages: ["json/json", "json/jsonc", "json/json5"],

docs: {
recommended: true,
description: "Disallow duplicate keys in JSON objects",
dialects: ["JSON", "JSONC", "JSON5"],
url: "https://github.com/eslint/json/tree/main/docs/rules/no-duplicate-keys.md",
},

Expand Down
2 changes: 2 additions & 0 deletions src/rules/no-empty-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import { getKey } from "../util.js";
const rule = {
meta: {
type: "problem",
languages: ["json/json", "json/jsonc", "json/json5"],

docs: {
recommended: true,
description: "Disallow empty keys in JSON objects",
dialects: ["JSON", "JSONC", "JSON5"],
url: "https://github.com/eslint/json/tree/main/docs/rules/no-empty-keys.md",
},

Expand Down
2 changes: 2 additions & 0 deletions src/rules/no-unnormalized-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ import { getKey, getRawKey } from "../util.js";
const rule = {
meta: {
type: "problem",
languages: ["json/json", "json/jsonc", "json/json5"],

fixable: "code",

docs: {
recommended: true,
description: "Disallow JSON keys that are not normalized",
dialects: ["JSON", "JSONC", "JSON5"],
url: "https://github.com/eslint/json/tree/main/docs/rules/no-unnormalized-keys.md",
},

Expand Down
2 changes: 2 additions & 0 deletions src/rules/no-unsafe-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ const NON_ZERO = /[1-9]/u;
const rule = {
meta: {
type: "problem",
languages: ["json/json", "json/jsonc", "json/json5"],

docs: {
recommended: true,
description: "Disallow JSON values that are unsafe for interchange",
dialects: ["JSON", "JSONC", "JSON5"],
url: "https://github.com/eslint/json/tree/main/docs/rules/no-unsafe-values.md",
},

Expand Down
2 changes: 2 additions & 0 deletions src/rules/sort-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const comparators = {
const rule = {
meta: {
type: "suggestion",
languages: ["json/json", "json/jsonc", "json/json5"],

fixable: "code",

Expand All @@ -95,6 +96,7 @@ const rule = {
docs: {
recommended: false,
description: `Require JSON object keys to be sorted`,
dialects: ["JSON", "JSONC", "JSON5"],
url: "https://github.com/eslint/json/tree/main/docs/rules/sort-keys.md",
},

Expand Down
2 changes: 2 additions & 0 deletions src/rules/top-level-interop.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
const rule = {
meta: {
type: "problem",
languages: ["json/json", "json/jsonc", "json/json5"],

docs: {
recommended: false,
description:
"Require the JSON top-level value to be an array or object",
dialects: ["JSON", "JSONC", "JSON5"],
url: "https://github.com/eslint/json/tree/main/docs/rules/top-level-interop.md",
},

Expand Down
36 changes: 36 additions & 0 deletions tests/plugin/eslint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,42 @@ describe("when the plugin is used with ESLint", () => {
.map(([name]) => `json/${name}`);
assert.deepStrictEqual(actualRuleIds, expectedRuleIds);
});

it("rules should work when the plugin is registered under a custom namespace", async () => {
for (const language of ["json", "jsonc", "json5"]) {
const eslint = new ESLint({
overrideConfigFile: true,
overrideConfig: {
files: [`**/*.${language}`],
plugins: {
eslintjson: json,
},
language: `eslintjson/${language}`,
rules: {
"eslintjson/no-duplicate-keys": "error",
},
},
});

const results = await eslint.lintText(
'{"foo": 42, "foo": 43}',
{
filePath: `test.${language}`,
},
);

assert.strictEqual(results.length, 1);
assert.strictEqual(results[0].messages.length, 1);
assert.strictEqual(
results[0].messages[0].ruleId,
"eslintjson/no-duplicate-keys",
);
assert.strictEqual(
results[0].messages[0].messageId,
"duplicateKey",
);
}
});
});

describe("config comments", () => {
Expand Down
1 change: 1 addition & 0 deletions tests/types/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type { Plugin, SourceLocation, SourceRange } from "@eslint/core";

json satisfies Plugin;
json.meta.name satisfies string;
json.meta.namespace satisfies string;
json.meta.version satisfies string;

// Check that these languages are defined:
Expand Down
Loading