Skip to content

Commit

Permalink
refactor: configuration, settings and options
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec-ant committed Jul 22, 2024
1 parent 5ed1340 commit b957d12
Show file tree
Hide file tree
Showing 121 changed files with 2,809 additions and 2,513 deletions.
4 changes: 2 additions & 2 deletions crates/biome_cli/src/changed.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::CliDiagnostic;
use biome_configuration::PartialConfiguration;
use biome_configuration::Configuration;
use biome_fs::FileSystem;
use biome_service::DynRef;
use std::ffi::OsString;

pub(crate) fn get_changed_files(
fs: &DynRef<'_, dyn FileSystem>,
configuration: &PartialConfiguration,
configuration: &Configuration,
since: Option<String>,
) -> Result<Vec<OsString>, CliDiagnostic> {
let default_branch = configuration
Expand Down
22 changes: 11 additions & 11 deletions crates/biome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ use crate::{
execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution, TraversalMode,
};
use biome_configuration::{
organize_imports::PartialOrganizeImports, PartialConfiguration, PartialFormatterConfiguration,
PartialLinterConfiguration,
organize_imports::OrganizeImports, Configuration, FormatterConfiguration, LinterConfiguration,
};
use biome_console::{markup, ConsoleExt};
use biome_deserialize::Merge;
use biome_diagnostics::PrintDiagnostic;
use biome_service::configuration::{load_editorconfig, PartialConfigurationExt};
use biome_service::configuration::{load_editorconfig, ConfigurationExt};
use biome_service::workspace::RegisterProjectFolderParams;
use biome_service::{
configuration::{load_configuration, LoadedConfiguration},
Expand All @@ -30,7 +29,7 @@ pub(crate) struct CheckCommandPayload {
pub(crate) fix: bool,
pub(crate) unsafe_: bool,
pub(crate) cli_options: CliOptions,
pub(crate) configuration: Option<PartialConfiguration>,
pub(crate) configuration: Option<Configuration>,
pub(crate) paths: Vec<OsString>,
pub(crate) stdin_file_path: Option<String>,
pub(crate) formatter_enabled: Option<bool>,
Expand Down Expand Up @@ -103,7 +102,8 @@ pub(crate) fn check(
.as_ref()
.and_then(|f| f.use_editorconfig)
.unwrap_or_default(),
);
)
.into();
let mut fs_configuration = if should_use_editorconfig {
let (editorconfig, editorconfig_diagnostics) = {
let search_path = editorconfig_search_path.unwrap_or_else(|| {
Expand All @@ -126,26 +126,26 @@ pub(crate) fn check(

let formatter = fs_configuration
.formatter
.get_or_insert_with(PartialFormatterConfiguration::default);
.get_or_insert_with(FormatterConfiguration::default);

if formatter_enabled.is_some() {
formatter.enabled = formatter_enabled;
formatter.enabled = formatter_enabled.map(Into::into);
}

let linter = fs_configuration
.linter
.get_or_insert_with(PartialLinterConfiguration::default);
.get_or_insert_with(LinterConfiguration::default);

if linter_enabled.is_some() {
linter.enabled = linter_enabled;
linter.enabled = linter_enabled.map(Into::into);
}

let organize_imports = fs_configuration
.organize_imports
.get_or_insert_with(PartialOrganizeImports::default);
.get_or_insert_with(OrganizeImports::default);

if organize_imports_enabled.is_some() {
organize_imports.enabled = organize_imports_enabled;
organize_imports.enabled = organize_imports_enabled.map(Into::into);
}

if let Some(mut configuration) = configuration {
Expand Down
36 changes: 18 additions & 18 deletions crates/biome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ use crate::cli_options::CliOptions;
use crate::commands::{resolve_manifest, validate_configuration_diagnostics};
use crate::execute::VcsTargeted;
use crate::{execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution};
use biome_configuration::{organize_imports::PartialOrganizeImports, PartialConfiguration};
use biome_configuration::{PartialFormatterConfiguration, PartialLinterConfiguration};
use biome_configuration::{organize_imports::OrganizeImports, Configuration};
use biome_configuration::{FormatterConfiguration, LinterConfiguration};
use biome_deserialize::Merge;
use biome_service::configuration::{
load_configuration, LoadedConfiguration, PartialConfigurationExt,
};
use biome_service::configuration::{load_configuration, ConfigurationExt, LoadedConfiguration};
use biome_service::workspace::{RegisterProjectFolderParams, UpdateSettingsParams};
use std::ffi::OsString;

Expand All @@ -17,7 +15,8 @@ pub(crate) struct CiCommandPayload {
pub(crate) linter_enabled: Option<bool>,
pub(crate) organize_imports_enabled: Option<bool>,
pub(crate) paths: Vec<OsString>,
pub(crate) configuration: Option<PartialConfiguration>,
// TODO(zzwu): What's the purpose of this option?
pub(crate) configuration: Option<Configuration>,
pub(crate) cli_options: CliOptions,
pub(crate) changed: bool,
pub(crate) since: Option<String>,
Expand Down Expand Up @@ -54,35 +53,36 @@ pub(crate) fn ci(session: CliSession, payload: CiCommandPayload) -> Result<(), C
} = loaded_configuration;
let formatter = fs_configuration
.formatter
.get_or_insert_with(PartialFormatterConfiguration::default);
.get_or_insert_with(FormatterConfiguration::default);

if formatter_enabled.is_some() {
formatter.enabled = formatter_enabled;
formatter.enabled = formatter_enabled.map(Into::into);
}

let linter = fs_configuration
.linter
.get_or_insert_with(PartialLinterConfiguration::default);
.get_or_insert_with(LinterConfiguration::default);

if linter_enabled.is_some() {
linter.enabled = linter_enabled;
linter.enabled = linter_enabled.map(Into::into);
}

let organize_imports = fs_configuration
.organize_imports
.get_or_insert_with(PartialOrganizeImports::default);
.get_or_insert_with(OrganizeImports::default);

if organize_imports_enabled.is_some() {
organize_imports.enabled = organize_imports_enabled;
organize_imports.enabled = organize_imports_enabled.map(Into::into);
}

// TODO(zzwu): We shouldn't bail because overrides can re-enable these options
// no point in doing the traversal if all the checks have been disabled
if fs_configuration.is_formatter_disabled()
&& fs_configuration.is_linter_disabled()
&& fs_configuration.is_organize_imports_disabled()
{
return Err(CliDiagnostic::incompatible_end_configuration("Formatter, linter and organize imports are disabled, can't perform the command. This is probably and error."));
}
// if !fs_configuration.is_formatter_enabled()
// && !fs_configuration.is_linter_enabled()
// && !fs_configuration.is_organize_imports_enabled()
// {
// return Err(CliDiagnostic::incompatible_end_configuration("Formatter, linter and organize imports are disabled, can't perform the command. This is probably and error."));
// }

if let Some(mut configuration) = configuration {
if let Some(linter) = configuration.linter.as_mut() {
Expand Down
29 changes: 15 additions & 14 deletions crates/biome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ use crate::execute::VcsTargeted;
use crate::{
execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution, TraversalMode,
};
use biome_configuration::vcs::PartialVcsConfiguration;
use biome_configuration::vcs::VcsConfiguration;
use biome_configuration::{
PartialCssFormatter, PartialFilesConfiguration, PartialFormatterConfiguration,
PartialGraphqlFormatter, PartialJavascriptFormatter, PartialJsonFormatter,
CssFormatterConfiguration, FilesConfiguration, FormatterConfiguration,
GraphqlFormatterConfiguration, JsFormatterConfiguration, JsonFormatterConfiguration,
};
use biome_console::{markup, ConsoleExt};
use biome_deserialize::Merge;
use biome_diagnostics::PrintDiagnostic;
use biome_service::configuration::{
load_configuration, load_editorconfig, LoadedConfiguration, PartialConfigurationExt,
load_configuration, load_editorconfig, ConfigurationExt, LoadedConfiguration,
};
use biome_service::workspace::{RegisterProjectFolderParams, UpdateSettingsParams};
use std::ffi::OsString;

use super::check_fix_incompatible_arguments;

pub(crate) struct FormatCommandPayload {
pub(crate) javascript_formatter: Option<PartialJavascriptFormatter>,
pub(crate) json_formatter: Option<PartialJsonFormatter>,
pub(crate) css_formatter: Option<PartialCssFormatter>,
pub(crate) graphql_formatter: Option<PartialGraphqlFormatter>,
pub(crate) formatter_configuration: Option<PartialFormatterConfiguration>,
pub(crate) vcs_configuration: Option<PartialVcsConfiguration>,
pub(crate) files_configuration: Option<PartialFilesConfiguration>,
pub(crate) javascript_formatter: Option<JsFormatterConfiguration>,
pub(crate) json_formatter: Option<JsonFormatterConfiguration>,
pub(crate) css_formatter: Option<CssFormatterConfiguration>,
pub(crate) graphql_formatter: Option<GraphqlFormatterConfiguration>,
pub(crate) formatter_configuration: Option<FormatterConfiguration>,
pub(crate) vcs_configuration: Option<VcsConfiguration>,
pub(crate) files_configuration: Option<FilesConfiguration>,
pub(crate) stdin_file_path: Option<String>,
pub(crate) write: bool,
pub(crate) fix: bool,
Expand Down Expand Up @@ -99,7 +99,8 @@ pub(crate) fn format(
.as_ref()
.and_then(|f| f.use_editorconfig)
.unwrap_or_default(),
);
)
.into();
let mut fs_configuration = if should_use_editorconfig {
let (editorconfig, editorconfig_diagnostics) = {
let search_path = editorconfig_search_path.unwrap_or_else(|| {
Expand Down Expand Up @@ -185,14 +186,14 @@ pub(crate) fn format(
if !configuration
.formatter
.as_ref()
.is_some_and(PartialFormatterConfiguration::is_disabled)
.is_some_and(FormatterConfiguration::is_disabled)
{
let formatter = configuration.formatter.get_or_insert_with(Default::default);
if let Some(formatter_configuration) = formatter_configuration {
formatter.merge_with(formatter_configuration);
}

formatter.enabled = Some(true);
formatter.enabled = Some(true.into());
}
if css_formatter.is_some() {
let css = configuration.css.get_or_insert_with(Default::default);
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_cli/src/commands/init.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{CliDiagnostic, CliSession};
use biome_configuration::PartialConfiguration;
use biome_configuration::Configuration;
use biome_console::{markup, ConsoleExt};
use biome_fs::ConfigName;
use biome_service::configuration::create_config;

pub(crate) fn init(mut session: CliSession, emit_jsonc: bool) -> Result<(), CliDiagnostic> {
let fs = &mut session.app.fs;
create_config(fs, PartialConfiguration::init(), emit_jsonc)?;
create_config(fs, Configuration::init(), emit_jsonc)?;
let file_created = if emit_jsonc {
ConfigName::biome_jsonc()
} else {
Expand Down
36 changes: 16 additions & 20 deletions crates/biome_cli/src/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@ use crate::execute::VcsTargeted;
use crate::{
execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution, TraversalMode,
};
use biome_configuration::css::PartialCssLinter;
use biome_configuration::javascript::PartialJavascriptLinter;
use biome_configuration::json::PartialJsonLinter;
use biome_configuration::css::CssLinterConfiguration;
use biome_configuration::graphql::GraphqlLinterConfiguration;
use biome_configuration::javascript::JsLinterConfiguration;
use biome_configuration::json::JsonLinterConfiguration;
use biome_configuration::linter::RuleSelector;
use biome_configuration::vcs::PartialVcsConfiguration;
use biome_configuration::{
PartialConfiguration, PartialFilesConfiguration, PartialGraphqlLinter,
PartialLinterConfiguration,
};
use biome_configuration::vcs::VcsConfiguration;
use biome_configuration::{Configuration, FilesConfiguration, LinterConfiguration};
use biome_deserialize::Merge;
use biome_service::configuration::{
load_configuration, LoadedConfiguration, PartialConfigurationExt,
};
use biome_service::configuration::{load_configuration, ConfigurationExt, LoadedConfiguration};
use biome_service::workspace::{RegisterProjectFolderParams, UpdateSettingsParams};
use std::ffi::OsString;

Expand All @@ -31,20 +27,20 @@ pub(crate) struct LintCommandPayload {
pub(crate) fix: bool,
pub(crate) unsafe_: bool,
pub(crate) cli_options: CliOptions,
pub(crate) linter_configuration: Option<PartialLinterConfiguration>,
pub(crate) vcs_configuration: Option<PartialVcsConfiguration>,
pub(crate) files_configuration: Option<PartialFilesConfiguration>,
pub(crate) linter_configuration: Option<LinterConfiguration>,
pub(crate) vcs_configuration: Option<VcsConfiguration>,
pub(crate) files_configuration: Option<FilesConfiguration>,
pub(crate) paths: Vec<OsString>,
pub(crate) only: Vec<RuleSelector>,
pub(crate) skip: Vec<RuleSelector>,
pub(crate) stdin_file_path: Option<String>,
pub(crate) staged: bool,
pub(crate) changed: bool,
pub(crate) since: Option<String>,
pub(crate) javascript_linter: Option<PartialJavascriptLinter>,
pub(crate) json_linter: Option<PartialJsonLinter>,
pub(crate) css_linter: Option<PartialCssLinter>,
pub(crate) graphql_linter: Option<PartialGraphqlLinter>,
pub(crate) javascript_linter: Option<JsLinterConfiguration>,
pub(crate) json_linter: Option<JsonLinterConfiguration>,
pub(crate) css_linter: Option<CssLinterConfiguration>,
pub(crate) graphql_linter: Option<GraphqlLinterConfiguration>,
}

/// Handler for the "lint" command of the Biome CLI
Expand Down Expand Up @@ -98,11 +94,11 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(
directory_path: configuration_path,
..
} = loaded_configuration;
fs_configuration.merge_with(PartialConfiguration {
fs_configuration.merge_with(Configuration {
linter: if fs_configuration
.linter
.as_ref()
.is_some_and(PartialLinterConfiguration::is_disabled)
.is_some_and(LinterConfiguration::is_disabled)
{
None
} else {
Expand Down
Loading

0 comments on commit b957d12

Please sign in to comment.