Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crates/oxc_formatter/tests/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ use project_root::get_project_root;
#[test]
fn test_schema_json() {
let path = get_project_root().unwrap().join("npm/oxfmt/configuration_schema.json");
let schema = schemars::schema_for!(Oxfmtrc);
let mut schema = schemars::schema_for!(Oxfmtrc);
// Allow comments and trailing commas for vscode-json-languageservice
// NOTE: This is NOT part of standard JSON Schema specification
// https://github.com/microsoft/vscode-json-languageservice/blob/fb83547762901f32d8449d57e24666573016b10c/src/jsonLanguageTypes.ts#L151-L159
schema.schema.extensions.insert("allowComments".to_string(), serde_json::Value::Bool(true));
schema
.schema
.extensions
.insert("allowTrailingCommas".to_string(), serde_json::Value::Bool(true));
let json = serde_json::to_string_pretty(&schema).unwrap();
let existing_json = fs::read_to_string(&path).unwrap_or_default();
if existing_json.trim() != json.trim() {
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_formatter/tests/snapshots/schema_json.snap
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ expression: json
]
}
},
"allowComments": true,
"allowTrailingCommas": true,
"definitions": {
"ArrowParensConfig": {
"type": "string",
Expand Down
9 changes: 7 additions & 2 deletions crates/oxc_linter/src/config/oxlintrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,14 @@ impl Oxlintrc {
/// Panics if the schema generation fails.
pub fn generate_schema_json() -> String {
let mut schema = schema_for!(Oxlintrc);
// setting `allowComments` to true to allow comments in JSON schema files
// https://github.com/microsoft/vscode-json-languageservice/blob/356d5dd980d49c6ac09ec8446614a6f94016dcea/src/jsonLanguageTypes.ts#L127-L131
// Allow comments and trailing commas for vscode-json-languageservice
// NOTE: This is NOT part of standard JSON Schema specification
// https://github.com/microsoft/vscode-json-languageservice/blob/fb83547762901f32d8449d57e24666573016b10c/src/jsonLanguageTypes.ts#L151-L159
schema.schema.extensions.insert("allowComments".to_string(), serde_json::Value::Bool(true));
schema
.schema
.extensions
.insert("allowTrailingCommas".to_string(), serde_json::Value::Bool(true));
serde_json::to_string_pretty(&schema).unwrap()
}

Expand Down
1 change: 1 addition & 0 deletions crates/oxc_linter/src/snapshots/schema_json.snap
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ expression: json
}
},
"allowComments": true,
"allowTrailingCommas": true,
"definitions": {
"AllowWarnDeny": {
"oneOf": [
Expand Down
2 changes: 2 additions & 0 deletions npm/oxfmt/configuration_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
]
}
},
"allowComments": true,
"allowTrailingCommas": true,
"definitions": {
"ArrowParensConfig": {
"type": "string",
Expand Down
3 changes: 2 additions & 1 deletion npm/oxlint/configuration_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
}
},
"allowComments": true,
"allowTrailingCommas": true,
"definitions": {
"AllowWarnDeny": {
"oneOf": [
Expand Down Expand Up @@ -620,4 +621,4 @@
}
}
}
}
}
Loading