Skip to content

Commit e68c04b

Browse files
committed
fix: fix regression of jsonc file with trailing comma or empty
1 parent ebdfee3 commit e68c04b

8 files changed

Lines changed: 169 additions & 45 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@
6565
},
6666
"dependencies": {
6767
"generate-differences": "^0.1.1",
68-
"load-oxfmt-config": "^0.7.1",
68+
"load-oxfmt-config": "^0.7.2",
6969
"picomatch": "^4.0.4",
7070
"synckit": "^0.11.12"
7171
},
7272
"devDependencies": {
7373
"@ntnyq/eslint-config": "^6.1.3",
7474
"@types/json-schema": "^7.0.15",
7575
"@types/node": "^25.6.2",
76-
"@typescript/native-preview": "^7.0.0-dev.20260507.1",
76+
"@typescript/native-preview": "^7.0.0-dev.20260508.1",
7777
"bumpp": "^11.1.0",
7878
"eslint": "^10.3.0",
7979
"eslint-parser-plain": "^0.1.1",

pnpm-lock.yaml

Lines changed: 43 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/__snapshots__/eslint-plugin.test.ts.snap

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,104 @@ format(
420420
}
421421
`;
422422

423+
exports[`should load .oxfmtrc.jsonc with trailing comma 1`] = `
424+
{
425+
"fixture": "jsonc-trailing-comma",
426+
"summary": [
427+
{
428+
"file": "src/example.js",
429+
"messages": [
430+
{
431+
"column": 3,
432+
"endColumn": 32,
433+
"endLine": 2,
434+
"fix": {
435+
"text": "console.log(
436+
'hello world',
437+
)",
438+
},
439+
"line": 2,
440+
"message": "Replace \`··console.log("hello·world");\` with \`console.log(⏎····'hello·world',⏎··)\`",
441+
"messageId": "replace",
442+
"ruleId": "oxfmt/oxfmt",
443+
"severity": 2,
444+
},
445+
{
446+
"column": 8,
447+
"endColumn": 43,
448+
"endLine": 5,
449+
"fix": {
450+
"text": "
451+
reallyLongArg(),
452+
anotherLongArg(),",
453+
},
454+
"line": 5,
455+
"message": "Replace \`reallyLongArg(),·anotherLongArg());\` with \`⏎··reallyLongArg(),⏎··anotherLongArg(),\`",
456+
"messageId": "replace",
457+
"ruleId": "oxfmt/oxfmt",
458+
"severity": 2,
459+
},
460+
{
461+
"column": 1,
462+
"endColumn": 1,
463+
"endLine": 6,
464+
"fix": {
465+
"text": ")",
466+
},
467+
"line": 6,
468+
"message": "Insert \`)\`",
469+
"messageId": "insert",
470+
"ruleId": "oxfmt/oxfmt",
471+
"severity": 2,
472+
},
473+
],
474+
"output": "export function greet() {
475+
console.log(
476+
'hello world',
477+
)
478+
}
479+
480+
format(
481+
reallyLongArg(),
482+
anotherLongArg(),
483+
)",
484+
},
485+
],
486+
}
487+
`;
488+
489+
exports[`should load empty .oxfmtrc.jsonc 1`] = `
490+
{
491+
"fixture": "jsonc-empty",
492+
"summary": [
493+
{
494+
"file": "src/example.js",
495+
"messages": [
496+
{
497+
"column": 3,
498+
"endColumn": 5,
499+
"endLine": 2,
500+
"fix": {
501+
"text": "",
502+
},
503+
"line": 2,
504+
"message": "Delete \`··\`",
505+
"messageId": "delete",
506+
"ruleId": "oxfmt/oxfmt",
507+
"severity": 2,
508+
},
509+
],
510+
"output": "export function greet() {
511+
console.log("hello world");
512+
}
513+
514+
format(reallyLongArg(), anotherLongArg());
515+
",
516+
},
517+
],
518+
}
519+
`;
520+
423521
exports[`should load oxfmt.config.ts 1`] = `
424522
{
425523
"fixture": "ts-config",

tests/eslint-plugin.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ const CONFIG_LOADER_FIXTURES = [
322322
cwd: resolve('tests/fixtures/config-loading/jsonc'),
323323
title: 'should load .oxfmtrc.jsonc',
324324
},
325+
{
326+
cwd: resolve('tests/fixtures/config-loading/jsonc-trailing-comma'),
327+
title: 'should load .oxfmtrc.jsonc with trailing comma',
328+
},
329+
{
330+
cwd: resolve('tests/fixtures/config-loading/jsonc-empty'),
331+
title: 'should load empty .oxfmtrc.jsonc',
332+
},
325333
{
326334
cwd: resolve('tests/fixtures/config-loading/ts-config'),
327335
title: 'should load oxfmt.config.ts',

tests/fixtures/config-loading/jsonc-empty/.oxfmtrc.jsonc

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function greet() {
2+
console.log("hello world");
3+
}
4+
5+
format(reallyLongArg(), anotherLongArg());
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
// regression: load-oxfmt-config should accept trailing commas in JSONC.
3+
"insertFinalNewline": false,
4+
"printWidth": 24,
5+
"semi": false,
6+
"singleQuote": true,
7+
"tabWidth": 2,
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function greet() {
2+
console.log("hello world");
3+
}
4+
5+
format(reallyLongArg(), anotherLongArg());

0 commit comments

Comments
 (0)