From 84de1cab683a6cf281dbfb6ca885601b7db8dc0a Mon Sep 17 00:00:00 2001 From: leaysgur <6259812+leaysgur@users.noreply.github.com> Date: Wed, 12 Nov 2025 00:55:24 +0000 Subject: [PATCH] feat(oxlint,oxfmt): Allow comments and also commas for vscode-json-ls (#15612) Fixes #15588 Add vscode specific extension of `allowComments` and `allowTrailingCommas` for both `oxlint` and `oxfmt`. --- crates/oxc_formatter/tests/schema.rs | 10 +++++++++- crates/oxc_formatter/tests/snapshots/schema_json.snap | 2 ++ crates/oxc_linter/src/config/oxlintrc.rs | 9 +++++++-- crates/oxc_linter/src/snapshots/schema_json.snap | 1 + npm/oxfmt/configuration_schema.json | 2 ++ npm/oxlint/configuration_schema.json | 3 ++- 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/oxc_formatter/tests/schema.rs b/crates/oxc_formatter/tests/schema.rs index c54b98c0a7a0c..c068d8c491233 100644 --- a/crates/oxc_formatter/tests/schema.rs +++ b/crates/oxc_formatter/tests/schema.rs @@ -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() { diff --git a/crates/oxc_formatter/tests/snapshots/schema_json.snap b/crates/oxc_formatter/tests/snapshots/schema_json.snap index 4c99b36665985..ad6a33742c11d 100644 --- a/crates/oxc_formatter/tests/snapshots/schema_json.snap +++ b/crates/oxc_formatter/tests/snapshots/schema_json.snap @@ -174,6 +174,8 @@ expression: json ] } }, + "allowComments": true, + "allowTrailingCommas": true, "definitions": { "ArrowParensConfig": { "type": "string", diff --git a/crates/oxc_linter/src/config/oxlintrc.rs b/crates/oxc_linter/src/config/oxlintrc.rs index dd0c2952ed39f..692d892ce0a0c 100644 --- a/crates/oxc_linter/src/config/oxlintrc.rs +++ b/crates/oxc_linter/src/config/oxlintrc.rs @@ -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() } diff --git a/crates/oxc_linter/src/snapshots/schema_json.snap b/crates/oxc_linter/src/snapshots/schema_json.snap index ef0e7cd2c7850..012f341ebcc56 100644 --- a/crates/oxc_linter/src/snapshots/schema_json.snap +++ b/crates/oxc_linter/src/snapshots/schema_json.snap @@ -127,6 +127,7 @@ expression: json } }, "allowComments": true, + "allowTrailingCommas": true, "definitions": { "AllowWarnDeny": { "oneOf": [ diff --git a/npm/oxfmt/configuration_schema.json b/npm/oxfmt/configuration_schema.json index 7cf6261cf00d5..be9a0fe8cf926 100644 --- a/npm/oxfmt/configuration_schema.json +++ b/npm/oxfmt/configuration_schema.json @@ -170,6 +170,8 @@ ] } }, + "allowComments": true, + "allowTrailingCommas": true, "definitions": { "ArrowParensConfig": { "type": "string", diff --git a/npm/oxlint/configuration_schema.json b/npm/oxlint/configuration_schema.json index b0b00f80f03ed..c5cc86fda7981 100644 --- a/npm/oxlint/configuration_schema.json +++ b/npm/oxlint/configuration_schema.json @@ -123,6 +123,7 @@ } }, "allowComments": true, + "allowTrailingCommas": true, "definitions": { "AllowWarnDeny": { "oneOf": [ @@ -620,4 +621,4 @@ } } } -} +} \ No newline at end of file