Skip to content

Commit 36b9fc7

Browse files
authored
fix: flat config issues (#315)
1 parent 016fa43 commit 36b9fc7

File tree

5 files changed

+63
-8
lines changed

5 files changed

+63
-8
lines changed

.changeset/rude-plums-relate.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-jsonc": patch
3+
---
4+
5+
fix: flat config issues

lib/configs/flat/base.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import type { ESLint } from "eslint";
22
import * as parser from "jsonc-eslint-parser";
33
export default [
4+
{
5+
plugins: {
6+
get jsonc(): ESLint.Plugin {
7+
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore
8+
return require("../../index");
9+
},
10+
},
11+
},
412
{
513
files: [
614
"*.json",
@@ -10,12 +18,6 @@ export default [
1018
"*.jsonc",
1119
"**/*.jsonc",
1220
],
13-
plugins: {
14-
get jsonc(): ESLint.Plugin {
15-
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore
16-
return require("../../index");
17-
},
18-
},
1921
languageOptions: {
2022
parser,
2123
},

lib/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import recommendedWithJsonc from "./configs/recommended-with-jsonc";
77
import recommendedWithJson5 from "./configs/recommended-with-json5";
88
import prettier from "./configs/prettier";
99
import all from "./configs/all";
10-
import flatBase from "./configs/base";
10+
import flatBase from "./configs/flat/base";
1111
import flatRecommendedWithJson from "./configs/flat/recommended-with-json";
1212
import flatRecommendedWithJsonc from "./configs/flat/recommended-with-jsonc";
1313
import flatRecommendedWithJson5 from "./configs/flat/recommended-with-json5";
1414
import flatPrettier from "./configs/flat/prettier";
15-
import flatAll from "./configs/all";
15+
import flatAll from "./configs/flat/all";
1616
import * as meta from "./meta";
1717

1818
// backward compatibility

tests/lib/configs/flat/base.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import assert from "assert";
2+
import plugin from "../../../../lib/index";
3+
import { ESLint } from "../../test-lib/eslint-compat";
4+
5+
const code = `{ foo: 42 }`;
6+
describe("`flat/base` config", () => {
7+
it("`flat/base` config should work. ", async () => {
8+
const linter = new ESLint({
9+
overrideConfigFile: true as never,
10+
overrideConfig: plugin.configs["flat/base"] as never,
11+
});
12+
const result = await linter.lintText(code, { filePath: "test.json" });
13+
const messages = result[0].messages;
14+
15+
assert.deepStrictEqual(
16+
messages.map((m) => ({
17+
ruleId: m.ruleId,
18+
line: m.line,
19+
message: m.message,
20+
})),
21+
[],
22+
);
23+
24+
const resultWithJs = await linter.lintText(";", { filePath: "test.js" });
25+
const messagesWithJs = resultWithJs[0].messages;
26+
27+
assert.deepStrictEqual(
28+
messagesWithJs.map((m) => ({
29+
ruleId: m.ruleId,
30+
line: m.line,
31+
message: m.message,
32+
})),
33+
[],
34+
);
35+
});
36+
});

tests/lib/configs/recommended-with-json.ts

+12
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,17 @@ describe("`recommended-with-json` config", () => {
5757
},
5858
],
5959
);
60+
61+
const resultWithJs = await linter.lintText(";", { filePath: "test.js" });
62+
const messagesWithJs = resultWithJs[0].messages;
63+
64+
assert.deepStrictEqual(
65+
messagesWithJs.map((m) => ({
66+
ruleId: m.ruleId,
67+
line: m.line,
68+
message: m.message,
69+
})),
70+
[],
71+
);
6072
});
6173
});

0 commit comments

Comments
 (0)