diff --git a/crates/oxc_language_server/src/formatter/options.rs b/crates/oxc_language_server/src/formatter/options.rs index f624992547293..2a48148b6ef9f 100644 --- a/crates/oxc_language_server/src/formatter/options.rs +++ b/crates/oxc_language_server/src/formatter/options.rs @@ -66,4 +66,14 @@ mod test { let options = FormatOptions::try_from(json).unwrap(); assert!(options.config_path.is_none()); } + + #[test] + fn test_empty_string_config_path() { + let json = json!({ + "fmt.configPath": "" + }); + + let options = FormatOptions::try_from(json).unwrap(); + assert_eq!(options.config_path, Some(String::new())); + } } diff --git a/crates/oxc_language_server/src/formatter/server_formatter.rs b/crates/oxc_language_server/src/formatter/server_formatter.rs index ad90d15486880..5cff4a4bf3783 100644 --- a/crates/oxc_language_server/src/formatter/server_formatter.rs +++ b/crates/oxc_language_server/src/formatter/server_formatter.rs @@ -115,7 +115,7 @@ impl ServerFormatterBuilder { } fn search_config_file(root_path: &Path, config_path: Option<&String>) -> Option { - if let Some(config_path) = config_path { + if let Some(config_path) = config_path.filter(|s| !s.is_empty()) { let config = normalize_path(root_path.join(config_path)); if config.try_exists().is_ok_and(|exists| exists) { return Some(config); @@ -215,7 +215,7 @@ impl Tool for ServerFormatter { } }; - if let Some(config_path) = options.config_path.as_ref() { + if let Some(config_path) = options.config_path.as_ref().filter(|s| !s.is_empty()) { return vec![config_path.clone()]; } @@ -416,6 +416,20 @@ mod test_watchers { assert_eq!(patterns.len(), 1); assert_eq!(patterns[0], "configs/formatter.json"); } + + #[test] + fn test_empty_string_config_path() { + let patterns = Tester::new( + FAKE_DIR, + json!({ + "fmt.configPath": "" + }), + ) + .get_watcher_patterns(); + assert_eq!(patterns.len(), 2); + assert_eq!(patterns[0], ".oxfmtrc.json"); + assert_eq!(patterns[1], ".oxfmtrc.jsonc"); + } } mod handle_configuration_change {