Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): configuration, settings and capabilities #4845

Merged
merged 22 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/biome_cli/src/changed.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::CliDiagnostic;
use biome_configuration::PartialConfiguration;
use biome_configuration::Configuration;
use biome_fs::FileSystem;
use std::ffi::OsString;

pub(crate) fn get_changed_files(
fs: &dyn FileSystem,
configuration: &PartialConfiguration,
configuration: &Configuration,
since: Option<&str>,
) -> Result<Vec<OsString>, CliDiagnostic> {
let default_branch = configuration
Expand Down
32 changes: 16 additions & 16 deletions crates/biome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use super::{determine_fix_file_mode, FixFileModeOptions, LoadEditorConfig};
use crate::cli_options::CliOptions;
use crate::commands::{get_files_to_process_with_cli_options, CommandRunner};
use crate::{CliDiagnostic, Execution, TraversalMode};
use biome_configuration::analyzer::assist::PartialAssistConfiguration;
use biome_configuration::{
PartialConfiguration, PartialFormatterConfiguration, PartialLinterConfiguration,
};
use biome_configuration::analyzer::assist::{AssistConfiguration, AssistEnabled};
use biome_configuration::analyzer::LinterEnabled;
use biome_configuration::formatter::FormatterEnabled;
use biome_configuration::{Configuration, FormatterConfiguration, LinterConfiguration};
use biome_console::Console;
use biome_deserialize::Merge;
use biome_fs::FileSystem;
Expand All @@ -17,23 +17,23 @@ pub(crate) struct CheckCommandPayload {
pub(crate) write: bool,
pub(crate) fix: bool,
pub(crate) unsafe_: bool,
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>,
pub(crate) linter_enabled: Option<bool>,
pub(crate) assist_enabled: Option<bool>,
pub(crate) formatter_enabled: Option<FormatterEnabled>,
pub(crate) linter_enabled: Option<LinterEnabled>,
pub(crate) assist_enabled: Option<AssistEnabled>,
pub(crate) staged: bool,
pub(crate) changed: bool,
pub(crate) since: Option<String>,
}

impl LoadEditorConfig for CheckCommandPayload {
fn should_load_editor_config(&self, fs_configuration: &PartialConfiguration) -> bool {
fn should_load_editor_config(&self, fs_configuration: &Configuration) -> bool {
self.configuration
.as_ref()
.and_then(|c| c.use_editorconfig())
.unwrap_or(fs_configuration.use_editorconfig().unwrap_or_default())
.is_some_and(|c| c.use_editorconfig())
|| fs_configuration.use_editorconfig()
}
}

Expand All @@ -45,7 +45,7 @@ impl CommandRunner for CheckCommandPayload {
loaded_configuration: LoadedConfiguration,
fs: &dyn FileSystem,
console: &mut dyn Console,
) -> Result<PartialConfiguration, WorkspaceError> {
) -> Result<Configuration, WorkspaceError> {
let editorconfig_search_path = loaded_configuration.directory_path.clone();
let LoadedConfiguration {
configuration: biome_configuration,
Expand All @@ -58,23 +58,23 @@ impl CommandRunner for CheckCommandPayload {

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

if self.formatter_enabled.is_some() {
formatter.enabled = self.formatter_enabled;
}

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

if self.linter_enabled.is_some() {
linter.enabled = self.linter_enabled;
}

let assist = fs_configuration
.assist
.get_or_insert_with(PartialAssistConfiguration::default);
.get_or_insert_with(AssistConfiguration::default);

if self.assist_enabled.is_some() {
assist.enabled = self.assist_enabled;
Expand All @@ -97,7 +97,7 @@ impl CommandRunner for CheckCommandPayload {
fn get_files_to_process(
&self,
fs: &dyn FileSystem,
configuration: &PartialConfiguration,
configuration: &Configuration,
) -> Result<Vec<OsString>, CliDiagnostic> {
let paths = get_files_to_process_with_cli_options(
self.since.as_deref(),
Expand Down
37 changes: 19 additions & 18 deletions crates/biome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use crate::changed::get_changed_files;
use crate::cli_options::CliOptions;
use crate::commands::{CommandRunner, LoadEditorConfig};
use crate::{CliDiagnostic, Execution};
use biome_configuration::analyzer::assist::PartialAssistConfiguration;
use biome_configuration::PartialConfiguration;
use biome_configuration::{PartialFormatterConfiguration, PartialLinterConfiguration};
use biome_configuration::analyzer::assist::{AssistConfiguration, AssistEnabled};
use biome_configuration::analyzer::LinterEnabled;
use biome_configuration::formatter::FormatterEnabled;
use biome_configuration::{Configuration, FormatterConfiguration, LinterConfiguration};
use biome_console::Console;
use biome_deserialize::Merge;
use biome_fs::FileSystem;
Expand All @@ -14,21 +15,21 @@ use biome_service::{Workspace, WorkspaceError};
use std::ffi::OsString;

pub(crate) struct CiCommandPayload {
pub(crate) formatter_enabled: Option<bool>,
pub(crate) linter_enabled: Option<bool>,
pub(crate) assist_enabled: Option<bool>,
pub(crate) formatter_enabled: Option<FormatterEnabled>,
pub(crate) linter_enabled: Option<LinterEnabled>,
pub(crate) assist_enabled: Option<AssistEnabled>,
pub(crate) paths: Vec<OsString>,
pub(crate) configuration: Option<PartialConfiguration>,
pub(crate) configuration: Option<Configuration>,
pub(crate) changed: bool,
pub(crate) since: Option<String>,
}

impl LoadEditorConfig for CiCommandPayload {
fn should_load_editor_config(&self, fs_configuration: &PartialConfiguration) -> bool {
fn should_load_editor_config(&self, fs_configuration: &Configuration) -> bool {
self.configuration
.as_ref()
.and_then(|c| c.use_editorconfig())
.unwrap_or(fs_configuration.use_editorconfig().unwrap_or_default())
.is_some_and(|c| c.use_editorconfig())
|| fs_configuration.use_editorconfig()
}
}

Expand All @@ -40,7 +41,7 @@ impl CommandRunner for CiCommandPayload {
loaded_configuration: LoadedConfiguration,
fs: &dyn FileSystem,
console: &mut dyn Console,
) -> Result<PartialConfiguration, WorkspaceError> {
) -> Result<Configuration, WorkspaceError> {
let LoadedConfiguration {
configuration: biome_configuration,
directory_path: configuration_path,
Expand All @@ -54,23 +55,23 @@ impl CommandRunner for CiCommandPayload {

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

if self.formatter_enabled.is_some() {
formatter.enabled = self.formatter_enabled;
}

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

if self.linter_enabled.is_some() {
linter.enabled = self.linter_enabled;
}

let assist = fs_configuration
.assist
.get_or_insert_with(PartialAssistConfiguration::default);
.get_or_insert_with(AssistConfiguration::default);

if self.assist_enabled.is_some() {
assist.enabled = self.assist_enabled;
Expand All @@ -93,7 +94,7 @@ impl CommandRunner for CiCommandPayload {
fn get_files_to_process(
&self,
fs: &dyn FileSystem,
configuration: &PartialConfiguration,
configuration: &Configuration,
) -> Result<Vec<OsString>, CliDiagnostic> {
if self.changed {
get_changed_files(fs, configuration, self.since.as_deref())
Expand Down Expand Up @@ -121,9 +122,9 @@ impl CommandRunner for CiCommandPayload {
}

fn check_incompatible_arguments(&self) -> Result<(), CliDiagnostic> {
if matches!(self.formatter_enabled, Some(false))
&& matches!(self.linter_enabled, Some(false))
&& matches!(self.assist_enabled, Some(false))
if self.formatter_enabled.is_some_and(|v| !v.value())
&& self.linter_enabled.is_some_and(|v| !v.value())
&& self.assist_enabled.is_some_and(|v| !v.value())
{
return Err(CliDiagnostic::incompatible_end_configuration("Formatter, linter and assist are disabled, can't perform the command. At least one feature needs to be enabled. This is probably and error."));
}
Expand Down
40 changes: 20 additions & 20 deletions crates/biome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::cli_options::CliOptions;
use crate::commands::{get_files_to_process_with_cli_options, CommandRunner, LoadEditorConfig};
use crate::{CliDiagnostic, Execution, TraversalMode};
use biome_configuration::vcs::PartialVcsConfiguration;
use biome_configuration::{
PartialConfiguration, PartialCssFormatter, PartialFilesConfiguration,
PartialFormatterConfiguration, PartialGraphqlFormatter, PartialJavascriptFormatter,
PartialJsonFormatter,
};
use biome_configuration::css::CssFormatterConfiguration;
use biome_configuration::graphql::GraphqlFormatterConfiguration;
use biome_configuration::javascript::JsFormatterConfiguration;
use biome_configuration::json::JsonFormatterConfiguration;
use biome_configuration::vcs::VcsConfiguration;
use biome_configuration::{Configuration, FilesConfiguration, FormatterConfiguration};
use biome_console::Console;
use biome_deserialize::Merge;
use biome_fs::FileSystem;
Expand All @@ -16,13 +16,13 @@ use biome_service::{Workspace, WorkspaceError};
use std::ffi::OsString;

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 All @@ -33,11 +33,11 @@ pub(crate) struct FormatCommandPayload {
}

impl LoadEditorConfig for FormatCommandPayload {
fn should_load_editor_config(&self, fs_configuration: &PartialConfiguration) -> bool {
fn should_load_editor_config(&self, fs_configuration: &Configuration) -> bool {
self.formatter_configuration
.as_ref()
.and_then(|c| c.use_editorconfig)
.unwrap_or(fs_configuration.use_editorconfig().unwrap_or_default())
.is_some_and(|c| c.use_editorconfig_resolved())
|| fs_configuration.use_editorconfig()
}
}

Expand All @@ -49,7 +49,7 @@ impl CommandRunner for FormatCommandPayload {
loaded_configuration: LoadedConfiguration,
fs: &dyn FileSystem,
console: &mut dyn Console,
) -> Result<PartialConfiguration, WorkspaceError> {
) -> Result<Configuration, WorkspaceError> {
let LoadedConfiguration {
configuration: biome_configuration,
directory_path: configuration_path,
Expand All @@ -66,14 +66,14 @@ impl CommandRunner for FormatCommandPayload {
if !configuration
.formatter
.as_ref()
.is_some_and(PartialFormatterConfiguration::is_disabled)
.is_some_and(|f| !f.is_enabled())
{
let formatter = configuration.formatter.get_or_insert_with(Default::default);
if let Some(formatter_configuration) = self.formatter_configuration.clone() {
formatter.merge_with(formatter_configuration);
}

formatter.enabled = Some(true);
formatter.enabled = Some(true.into());
}
if self.css_formatter.is_some() {
let css = configuration.css.get_or_insert_with(Default::default);
Expand Down Expand Up @@ -108,7 +108,7 @@ impl CommandRunner for FormatCommandPayload {
fn get_files_to_process(
&self,
fs: &dyn FileSystem,
configuration: &PartialConfiguration,
configuration: &Configuration,
) -> Result<Vec<OsString>, CliDiagnostic> {
let paths = get_files_to_process_with_cli_options(
self.since.as_deref(),
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(session: CliSession, emit_jsonc: bool) -> Result<(), CliDiagnostic> {
let fs = session.app.workspace.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: 17 additions & 19 deletions crates/biome_cli/src/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ use crate::cli_options::CliOptions;
use crate::commands::{get_files_to_process_with_cli_options, CommandRunner};
use crate::{CliDiagnostic, Execution, TraversalMode};
use biome_configuration::analyzer::RuleSelector;
use biome_configuration::css::PartialCssLinter;
use biome_configuration::javascript::PartialJavascriptLinter;
use biome_configuration::json::PartialJsonLinter;
use biome_configuration::vcs::PartialVcsConfiguration;
use biome_configuration::{
PartialConfiguration, PartialFilesConfiguration, PartialGraphqlLinter,
PartialLinterConfiguration,
};
use biome_configuration::css::CssLinterConfiguration;
use biome_configuration::graphql::GraphqlLinterConfiguration;
use biome_configuration::javascript::JsLinterConfiguration;
use biome_configuration::json::JsonLinterConfiguration;
use biome_configuration::vcs::VcsConfiguration;
use biome_configuration::{Configuration, FilesConfiguration, LinterConfiguration};
use biome_console::Console;
use biome_deserialize::Merge;
use biome_fs::FileSystem;
Expand All @@ -25,20 +23,20 @@ pub(crate) struct LintCommandPayload {
pub(crate) unsafe_: bool,
pub(crate) suppress: bool,
pub(crate) suppression_reason: Option<String>,
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>,
}

impl CommandRunner for LintCommandPayload {
Expand All @@ -49,17 +47,17 @@ impl CommandRunner for LintCommandPayload {
loaded_configuration: LoadedConfiguration,
_fs: &dyn FileSystem,
_console: &mut dyn Console,
) -> Result<PartialConfiguration, WorkspaceError> {
) -> Result<Configuration, WorkspaceError> {
let LoadedConfiguration {
configuration: mut fs_configuration,
..
} = 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_enabled)
{
None
} else {
Expand Down Expand Up @@ -102,7 +100,7 @@ impl CommandRunner for LintCommandPayload {
fn get_files_to_process(
&self,
fs: &dyn FileSystem,
configuration: &PartialConfiguration,
configuration: &Configuration,
) -> Result<Vec<OsString>, CliDiagnostic> {
let paths = get_files_to_process_with_cli_options(
self.since.as_deref(),
Expand Down
Loading
Loading