File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4141 "@codemirror/language" : " ^6.10.3" ,
4242 "@eslint/css" : " ^0.2.0" ,
4343 "@eslint/js" : " ^9.9.0" ,
44- "@eslint/json" : " ^0.4.1 " ,
44+ "@eslint/json" : " ^0.12.0 " ,
4545 "@eslint/markdown" : " ^6.4.0" ,
4646 "@lezer/highlight" : " ^1.2.1" ,
4747 "@radix-ui/react-accordion" : " ^1.2.0" ,
Original file line number Diff line number Diff line change @@ -33,19 +33,39 @@ import type {
3333const JSONPanel : React . FC = ( ) => {
3434 const explorer = useExplorer ( ) ;
3535 const { jsonOptions, setJsonOptions } = explorer ;
36- const { jsonMode } = jsonOptions ;
36+ const { jsonMode, allowTrailingCommas } = jsonOptions ;
3737 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+ </ >
4969 ) ;
5070} ;
5171
Original file line number Diff line number Diff line change @@ -41,14 +41,21 @@ export function useAST() {
4141 }
4242
4343 case "json" : {
44- const { jsonMode } = jsonOptions ;
44+ const { jsonMode, allowTrailingCommas } = jsonOptions ;
4545 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+ ) ;
5259 break ;
5360 }
5461
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ export type JsOptions = {
3838
3939export type JsonOptions = {
4040 jsonMode : JsonMode ;
41+ allowTrailingCommas : boolean ;
4142} ;
4243
4344export type MarkdownOptions = {
Original file line number Diff line number Diff line change @@ -392,6 +392,7 @@ export const defaultJsOptions: JsOptions = {
392392
393393export const defaultJsonOptions : JsonOptions = {
394394 jsonMode : "jsonc" ,
395+ allowTrailingCommas : false ,
395396} ;
396397
397398export const defaultMarkdownOptions : MarkdownOptions = {
You can’t perform that action at this time.
0 commit comments