@@ -175,7 +175,7 @@ impl FormatRunner {
175175 }
176176}
177177
178- const DEFAULT_CONFIG_NAMES : & [ & str ] = & [ ".oxfmtrc.json" , ".oxfmtrc.jsonc" ] ;
178+ const DEFAULT_OXFMTRC : & str = ".oxfmtrc.json" ;
179179
180180/// # Errors
181181///
@@ -185,30 +185,23 @@ const DEFAULT_CONFIG_NAMES: &[&str] = &[".oxfmtrc.json", ".oxfmtrc.jsonc"];
185185fn load_config ( cwd : & Path , config : Option < & PathBuf > ) -> Result < FormatOptions , String > {
186186 // If `--config` is explicitly specified, use that path directly
187187 if let Some ( config_path) = config {
188- let full_path =
189- if config_path. is_absolute ( ) { config_path. clone ( ) } else { cwd. join ( config_path) } ;
188+ let full_path = if config_path. is_absolute ( ) {
189+ PathBuf :: from ( config_path)
190+ } else {
191+ cwd. join ( config_path)
192+ } ;
190193
191194 // This will error if the file does not exist or is invalid
192195 let oxfmtrc = Oxfmtrc :: from_file ( & full_path) ?;
193196 return oxfmtrc. into_format_options ( ) ;
194197 }
195198
196199 // If `--config` is not specified, search the nearest config file from cwd upwards
197- let mut current_dir = cwd;
198- loop {
199- // Try each config name in order
200- for config_name in DEFAULT_CONFIG_NAMES {
201- let config_path = current_dir. join ( config_name) ;
202- if config_path. exists ( ) {
203- let oxfmtrc = Oxfmtrc :: from_file ( & config_path) ?;
204- return oxfmtrc. into_format_options ( ) ;
205- }
206- }
207-
208- if let Some ( parent) = current_dir. parent ( ) {
209- current_dir = parent;
210- } else {
211- break ;
200+ for dir in cwd. ancestors ( ) {
201+ let config_path = dir. join ( DEFAULT_OXFMTRC ) ;
202+ if config_path. exists ( ) {
203+ let oxfmtrc = Oxfmtrc :: from_file ( & config_path) ?;
204+ return oxfmtrc. into_format_options ( ) ;
212205 }
213206 }
214207
0 commit comments