From 243463005946b220712ed6fcfdcb187854ee58f9 Mon Sep 17 00:00:00 2001 From: unvalley Date: Fri, 17 May 2024 18:46:14 +0900 Subject: [PATCH] Add write, fix and unsafe to check command --- crates/biome_cli/src/commands/check.rs | 29 ++++++++++++++------------ crates/biome_cli/src/commands/mod.rs | 13 ++++++++++++ crates/biome_cli/src/lib.rs | 6 ++++++ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/crates/biome_cli/src/commands/check.rs b/crates/biome_cli/src/commands/check.rs index 25899e9e6076..37a40a89bab2 100644 --- a/crates/biome_cli/src/commands/check.rs +++ b/crates/biome_cli/src/commands/check.rs @@ -14,13 +14,18 @@ use biome_service::configuration::PartialConfigurationExt; use biome_service::workspace::RegisterProjectFolderParams; use biome_service::{ configuration::{load_configuration, LoadedConfiguration}, - workspace::{FixFileMode, UpdateSettingsParams}, + workspace::UpdateSettingsParams, }; use std::ffi::OsString; +use super::{determine_fix_file_mode, FixFileModeOptions}; + pub(crate) struct CheckCommandPayload { pub(crate) apply: bool, pub(crate) apply_unsafe: bool, + pub(crate) write: bool, + pub(crate) fix: bool, + pub(crate) unsafe_: bool, pub(crate) cli_options: CliOptions, pub(crate) configuration: Option, pub(crate) paths: Vec, @@ -41,6 +46,9 @@ pub(crate) fn check( let CheckCommandPayload { apply, apply_unsafe, + write, + fix, + unsafe_, cli_options, configuration, mut paths, @@ -54,18 +62,13 @@ pub(crate) fn check( } = payload; setup_cli_subscriber(cli_options.log_level, cli_options.log_kind); - let fix_file_mode = if apply && apply_unsafe { - return Err(CliDiagnostic::incompatible_arguments( - "--apply", - "--apply-unsafe", - )); - } else if !apply && !apply_unsafe { - None - } else if apply && !apply_unsafe { - Some(FixFileMode::SafeFixes) - } else { - Some(FixFileMode::SafeAndUnsafeFixes) - }; + let fix_file_mode = determine_fix_file_mode(FixFileModeOptions { + apply, + apply_unsafe, + write, + fix, + unsafe_, + })?; let loaded_configuration = load_configuration(&session.app.fs, cli_options.as_configuration_path_hint())?; diff --git a/crates/biome_cli/src/commands/mod.rs b/crates/biome_cli/src/commands/mod.rs index c8bad4dda8bb..72c5fdaa6428 100644 --- a/crates/biome_cli/src/commands/mod.rs +++ b/crates/biome_cli/src/commands/mod.rs @@ -82,6 +82,19 @@ pub enum BiomeCommand { /// Apply safe fixes and unsafe fixes, formatting and import sorting #[bpaf(long("apply-unsafe"), switch)] apply_unsafe: bool, + + /// Fixes lint errors safely, formatting and import sorting + #[bpaf(long("fix"))] + fix: bool, + + /// Alias for `--fix`, fixes lint errors safely, formatting and import sorting + #[bpaf(long("write"), switch)] + write: bool, + + /// Fixes lint errors, formatting and import sorting unsafely when used with `--fix` or `--write` + #[bpaf(long("unsafe"), switch)] + unsafe_: bool, + /// Allow to enable or disable the formatter check. #[bpaf( long("formatter-enabled"), diff --git a/crates/biome_cli/src/lib.rs b/crates/biome_cli/src/lib.rs index 55f40092eeb2..ac1feb6d2aaa 100644 --- a/crates/biome_cli/src/lib.rs +++ b/crates/biome_cli/src/lib.rs @@ -82,6 +82,9 @@ impl<'app> CliSession<'app> { BiomeCommand::Check { apply, apply_unsafe, + write, + fix, + unsafe_, cli_options, configuration, paths, @@ -97,6 +100,9 @@ impl<'app> CliSession<'app> { CheckCommandPayload { apply_unsafe, apply, + write, + fix, + unsafe_, cli_options, configuration, paths,