From 045f3da31637fdd03aa5961d508606453cc40bbf Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sun, 15 Sep 2024 16:52:28 -0400 Subject: [PATCH] fix(config): handle `unset` and `off` values in editorconfig files --- crates/biome_cli/tests/cases/editorconfig.rs | 45 ++++++ .../should_emit_diagnostics.snap | 33 +++++ crates/biome_configuration/src/diagnostics.rs | 6 +- .../biome_configuration/src/editorconfig.rs | 131 +++++++++++++----- 4 files changed, 180 insertions(+), 35 deletions(-) create mode 100644 crates/biome_cli/tests/snapshots/main_cases_editorconfig/should_emit_diagnostics.snap diff --git a/crates/biome_cli/tests/cases/editorconfig.rs b/crates/biome_cli/tests/cases/editorconfig.rs index 4fd50b74732b..b4f273c00ce1 100644 --- a/crates/biome_cli/tests/cases/editorconfig.rs +++ b/crates/biome_cli/tests/cases/editorconfig.rs @@ -452,3 +452,48 @@ max_line_length = 300 result, )); } + +#[test] +fn should_emit_diagnostics() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let editorconfig = Path::new(".editorconfig"); + fs.insert( + editorconfig.into(), + r#" +[*] +insert_final_newline = false +"#, + ); + + let test_file = Path::new("test.js"); + let contents = r#"console.log("foo"); +"#; + fs.insert(test_file.into(), contents); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from( + [ + ("format"), + ("--write"), + ("--use-editorconfig=true"), + test_file.as_os_str().to_str().unwrap(), + ] + .as_slice(), + ), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_file_contents(&fs, test_file, contents); + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "should_emit_diagnostics", + fs, + console, + result, + )); +} diff --git a/crates/biome_cli/tests/snapshots/main_cases_editorconfig/should_emit_diagnostics.snap b/crates/biome_cli/tests/snapshots/main_cases_editorconfig/should_emit_diagnostics.snap new file mode 100644 index 000000000000..a15f6ceae77c --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_editorconfig/should_emit_diagnostics.snap @@ -0,0 +1,33 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +## `.editorconfig` + +```editorconfig + +[*] +insert_final_newline = false + +``` + +## `test.js` + +```js +console.log("foo"); + +``` + +# Emitted Messages + +```block +configuration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Key 'insert_final_newline' is incompatible with biome: Biome always inserts a final newline. Set this option to true. + + +``` + +```block +Formatted 1 file in