diff --git a/.changeset/bumpy-months-draw.md b/.changeset/bumpy-months-draw.md new file mode 100644 index 000000000000..b3f14c630cb3 --- /dev/null +++ b/.changeset/bumpy-months-draw.md @@ -0,0 +1,7 @@ +--- +"@biomejs/biome": patch +--- + +Fixed [#7390](https://github.com/biomejs/biome/issues/7390), where Biome couldn't apply the correct configuration passed via `--config-path`. + +If you have multiple **root** configuration files, running any command with `--config-path` will now apply the chosen configuration file. diff --git a/crates/biome_cli/src/cli_options.rs b/crates/biome_cli/src/cli_options.rs index 79ad1001d081..aa1a842c79fe 100644 --- a/crates/biome_cli/src/cli_options.rs +++ b/crates/biome_cli/src/cli_options.rs @@ -3,7 +3,7 @@ use crate::logging::LoggingKind; use biome_configuration::ConfigurationPathHint; use biome_diagnostics::Severity; use bpaf::Bpaf; -use camino::Utf8PathBuf; +use camino::{Utf8Path, Utf8PathBuf}; use std::fmt::{Display, Formatter}; use std::str::FromStr; @@ -100,13 +100,20 @@ pub struct CliOptions { impl CliOptions { /// Computes the [ConfigurationPathHint] based on the options passed by the user - pub(crate) fn as_configuration_path_hint(&self) -> ConfigurationPathHint { + pub(crate) fn as_configuration_path_hint( + &self, + working_directory: &Utf8Path, + ) -> ConfigurationPathHint { match self.config_path.as_ref() { None => ConfigurationPathHint::default(), Some(path) => { let path = Utf8PathBuf::from(path); let path = path.strip_prefix("./").unwrap_or(&path); - ConfigurationPathHint::FromUser(path.to_path_buf()) + if path.is_absolute() { + ConfigurationPathHint::FromUser(path.to_path_buf()) + } else { + ConfigurationPathHint::FromUser(working_directory.join(path)) + } } } } diff --git a/crates/biome_cli/src/commands/mod.rs b/crates/biome_cli/src/commands/mod.rs index 9ebad78f51b3..80040c0b4628 100644 --- a/crates/biome_cli/src/commands/mod.rs +++ b/crates/biome_cli/src/commands/mod.rs @@ -939,8 +939,9 @@ pub(crate) trait CommandRunner: Sized { workspace: &dyn Workspace, cli_options: &CliOptions, ) -> Result { + let working_dir = fs.working_directory().unwrap_or_default(); // Load configuration - let configuration_path_hint = cli_options.as_configuration_path_hint(); + let configuration_path_hint = cli_options.as_configuration_path_hint(working_dir.as_path()); let loaded_configuration = load_configuration(fs, configuration_path_hint)?; if self.should_validate_configuration_diagnostics() { validate_configuration_diagnostics( @@ -961,7 +962,6 @@ pub(crate) trait CommandRunner: Sized { let execution = self.get_execution(cli_options, console, workspace)?; - let working_dir = fs.working_directory().unwrap_or_default(); let root_configuration_dir = configuration_dir_path .clone() .unwrap_or_else(|| working_dir.clone());