Skip to content

Commit 4ca088c

Browse files
authored
fix(cli): make config-path absolute (#8188)
1 parent 2e70165 commit 4ca088c

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.changeset/bumpy-months-draw.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#7390](https://github.com/biomejs/biome/issues/7390), where Biome couldn't apply the correct configuration passed via `--config-path`.
6+
7+
If you have multiple **root** configuration files, running any command with `--config-path` will now apply the chosen configuration file.

crates/biome_cli/src/cli_options.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::logging::LoggingKind;
33
use biome_configuration::ConfigurationPathHint;
44
use biome_diagnostics::Severity;
55
use bpaf::Bpaf;
6-
use camino::Utf8PathBuf;
6+
use camino::{Utf8Path, Utf8PathBuf};
77
use std::fmt::{Display, Formatter};
88
use std::str::FromStr;
99

@@ -100,13 +100,20 @@ pub struct CliOptions {
100100

101101
impl CliOptions {
102102
/// Computes the [ConfigurationPathHint] based on the options passed by the user
103-
pub(crate) fn as_configuration_path_hint(&self) -> ConfigurationPathHint {
103+
pub(crate) fn as_configuration_path_hint(
104+
&self,
105+
working_directory: &Utf8Path,
106+
) -> ConfigurationPathHint {
104107
match self.config_path.as_ref() {
105108
None => ConfigurationPathHint::default(),
106109
Some(path) => {
107110
let path = Utf8PathBuf::from(path);
108111
let path = path.strip_prefix("./").unwrap_or(&path);
109-
ConfigurationPathHint::FromUser(path.to_path_buf())
112+
if path.is_absolute() {
113+
ConfigurationPathHint::FromUser(path.to_path_buf())
114+
} else {
115+
ConfigurationPathHint::FromUser(working_directory.join(path))
116+
}
110117
}
111118
}
112119
}

crates/biome_cli/src/commands/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,9 @@ pub(crate) trait CommandRunner: Sized {
939939
workspace: &dyn Workspace,
940940
cli_options: &CliOptions,
941941
) -> Result<ConfiguredWorkspace, CliDiagnostic> {
942+
let working_dir = fs.working_directory().unwrap_or_default();
942943
// Load configuration
943-
let configuration_path_hint = cli_options.as_configuration_path_hint();
944+
let configuration_path_hint = cli_options.as_configuration_path_hint(working_dir.as_path());
944945
let loaded_configuration = load_configuration(fs, configuration_path_hint)?;
945946
if self.should_validate_configuration_diagnostics() {
946947
validate_configuration_diagnostics(
@@ -961,7 +962,6 @@ pub(crate) trait CommandRunner: Sized {
961962

962963
let execution = self.get_execution(cli_options, console, workspace)?;
963964

964-
let working_dir = fs.working_directory().unwrap_or_default();
965965
let root_configuration_dir = configuration_dir_path
966966
.clone()
967967
.unwrap_or_else(|| working_dir.clone());

0 commit comments

Comments
 (0)