From eb3335212000484a73efd6a671b76d81ed09d9c7 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Mon, 27 May 2024 15:38:24 -0400 Subject: [PATCH] fix(formatter): never format biome.json with trailing commas --- .../tests/cases/biome_json_support.rs | 38 +++++++++++++++++++ ...ys_disable_trailing_commas_biome_json.snap | 25 ++++++++++++ .../biome_service/src/file_handlers/json.rs | 12 +++++- 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 crates/biome_cli/tests/snapshots/main_cases_biome_json_support/always_disable_trailing_commas_biome_json.snap diff --git a/crates/biome_cli/tests/cases/biome_json_support.rs b/crates/biome_cli/tests/cases/biome_json_support.rs index f0ce4329f983..a2c9eb79cb06 100644 --- a/crates/biome_cli/tests/cases/biome_json_support.rs +++ b/crates/biome_cli/tests/cases/biome_json_support.rs @@ -253,3 +253,41 @@ fn biome_json_is_not_ignored() { result, )); } + +#[test] +fn always_disable_trailing_commas_biome_json() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Path::new("biome.json"); + let config = r#"{ + "formatter": { + "indentStyle": "space", + "indentWidth": 4 + }, + "json": { + "formatter": { + "trailingCommas": "all" + } + } +} +"#; + fs.insert(file_path.into(), config); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(["check", "--write", "."].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_file_contents(&fs, file_path, config); + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "always_disable_trailing_commas_biome_json", + fs, + console, + result, + )); +} diff --git a/crates/biome_cli/tests/snapshots/main_cases_biome_json_support/always_disable_trailing_commas_biome_json.snap b/crates/biome_cli/tests/snapshots/main_cases_biome_json_support/always_disable_trailing_commas_biome_json.snap new file mode 100644 index 000000000000..bb39f9fa3789 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_biome_json_support/always_disable_trailing_commas_biome_json.snap @@ -0,0 +1,25 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +## `biome.json` + +```json +{ + "formatter": { + "indentStyle": "space", + "indentWidth": 4 + }, + "json": { + "formatter": { + "trailingCommas": "all" + } + } +} +``` + +# Emitted Messages + +```block +Checked 1 file in