Skip to content

Commit

Permalink
finally all tests pass!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Dec 12, 2023
1 parent 3ce8bf5 commit 08b87d6
Show file tree
Hide file tree
Showing 33 changed files with 1,042 additions and 763 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

32 changes: 20 additions & 12 deletions crates/biome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use crate::cli_options::CliOptions;
use crate::configuration::{load_configuration, LoadedConfiguration};
use crate::vcs::store_path_to_ignore_from_vcs;
use crate::commands::validate_configuration_diagnostics;
use crate::vcs::retrieve_gitignore_matches;
use crate::{
execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution, TraversalMode,
};
use biome_service::configuration::organize_imports::OrganizeImports;
use biome_service::configuration::{FormatterConfiguration, LinterConfiguration};
use biome_service::configuration::{
load_configuration, FormatterConfiguration, LinterConfiguration, LoadedConfiguration,
};
use biome_service::workspace::{FixFileMode, UpdateSettingsParams};
use biome_service::{Configuration, MergeWith};
use biome_service::{Configuration, ConfigurationBasePath, MergeWith};
use std::ffi::OsString;
use std::path::PathBuf;

Expand Down Expand Up @@ -54,9 +56,17 @@ pub(crate) fn check(
Some(FixFileMode::SafeAndUnsafeFixes)
};

let loaded_configuration = load_configuration(&mut session, &cli_options)?.with_file_path();
let base_path = match cli_options.config_path.as_ref() {
None => ConfigurationBasePath::default(),
Some(path) => ConfigurationBasePath::FromUser(PathBuf::from(path)),
};

loaded_configuration.check_for_errors(session.app.console, cli_options.verbose)?;
let loaded_configuration = load_configuration(&session.app.fs, base_path)?;
validate_configuration_diagnostics(
&loaded_configuration,
session.app.console,
cli_options.verbose,
)?;

