From 4938c083542a28332e1e3501060258eda83567e3 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Mon, 18 Mar 2024 22:16:19 +0900 Subject: [PATCH 1/4] Create famous-countries-applaud.md --- .changeset/famous-countries-applaud.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/famous-countries-applaud.md diff --git a/.changeset/famous-countries-applaud.md b/.changeset/famous-countries-applaud.md new file mode 100644 index 00000000..9824e534 --- /dev/null +++ b/.changeset/famous-countries-applaud.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-jsonc": minor +--- + +Add support for flat config From 0fe192216f9c7aede529ad25e060629947c6d417 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Tue, 19 Mar 2024 06:52:42 +0900 Subject: [PATCH 2/4] fix: flat config issues --- lib/configs/flat/base.ts | 14 +++++---- lib/index.ts | 4 +-- tests/lib/configs/flat/base.ts | 36 ++++++++++++++++++++++ tests/lib/configs/recommended-with-json.ts | 12 ++++++++ 4 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 tests/lib/configs/flat/base.ts diff --git a/lib/configs/flat/base.ts b/lib/configs/flat/base.ts index 9f75848e..7fee4ee9 100644 --- a/lib/configs/flat/base.ts +++ b/lib/configs/flat/base.ts @@ -1,6 +1,14 @@ import type { ESLint } from "eslint"; import * as parser from "jsonc-eslint-parser"; export default [ + { + plugins: { + get jsonc(): ESLint.Plugin { + // eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore + return require("../../index"); + }, + }, + }, { files: [ "*.json", @@ -10,12 +18,6 @@ export default [ "*.jsonc", "**/*.jsonc", ], - plugins: { - get jsonc(): ESLint.Plugin { - // eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore - return require("../../index"); - }, - }, languageOptions: { parser, }, diff --git a/lib/index.ts b/lib/index.ts index e22757fb..2ba7fe8b 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -7,12 +7,12 @@ import recommendedWithJsonc from "./configs/recommended-with-jsonc"; import recommendedWithJson5 from "./configs/recommended-with-json5"; import prettier from "./configs/prettier"; import all from "./configs/all"; -import flatBase from "./configs/base"; +import flatBase from "./configs/flat/base"; import flatRecommendedWithJson from "./configs/flat/recommended-with-json"; import flatRecommendedWithJsonc from "./configs/flat/recommended-with-jsonc"; import flatRecommendedWithJson5 from "./configs/flat/recommended-with-json5"; import flatPrettier from "./configs/flat/prettier"; -import flatAll from "./configs/all"; +import flatAll from "./configs/flat/all"; import * as meta from "./meta"; // backward compatibility diff --git a/tests/lib/configs/flat/base.ts b/tests/lib/configs/flat/base.ts new file mode 100644 index 00000000..1f249b1a --- /dev/null +++ b/tests/lib/configs/flat/base.ts @@ -0,0 +1,36 @@ +import assert from "assert"; +import plugin from "../../../../lib/index"; +import { ESLint } from "../../test-lib/eslint-compat"; + +const code = `{ foo: 42 }`; +describe("`flat/base` config", () => { + it("`flat/base` config should work. ", async () => { + const linter = new ESLint({ + overrideConfigFile: true as never, + overrideConfig: plugin.configs["flat/base"] as never, + }); + const result = await linter.lintText(code, { filePath: "test.json" }); + const messages = result[0].messages; + + assert.deepStrictEqual( + messages.map((m) => ({ + ruleId: m.ruleId, + line: m.line, + message: m.message, + })), + [], + ); + + const resultWithJs = await linter.lintText(";", { filePath: "test.js" }); + const messagesWithJs = resultWithJs[0].messages; + + assert.deepStrictEqual( + messagesWithJs.map((m) => ({ + ruleId: m.ruleId, + line: m.line, + message: m.message, + })), + [], + ); + }); +}); diff --git a/tests/lib/configs/recommended-with-json.ts b/tests/lib/configs/recommended-with-json.ts index e5dd44aa..47940207 100644 --- a/tests/lib/configs/recommended-with-json.ts +++ b/tests/lib/configs/recommended-with-json.ts @@ -57,5 +57,17 @@ describe("`recommended-with-json` config", () => { }, ], ); + + const resultWithJs = await linter.lintText(";", { filePath: "test.js" }); + const messagesWithJs = resultWithJs[0].messages; + + assert.deepStrictEqual( + messagesWithJs.map((m) => ({ + ruleId: m.ruleId, + line: m.line, + message: m.message, + })), + [], + ); }); }); From 70e26abd91c05c88880b5ba37660ba20137f5b10 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Tue, 19 Mar 2024 06:53:48 +0900 Subject: [PATCH 3/4] fix --- .changeset/famous-countries-applaud.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .changeset/famous-countries-applaud.md diff --git a/.changeset/famous-countries-applaud.md b/.changeset/famous-countries-applaud.md deleted file mode 100644 index 9824e534..00000000 --- a/.changeset/famous-countries-applaud.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"eslint-plugin-jsonc": minor ---- - -Add support for flat config From 65357b9a89ffeaa0fcd1ef8d470d5bb6b30191a4 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Tue, 19 Mar 2024 06:54:31 +0900 Subject: [PATCH 4/4] Create rude-plums-relate.md --- .changeset/rude-plums-relate.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/rude-plums-relate.md diff --git a/.changeset/rude-plums-relate.md b/.changeset/rude-plums-relate.md new file mode 100644 index 00000000..8c9b1cfb --- /dev/null +++ b/.changeset/rude-plums-relate.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-jsonc": patch +--- + +fix: flat config issues