From 69135758a2e79db16765d927d6a4942440856ccf Mon Sep 17 00:00:00 2001 From: zoomdong <1344492820@qq.com> Date: Sun, 2 Mar 2025 17:44:29 +0800 Subject: [PATCH] chore: update config --- crates/biome_cli/src/commands/format.rs | 1 + crates/biome_cli/tests/cases/editorconfig.rs | 87 ++++++++++--------- .../should_not_use_editorconfig.snap | 29 +++++++ crates/biome_configuration/src/lib.rs | 3 +- 4 files changed, 78 insertions(+), 42 deletions(-) create mode 100644 crates/biome_cli/tests/snapshots/main_cases_editorconfig/should_not_use_editorconfig.snap diff --git a/crates/biome_cli/src/commands/format.rs b/crates/biome_cli/src/commands/format.rs index ce8e7399211d..a4bbfb19662f 100644 --- a/crates/biome_cli/src/commands/format.rs +++ b/crates/biome_cli/src/commands/format.rs @@ -75,6 +75,7 @@ impl CommandRunner for FormatCommandPayload { formatter.enabled = Some(true.into()); } + if self.css_formatter.is_some() { let css = configuration.css.get_or_insert_with(Default::default); css.formatter.merge_with(self.css_formatter.clone()); diff --git a/crates/biome_cli/tests/cases/editorconfig.rs b/crates/biome_cli/tests/cases/editorconfig.rs index 15e457728ee5..b237904f3ff1 100644 --- a/crates/biome_cli/tests/cases/editorconfig.rs +++ b/crates/biome_cli/tests/cases/editorconfig.rs @@ -27,6 +27,45 @@ indent_size = 8 "#; fs.insert(test_file.into(), contents); + let (fs, result) = run_cli( + fs, + &mut console, + Args::from(["format", "--write", test_file.as_str()].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "should_use_editorconfig", + fs, + console, + result, + )); +} + +#[test] +fn shoud_not_use_editorconfig() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let editorconfig = Utf8Path::new(".editorconfig"); + fs.insert( + editorconfig.into(), + r#" +[*] +indent_style = space +indent_size = 8 +"#, + ); + + let test_file = Utf8Path::new("test.js"); + let contents = r#"function setName(name) { + currentName = name; +} +"#; + fs.insert(test_file.into(), contents); + let (fs, result) = run_cli( fs, &mut console, @@ -34,7 +73,7 @@ indent_size = 8 [ "format", "--write", - "--use-editorconfig=true", + "--use-editorconfig=false", test_file.as_str(), ] .as_slice(), @@ -45,7 +84,7 @@ indent_size = 8 assert_cli_snapshot(SnapshotPayload::new( module_path!(), - "should_use_editorconfig", + "should_not_use_editorconfig", fs, console, result, @@ -127,7 +166,7 @@ indent_size = 8 let (fs, result) = run_cli( fs, &mut console, - Args::from(["check", "--use-editorconfig=true", test_file.as_str()].as_slice()), + Args::from(["check", test_file.as_str()].as_slice()), ); assert!(result.is_err(), "run_cli returned {result:?}"); @@ -226,15 +265,7 @@ indent_style = tab let (fs, result) = run_cli( fs, &mut console, - Args::from( - [ - "format", - "--write", - "--use-editorconfig=true", - test_file.as_str(), - ] - .as_slice(), - ), + Args::from(["format", "--write", test_file.as_str()].as_slice()), ); assert!(result.is_ok(), "run_cli returned {result:?}"); @@ -275,15 +306,7 @@ indent_size = 8 let (fs, result) = run_cli( fs, &mut console, - Args::from( - [ - "check", - "--indent-width=4", - "--use-editorconfig=true", - test_file.as_str(), - ] - .as_slice(), - ), + Args::from(["check", "--indent-width=4", test_file.as_str()].as_slice()), ); assert!(result.is_err(), "run_cli returned {result:?}"); @@ -336,15 +359,7 @@ indent_style = space let (fs, result) = run_cli( fs, &mut console, - Args::from( - [ - "check", - "--use-editorconfig=true", - test_file.as_str(), - test_file2.as_str(), - ] - .as_slice(), - ), + Args::from(["check", test_file.as_str(), test_file2.as_str()].as_slice()), ); assert!(result.is_err(), "run_cli returned {result:?}"); @@ -383,7 +398,7 @@ indent_size = 8 let (fs, result) = run_cli( fs, &mut console, - Args::from(["ci", "--use-editorconfig=true", test_file.as_str()].as_slice()), + Args::from(["ci", test_file.as_str()].as_slice()), ); assert!(result.is_err(), "run_cli returned {result:?}"); @@ -467,15 +482,7 @@ insert_final_newline = false let (fs, result) = run_cli( fs, &mut console, - Args::from( - [ - "format", - "--write", - "--use-editorconfig=true", - test_file.as_str(), - ] - .as_slice(), - ), + Args::from(["format", "--write", test_file.as_str()].as_slice()), ); assert!(result.is_ok(), "run_cli returned {result:?}"); diff --git a/crates/biome_cli/tests/snapshots/main_cases_editorconfig/should_not_use_editorconfig.snap b/crates/biome_cli/tests/snapshots/main_cases_editorconfig/should_not_use_editorconfig.snap new file mode 100644 index 000000000000..b1c48aa1e7c1 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_editorconfig/should_not_use_editorconfig.snap @@ -0,0 +1,29 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: redactor(content) +snapshot_kind: text +--- +## `.editorconfig` + +```editorconfig + +[*] +indent_style = space +indent_size = 8 + +``` + +## `test.js` + +```js +function setName(name) { + currentName = name; +} + +``` + +# Emitted Messages + +```block +Formatted 1 file in