let LoadedConfiguration {
configuration: mut fs_configuration,
Expand Down Expand Up @@ -92,12 +102,8 @@ pub(crate) fn check(

// check if support of git ignore files is enabled
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
store_path_to_ignore_from_vcs(
&mut session,
&mut fs_configuration,
vcs_base_path,
&cli_options,
)?;
let (vcs_base_path, gitignore_matches) =
retrieve_gitignore_matches(&session.app.fs, &fs_configuration, vcs_base_path.clone())?;

let stdin = if let Some(stdin_file_path) = stdin_file_path {
let console = &mut session.app.console;
Expand All @@ -118,6 +124,8 @@ pub(crate) fn check(
.workspace
.update_settings(UpdateSettingsParams {
configuration: fs_configuration,
vcs_base_path,
gitignore_matches,
})?;

execute_mode(
Expand Down
47 changes: 28 additions & 19 deletions crates/biome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::cli_options::CliOptions;
use crate::configuration::LoadedConfiguration;
use crate::vcs::store_path_to_ignore_from_vcs;
use crate::{
configuration::load_configuration, execute_mode, setup_cli_subscriber, CliDiagnostic,
CliSession, Execution,
};
use crate::commands::validate_configuration_diagnostics;
use crate::vcs::retrieve_gitignore_matches;
use crate::{execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution};
use biome_service::configuration::organize_imports::OrganizeImports;
use biome_service::configuration::{FormatterConfiguration, LinterConfiguration};
use biome_service::configuration::{
load_configuration, FormatterConfiguration, LinterConfiguration, LoadedConfiguration,
};
use biome_service::workspace::UpdateSettingsParams;
use biome_service::{Configuration, MergeWith};
use biome_service::{Configuration, ConfigurationBasePath, MergeWith};
use std::ffi::OsString;
use std::path::PathBuf;

pub(crate) struct CiCommandPayload {
pub(crate) formatter_enabled: Option<bool>,
Expand All @@ -21,16 +21,25 @@ pub(crate) struct CiCommandPayload {
}

/// Handler for the "ci" command of the Biome CLI
pub(crate) fn ci(mut session: CliSession, payload: CiCommandPayload) -> Result<(), CliDiagnostic> {
pub(crate) fn ci(session: CliSession, payload: CiCommandPayload) -> Result<(), CliDiagnostic> {
setup_cli_subscriber(
payload.cli_options.log_level.clone(),
payload.cli_options.log_kind.clone(),
);

let loaded_configuration =
load_configuration(&mut session, &payload.cli_options)?.with_file_path();
let base_path = match payload.cli_options.config_path.as_ref() {
None => ConfigurationBasePath::default(),
Some(path) => ConfigurationBasePath::FromUser(PathBuf::from(path)),
};

let loaded_configuration = load_configuration(&session.app.fs, base_path)?;

validate_configuration_diagnostics(
&loaded_configuration,
session.app.console,
payload.cli_options.verbose,
)?;

loaded_configuration.check_for_errors(session.app.console, payload.cli_options.verbose)?;
let LoadedConfiguration {
mut configuration,
directory_path: configuration_path,
Expand Down Expand Up @@ -81,17 +90,17 @@ pub(crate) fn ci(mut session: CliSession, payload: CiCommandPayload) -> Result<(

// check if support of git ignore files is enabled
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
store_path_to_ignore_from_vcs(
&mut session,
&mut configuration,
vcs_base_path,
&payload.cli_options,
)?;
let (vcs_base_path, gitignore_matches) =
retrieve_gitignore_matches(&session.app.fs, &configuration, vcs_base_path.clone())?;

session
.app
.workspace
.update_settings(UpdateSettingsParams { configuration })?;
.update_settings(UpdateSettingsParams {
configuration,
vcs_base_path,
gitignore_matches,
})?;

execute_mode(
Execution::new_ci(),
Expand Down
38 changes: 24 additions & 14 deletions crates/biome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
use crate::cli_options::CliOptions;
use crate::configuration::{load_configuration, LoadedConfiguration};
use crate::commands::validate_configuration_diagnostics;
use crate::diagnostics::DeprecatedArgument;
use crate::execute::ReportMode;
use crate::vcs::store_path_to_ignore_from_vcs;
use crate::vcs::retrieve_gitignore_matches;
use crate::{
execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution, TraversalMode,
};
use biome_console::{markup, ConsoleExt};
use biome_diagnostics::PrintDiagnostic;
use biome_service::configuration::json::JsonFormatter;
use biome_service::configuration::vcs::VcsConfiguration;
use biome_service::configuration::{FilesConfiguration, FormatterConfiguration};
use biome_service::configuration::{
load_configuration, FilesConfiguration, FormatterConfiguration, LoadedConfiguration,
};
use biome_service::workspace::UpdateSettingsParams;
use biome_service::{JavascriptFormatter, MergeWith};
use biome_service::{ConfigurationBasePath, JavascriptFormatter, MergeWith};
use std::ffi::OsString;
use std::path::PathBuf;

Expand Down Expand Up @@ -46,10 +48,17 @@ pub(crate) fn format(
} = payload;
setup_cli_subscriber(cli_options.log_level.clone(), cli_options.log_kind.clone());

let loaded_configuration = load_configuration(&mut session, &cli_options)?.with_file_path();

loaded_configuration.check_for_errors(session.app.console, cli_options.verbose)?;
let base_path = match cli_options.config_path.as_ref() {
None => ConfigurationBasePath::default(),
Some(path) => ConfigurationBasePath::FromUser(PathBuf::from(path)),
};

let loaded_configuration = load_configuration(&session.app.fs, base_path)?;
validate_configuration_diagnostics(
&loaded_configuration,
session.app.console,
cli_options.verbose,
)?;
let LoadedConfiguration {
mut configuration,
directory_path: configuration_path,
Expand Down Expand Up @@ -103,16 +112,17 @@ pub(crate) fn format(

// check if support of git ignore files is enabled
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
store_path_to_ignore_from_vcs(
&mut session,
&mut configuration,
vcs_base_path,
&cli_options,
)?;
let (vcs_base_path, gitignore_matches) =
retrieve_gitignore_matches(&session.app.fs, &configuration, vcs_base_path.clone())?;

session
.app
.workspace
.update_settings(UpdateSettingsParams { configuration })?;
.update_settings(UpdateSettingsParams {
configuration,
vcs_base_path,
gitignore_matches,
})?;

let stdin = if let Some(stdin_file_path) = stdin_file_path {
let console = &mut session.app.console;
Expand Down
32 changes: 20 additions & 12 deletions crates/biome_cli/src/commands/lint.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use crate::cli_options::CliOptions;
use crate::configuration::{load_configuration, LoadedConfiguration};
use crate::vcs::store_path_to_ignore_from_vcs;
use crate::commands::validate_configuration_diagnostics;
use crate::vcs::retrieve_gitignore_matches;
use crate::{
execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution, TraversalMode,
};
use biome_service::configuration::vcs::VcsConfiguration;
use biome_service::configuration::{FilesConfiguration, LinterConfiguration};
use biome_service::configuration::{
load_configuration, FilesConfiguration, LinterConfiguration, LoadedConfiguration,
};
use biome_service::workspace::{FixFileMode, UpdateSettingsParams};
use biome_service::MergeWith;
use biome_service::{ConfigurationBasePath, MergeWith};
use std::ffi::OsString;
use std::path::PathBuf;

Expand Down Expand Up @@ -52,9 +54,17 @@ pub(crate) fn lint(
Some(FixFileMode::SafeAndUnsafeFixes)
};

let loaded_configuration = load_configuration(&mut session, &cli_options)?.with_file_path();
let base_path = match cli_options.config_path.as_ref() {
None => ConfigurationBasePath::default(),
Some(path) => ConfigurationBasePath::FromUser(PathBuf::from(path)),
};

loaded_configuration.check_for_errors(session.app.console, cli_options.verbose)?;
let loaded_configuration = load_configuration(&session.app.fs, base_path)?;
validate_configuration_diagnostics(
&loaded_configuration,
session.app.console,
cli_options.verbose,
)?;

let LoadedConfiguration {
configuration: mut fs_configuration,
Expand All @@ -67,12 +77,8 @@ pub(crate) fn lint(

// check if support of git ignore files is enabled
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
store_path_to_ignore_from_vcs(
&mut session,
&mut fs_configuration,
vcs_base_path,
&cli_options,
)?;
let (vcs_base_path, gitignore_matches) =
retrieve_gitignore_matches(&session.app.fs, &fs_configuration, vcs_base_path.clone())?;

let stdin = if let Some(stdin_file_path) = stdin_file_path {
let console = &mut session.app.console;
Expand All @@ -93,6 +99,8 @@ pub(crate) fn lint(
.workspace
.update_settings(UpdateSettingsParams {
configuration: fs_configuration,
vcs_base_path,
gitignore_matches,
})?;

execute_mode(
Expand Down
12 changes: 9 additions & 3 deletions crates/biome_cli/src/commands/migrate.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
use crate::cli_options::CliOptions;
use crate::configuration::{load_configuration, LoadedConfiguration};
use crate::diagnostics::MigrationDiagnostic;
use crate::execute::{execute_mode, Execution, TraversalMode};
use crate::{setup_cli_subscriber, CliDiagnostic, CliSession};
use biome_service::configuration::{load_configuration, LoadedConfiguration};
use biome_service::ConfigurationBasePath;
use std::path::PathBuf;

/// Handler for the "check" command of the Biome CLI
pub(crate) fn migrate(
mut session: CliSession,
session: CliSession,
cli_options: CliOptions,
write: bool,
) -> Result<(), CliDiagnostic> {
let base_path = match cli_options.config_path.as_ref() {
None => ConfigurationBasePath::default(),
Some(path) => ConfigurationBasePath::FromUser(PathBuf::from(path)),
};
let LoadedConfiguration {
configuration: _,
diagnostics: _,
directory_path,
file_path,
} = load_configuration(&mut session, &cli_options)?;
} = load_configuration(&session.app.fs, base_path)?;
setup_cli_subscriber(cli_options.log_level.clone(), cli_options.log_kind.clone());

if let (Some(path), Some(directory_path)) = (file_path, directory_path) {
Expand Down
47 changes: 44 additions & 3 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use crate::cli_options::{cli_options, CliOptions, ColorsArg};
use crate::diagnostics::DeprecatedConfigurationFile;
use crate::logging::LoggingKind;
use crate::{LoggingLevel, VERSION};
use crate::{CliDiagnostic, LoggingLevel, VERSION};
use biome_console::{markup, Console, ConsoleExt};
use biome_diagnostics::PrintDiagnostic;
use biome_service::configuration::json::JsonFormatter;
use biome_service::configuration::vcs::VcsConfiguration;
use biome_service::configuration::{
configuration, files_configuration, formatter_configuration, javascript::javascript_formatter,
json::json_formatter, linter_configuration, vcs::vcs_configuration, FilesConfiguration,
FormatterConfiguration, JavascriptFormatter, LinterConfiguration,
FormatterConfiguration, JavascriptFormatter, LinterConfiguration, LoadedConfiguration,
};
use biome_service::Configuration;
use biome_service::{Configuration, ConfigurationDiagnostic, WorkspaceError};
use bpaf::Bpaf;
use std::ffi::OsString;
use std::path::PathBuf;
Expand Down Expand Up @@ -311,3 +314,41 @@ impl BiomeCommand {
}
}
}

/// It accepts a [LoadedConfiguration] and it prints the diagnostics emitted during parsing and deserialization.
///
/// If it contains errors, it return an error.
pub(crate) fn validate_configuration_diagnostics(
loaded_configuration: &LoadedConfiguration,
console: &mut dyn Console,
verbose: bool,
) -> Result<(), CliDiagnostic> {
if let Some(file_path) = loaded_configuration
.file_path
.as_ref()
.and_then(|f| f.file_name())
.and_then(|f| f.to_str())
{
if file_path == "rome.json" {
let diagnostic = DeprecatedConfigurationFile::new(file_path);
console.error(markup!{
{if verbose { PrintDiagnostic::verbose(&diagnostic) } else { PrintDiagnostic::simple(&diagnostic) }}
});
}
}
let diagnostics = loaded_configuration.as_diagnostics_iter();
for (diagnostic, path) in diagnostics {
console.error(markup!{
{if verbose { PrintDiagnostic::verbose(diagnostic) } else { PrintDiagnostic::simple(diagnostic) }}
});
}
if loaded_configuration.has_errors() {
return Err(CliDiagnostic::workspace_error(
WorkspaceError::Configuration(ConfigurationDiagnostic::invalid_configuration(
"Biome exited because the configuration resulted in errors. Please fix them.",
)),
));
}

Ok(())
}
Loading

0 comments on commit 08b87d6

Please sign in to comment.