File tree Expand file tree Collapse file tree 6 files changed +83
-76
lines changed Expand file tree Collapse file tree 6 files changed +83
-76
lines changed Original file line number Diff line number Diff line change 41
41
"@codemirror/language" : " ^6.10.3" ,
42
42
"@eslint/css" : " ^0.2.0" ,
43
43
"@eslint/js" : " ^9.9.0" ,
44
- "@eslint/json" : " ^0.4.1 " ,
44
+ "@eslint/json" : " ^0.12.0 " ,
45
45
"@eslint/markdown" : " ^6.4.0" ,
46
46
"@lezer/highlight" : " ^1.2.1" ,
47
47
"@radix-ui/react-accordion" : " ^1.2.0" ,
Original file line number Diff line number Diff line change @@ -33,19 +33,39 @@ import type {
33
33
const JSONPanel : React . FC = ( ) => {
34
34
const explorer = useExplorer ( ) ;
35
35
const { jsonOptions, setJsonOptions } = explorer ;
36
- const { jsonMode } = jsonOptions ;
36
+ const { jsonMode, allowTrailingCommas } = jsonOptions ;
37
37
return (
38
- < LabeledSelect
39
- id = "jsonMode"
40
- label = "Mode"
41
- value = { jsonMode }
42
- onValueChange = { ( value : string ) => {
43
- const jsonMode = value as JsonMode ;
44
- setJsonOptions ( { ...jsonOptions , jsonMode } ) ;
45
- } }
46
- items = { jsonModes }
47
- placeholder = "Mode"
48
- />
38
+ < >
39
+ < LabeledSelect
40
+ id = "jsonMode"
41
+ label = "Mode"
42
+ value = { jsonMode }
43
+ onValueChange = { ( value : string ) => {
44
+ const jsonMode = value as JsonMode ;
45
+ setJsonOptions ( { ...jsonOptions , jsonMode } ) ;
46
+ } }
47
+ items = { jsonModes }
48
+ placeholder = "Mode"
49
+ />
50
+
51
+ { jsonMode === "jsonc" && (
52
+ < div className = "flex items-center gap-1.5" >
53
+ < Switch
54
+ id = "allowTrailingCommas"
55
+ checked = { allowTrailingCommas }
56
+ onCheckedChange = { ( value : boolean ) => {
57
+ setJsonOptions ( {
58
+ ...jsonOptions ,
59
+ allowTrailingCommas : value ,
60
+ } ) ;
61
+ } }
62
+ />
63
+ < Label htmlFor = "allowTrailingCommas" >
64
+ Allow Trailing Commas
65
+ </ Label >
66
+ </ div >
67
+ ) }
68
+ </ >
49
69
) ;
50
70
} ;
51
71
Original file line number Diff line number Diff line change @@ -41,14 +41,21 @@ export function useAST() {
41
41
}
42
42
43
43
case "json" : {
44
- const { jsonMode } = jsonOptions ;
44
+ const { jsonMode, allowTrailingCommas } = jsonOptions ;
45
45
const language = json . languages [ jsonMode ] ;
46
- astParseResult = language . parse ( {
47
- body : code . json ,
48
- path : "" ,
49
- physicalPath : "" ,
50
- bom : false ,
51
- } ) ;
46
+ astParseResult = language . parse (
47
+ {
48
+ body : code . json ,
49
+ path : "" ,
50
+ physicalPath : "" ,
51
+ bom : false ,
52
+ } ,
53
+ {
54
+ languageOptions : {
55
+ allowTrailingCommas,
56
+ } ,
57
+ } ,
58
+ ) ;
52
59
break ;
53
60
}
54
61
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ export type JsOptions = {
38
38
39
39
export type JsonOptions = {
40
40
jsonMode : JsonMode ;
41
+ allowTrailingCommas : boolean ;
41
42
} ;
42
43
43
44
export type MarkdownOptions = {
Original file line number Diff line number Diff line change @@ -392,6 +392,7 @@ export const defaultJsOptions: JsOptions = {
392
392
393
393
export const defaultJsonOptions : JsonOptions = {
394
394
jsonMode : "jsonc" ,
395
+ allowTrailingCommas : false ,
395
396
} ;
396
397
397
398
export const defaultMarkdownOptions : MarkdownOptions = {
You can’t perform that action at this time.
0 commit comments