Skip to content

Commit

Permalink
fix(project): config merging (#1460)
Browse files Browse the repository at this point in the history
Co-authored-by: Emanuele Stoppa <[email protected]>
  • Loading branch information
arendjr and ematipico authored Jan 12, 2024
1 parent 0d85d6f commit a100bec
Show file tree
Hide file tree
Showing 55 changed files with 879 additions and 2,017 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

### Configuration

#### Bug fixes

- Fix [1440](https://github.com/biomejs/biome/issues/1440), a case where `extends` and `overrides` weren't correctly emitting the final configuration. Contributed by @arendjr

### Editors

### Formatter
Expand Down
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ biome_css_formatter = { version = "0.4.0", path = "./crates/biome_css_f
biome_css_parser = { version = "0.4.0", path = "./crates/biome_css_parser" }
biome_css_syntax = { version = "0.4.0", path = "./crates/biome_css_syntax" }
biome_deserialize = { version = "0.4.0", path = "./crates/biome_deserialize" }
biome_deserialize_macros = { version = "0.3.1", path = "./crates/biome_deserialize_macros" }
biome_diagnostics = { version = "0.4.0", path = "./crates/biome_diagnostics" }
biome_diagnostics_categories = { version = "0.4.0", path = "./crates/biome_diagnostics_categories" }
biome_diagnostics_macros = { version = "0.4.0", path = "./crates/biome_diagnostics_macros" }
Expand Down
14 changes: 12 additions & 2 deletions crates/biome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use crate::commands::{get_stdin, validate_configuration_diagnostics};
use crate::{
execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution, TraversalMode,
};
use biome_deserialize::Merge;
use biome_service::configuration::organize_imports::OrganizeImports;
use biome_service::configuration::{
load_configuration, FormatterConfiguration, LinterConfiguration, LoadedConfiguration,
};
use biome_service::workspace::{FixFileMode, UpdateSettingsParams};
use biome_service::{Configuration, MergeWith};
use biome_service::Configuration;
use std::ffi::OsString;

pub(crate) struct CheckCommandPayload {
Expand Down Expand Up @@ -97,7 +98,16 @@ pub(crate) fn check(
organize_imports.enabled = organize_imports_enabled;
}

fs_configuration.merge_with(configuration);
if let Some(mut configuration) = configuration {
if let Some(linter) = configuration.linter.as_mut() {
// Don't overwrite rules from the CLI configuration.
// Otherwise, rules that are disabled in the config file might
// become re-enabled due to the defaults included in the CLI
// configuration.
linter.rules = None;
}
fs_configuration.merge_with(configuration);
}

// check if support of git ignore files is enabled
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
Expand Down
16 changes: 4 additions & 12 deletions crates/biome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ use crate::changed::get_changed_files;
use crate::cli_options::CliOptions;
use crate::commands::validate_configuration_diagnostics;
use crate::{execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution};
use biome_deserialize::Merge;
use biome_service::configuration::organize_imports::OrganizeImports;
use biome_service::configuration::{
load_configuration, FormatterConfiguration, LinterConfiguration, LoadedConfiguration,
};
use biome_service::workspace::UpdateSettingsParams;
use biome_service::{Configuration, MergeWith};
use biome_service::Configuration;
use std::ffi::OsString;

pub(crate) struct CiCommandPayload {
pub(crate) formatter_enabled: Option<bool>,
pub(crate) linter_enabled: Option<bool>,
pub(crate) organize_imports_enabled: Option<bool>,
pub(crate) paths: Vec<OsString>,
pub(crate) rome_configuration: Configuration,
pub(crate) configuration: Configuration,
pub(crate) cli_options: CliOptions,
pub(crate) changed: bool,
pub(crate) since: Option<String>,
Expand Down Expand Up @@ -76,16 +77,7 @@ pub(crate) fn ci(session: CliSession, mut payload: CiCommandPayload) -> Result<(
return Err(CliDiagnostic::incompatible_end_configuration("Formatter, linter and organize imports are disabled, can't perform the command. This is probably and error."));
}

configuration.merge_with(payload.rome_configuration.files);
configuration.merge_with(payload.rome_configuration.vcs);
configuration.merge_with_if(
payload.rome_configuration.formatter,
!configuration.is_formatter_disabled(),
);
configuration.merge_with_if(
payload.rome_configuration.organize_imports,
!configuration.is_organize_imports_disabled(),
);
configuration.merge_with(payload.configuration);

// check if support of git ignore files is enabled
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
Expand Down
135 changes: 81 additions & 54 deletions crates/biome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution, TraversalMode,
};
use biome_console::{markup, ConsoleExt};
use biome_deserialize::Merge;
use biome_diagnostics::PrintDiagnostic;
use biome_service::configuration::css::CssFormatter;
use biome_service::configuration::json::JsonFormatter;
Expand All @@ -15,7 +16,7 @@ use biome_service::configuration::{
load_configuration, FilesConfiguration, FormatterConfiguration, LoadedConfiguration,
};
use biome_service::workspace::UpdateSettingsParams;
use biome_service::{JavascriptFormatter, MergeWith};
use biome_service::JavascriptFormatter;
use std::ffi::OsString;

pub(crate) struct FormatCommandPayload {
Expand All @@ -39,16 +40,16 @@ pub(crate) fn format(
payload: FormatCommandPayload,
) -> Result<(), CliDiagnostic> {
let FormatCommandPayload {
javascript_formatter,
formatter_configuration,
mut javascript_formatter,
mut formatter_configuration,
vcs_configuration,
mut paths,
cli_options,
stdin_file_path,
files_configuration,
write,
json_formatter,
css_formatter,
mut json_formatter,
mut css_formatter,
since,
changed,
} = payload;
Expand All @@ -67,64 +68,90 @@ pub(crate) fn format(
..
} = loaded_configuration;
// TODO: remove in biome 2.0
if formatter_configuration
.as_ref()
.is_some_and(|f| f.indent_size.is_some())
{
let console = &mut session.app.console;
let diagnostic = DeprecatedArgument::new(markup! {
"The argument "<Emphasis>"--indent-size"</Emphasis>" is deprecated, it will be removed in the next major release. Use "<Emphasis>"--indent-width"</Emphasis>" instead."
});
console.error(markup! {
{PrintDiagnostic::simple(&diagnostic)}
})
if let Some(config) = formatter_configuration.as_mut() {
if let Some(indent_size) = config.indent_size {
let console = &mut session.app.console;
let diagnostic = DeprecatedArgument::new(markup! {
"The argument "<Emphasis>"--indent-size"</Emphasis>" is deprecated, it will be removed in the next major release. Use "<Emphasis>"--indent-width"</Emphasis>" instead."
});
console.error(markup! {
{PrintDiagnostic::simple(&diagnostic)}
});

config.indent_width = Some(indent_size);
}
}
// TODO: remove in biome 2.0
if javascript_formatter
.as_ref()
.is_some_and(|f| f.indent_size.is_some())
{
let console = &mut session.app.console;
let diagnostic = DeprecatedArgument::new(markup! {
"The argument "<Emphasis>"--javascript-formatter-indent-size"</Emphasis>" is deprecated, it will be removed in the next major release. Use "<Emphasis>"--javascript-formatter-indent-width"</Emphasis>" instead."
});
console.error(markup! {
{PrintDiagnostic::simple(&diagnostic)}
})
if let Some(js_formatter) = javascript_formatter.as_mut() {
if let Some(indent_size) = js_formatter.indent_size {
let console = &mut session.app.console;
let diagnostic = DeprecatedArgument::new(markup! {
"The argument "<Emphasis>"--javascript-formatter-indent-size"</Emphasis>" is deprecated, it will be removed in the next major release. Use "<Emphasis>"--javascript-formatter-indent-width"</Emphasis>" instead."
});
console.error(markup! {
{PrintDiagnostic::simple(&diagnostic)}
});

js_formatter.indent_width = Some(indent_size);
}
}
// TODO: remove in biome 2.0
if json_formatter
.as_ref()
.is_some_and(|f| f.indent_size.is_some())
{
let console = &mut session.app.console;
let diagnostic = DeprecatedArgument::new(markup! {
"The argument "<Emphasis>"--json-formatter-indent-size"</Emphasis>" is deprecated, it will be removed in the next major release. Use "<Emphasis>"--json-formatter-indent-width"</Emphasis>" instead."
});
console.error(markup! {
{PrintDiagnostic::simple(&diagnostic)}
})
if let Some(json_formatter) = json_formatter.as_mut() {
if let Some(indent_size) = json_formatter.indent_size {
let console = &mut session.app.console;
let diagnostic = DeprecatedArgument::new(markup! {
"The argument "<Emphasis>"--json-formatter-indent-size"</Emphasis>" is deprecated, it will be removed in the next major release. Use "<Emphasis>"--json-formatter-indent-width"</Emphasis>" instead."
});
console.error(markup! {
{PrintDiagnostic::simple(&diagnostic)}
});

json_formatter.indent_width = Some(indent_size);
}
}
// TODO: remove in biome 2.0
if css_formatter
if let Some(css_formatter) = css_formatter.as_mut() {
if let Some(indent_size) = css_formatter.indent_size {
let console = &mut session.app.console;
let diagnostic = DeprecatedArgument::new(markup! {
"The argument "<Emphasis>"--css-formatter-indent-size"</Emphasis>" is deprecated, it will be removed in the next major release. Use "<Emphasis>"--css-formatter-indent-width"</Emphasis>" instead."
});
console.error(markup! {
{PrintDiagnostic::simple(&diagnostic)}
});

css_formatter.indent_width = Some(indent_size);
}
}

if css_formatter.is_some() {
let css = configuration.css.get_or_insert_with(Default::default);
css.formatter.merge_with(css_formatter);
}
configuration.files.merge_with(files_configuration);
if !configuration
.formatter
.as_ref()
.is_some_and(|f| f.indent_size.is_some())
.is_some_and(FormatterConfiguration::is_disabled)
{
let console = &mut session.app.console;
let diagnostic = DeprecatedArgument::new(markup! {
"The argument "<Emphasis>"--css-formatter-indent-size"</Emphasis>" is deprecated, it will be removed in the next major release. Use "<Emphasis>"--css-formatter-indent-width"</Emphasis>" instead."
});
console.error(markup! {
{PrintDiagnostic::simple(&diagnostic)}
})
}
let formatter = configuration.formatter.get_or_insert_with(Default::default);
if let Some(formatter_configuration) = formatter_configuration {
formatter.merge_with(formatter_configuration);
}

configuration.merge_with(javascript_formatter);
configuration.merge_with(json_formatter);
configuration.merge_with(css_formatter);
configuration.merge_with(formatter_configuration);
configuration.merge_with(vcs_configuration);
configuration.merge_with(files_configuration);
formatter.enabled = Some(true);
}
if javascript_formatter.is_some() {
let javascript = configuration
.javascript
.get_or_insert_with(Default::default);
javascript.formatter.merge_with(javascript_formatter);
}
if json_formatter.is_some() {
let json = configuration.json.get_or_insert_with(Default::default);
json.formatter.merge_with(json_formatter);
}
configuration.vcs.merge_with(vcs_configuration);

// check if support of git ignore files is enabled
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
Expand Down
26 changes: 21 additions & 5 deletions crates/biome_cli/src/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use crate::commands::{get_stdin, validate_configuration_diagnostics};
use crate::{
execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution, TraversalMode,
};
use biome_deserialize::{Merge, NoneState};
use biome_service::configuration::vcs::VcsConfiguration;
use biome_service::configuration::{
load_configuration, FilesConfiguration, LinterConfiguration, LoadedConfiguration,
};
use biome_service::workspace::{FixFileMode, UpdateSettingsParams};
use biome_service::MergeWith;
use biome_service::Configuration;
use std::ffi::OsString;

pub(crate) struct LintCommandPayload {
Expand All @@ -31,7 +32,7 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(
apply,
apply_unsafe,
cli_options,
linter_configuration,
mut linter_configuration,
mut paths,
stdin_file_path,
vcs_configuration,
Expand Down Expand Up @@ -67,9 +68,24 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(
directory_path: configuration_path,
..
} = loaded_configuration;
fs_configuration.merge_with(linter_configuration);
fs_configuration.merge_with(files_configuration);
fs_configuration.merge_with(vcs_configuration);
fs_configuration.merge_with(Configuration {
linter: if fs_configuration
.linter
.as_ref()
.is_some_and(LinterConfiguration::is_disabled)
{
None
} else {
if let Some(linter) = linter_configuration.as_mut() {
// Don't overwrite rules from the CLI configuration.
linter.rules = None;
}
linter_configuration
},
files: files_configuration,
vcs: vcs_configuration,
..NoneState::none()
});

// check if support of git ignore files is enabled
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
Expand Down
Loading

0 comments on commit a100bec

Please sign in to comment.