Skip to content

Commit 7699013

Browse files
committed
feat(oxlint,oxfmt): Allow comments and also commas for vscode-json-ls
1 parent 3aabfac commit 7699013

File tree

6 files changed

+23
-4
lines changed

6 files changed

+23
-4
lines changed

crates/oxc_formatter/tests/schema.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ use project_root::get_project_root;
88
#[test]
99
fn test_schema_json() {
1010
let path = get_project_root().unwrap().join("npm/oxfmt/configuration_schema.json");
11-
let schema = schemars::schema_for!(Oxfmtrc);
11+
let mut schema = schemars::schema_for!(Oxfmtrc);
12+
// Allow comments and trailing commas for vscode-json-languageservice
13+
// NOTE: This is NOT part of standard JSON Schema specification
14+
// https://github.com/microsoft/vscode-json-languageservice/blob/fb83547762901f32d8449d57e24666573016b10c/src/jsonLanguageTypes.ts#L151-L159
15+
schema.schema.extensions.insert("allowComments".to_string(), serde_json::Value::Bool(true));
16+
schema
17+
.schema
18+
.extensions
19+
.insert("allowTrailingCommas".to_string(), serde_json::Value::Bool(true));
1220
let json = serde_json::to_string_pretty(&schema).unwrap();
1321
let existing_json = fs::read_to_string(&path).unwrap_or_default();
1422
if existing_json.trim() != json.trim() {

crates/oxc_formatter/tests/snapshots/schema_json.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ expression: json
174174
]
175175
}
176176
},
177+
"allowComments": true,
178+
"allowTrailingCommas": true,
177179
"definitions": {
178180
"ArrowParensConfig": {
179181
"type": "string",

crates/oxc_linter/src/config/oxlintrc.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,14 @@ impl Oxlintrc {
204204
/// Panics if the schema generation fails.
205205
pub fn generate_schema_json() -> String {
206206
let mut schema = schema_for!(Oxlintrc);
207-
// setting `allowComments` to true to allow comments in JSON schema files
208-
// https://github.com/microsoft/vscode-json-languageservice/blob/356d5dd980d49c6ac09ec8446614a6f94016dcea/src/jsonLanguageTypes.ts#L127-L131
207+
// Allow comments and trailing commas for vscode-json-languageservice
208+
// NOTE: This is NOT part of standard JSON Schema specification
209+
// https://github.com/microsoft/vscode-json-languageservice/blob/fb83547762901f32d8449d57e24666573016b10c/src/jsonLanguageTypes.ts#L151-L159
209210
schema.schema.extensions.insert("allowComments".to_string(), serde_json::Value::Bool(true));
211+
schema
212+
.schema
213+
.extensions
214+
.insert("allowTrailingCommas".to_string(), serde_json::Value::Bool(true));
210215
serde_json::to_string_pretty(&schema).unwrap()
211216
}
212217

crates/oxc_linter/src/snapshots/schema_json.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ expression: json
127127
}
128128
},
129129
"allowComments": true,
130+
"allowTrailingCommas": true,
130131
"definitions": {
131132
"AllowWarnDeny": {
132133
"oneOf": [

npm/oxfmt/configuration_schema.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@
170170
]
171171
}
172172
},
173+
"allowComments": true,
174+
"allowTrailingCommas": true,
173175
"definitions": {
174176
"ArrowParensConfig": {
175177
"type": "string",

npm/oxlint/configuration_schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
}
124124
},
125125
"allowComments": true,
126+
"allowTrailingCommas": true,
126127
"definitions": {
127128
"AllowWarnDeny": {
128129
"oneOf": [
@@ -620,4 +621,4 @@
620621
}
621622
}
622623
}
623-
}
624+
}

0 commit comments

Comments
 (0)