Skip to content

Commit

Permalink
Add write, fix and unsafe to check command
Browse files Browse the repository at this point in the history
  • Loading branch information
unvalley committed May 17, 2024
1 parent 45b5b59 commit 2434630
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
29 changes: 16 additions & 13 deletions crates/biome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PartialConfiguration>,
pub(crate) paths: Vec<OsString>,
Expand All @@ -41,6 +46,9 @@ pub(crate) fn check(
let CheckCommandPayload {
apply,
apply_unsafe,
write,
fix,
unsafe_,
cli_options,
configuration,
mut paths,
Expand All @@ -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())?;
Expand Down
13 changes: 13 additions & 0 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
6 changes: 6 additions & 0 deletions crates/biome_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ impl<'app> CliSession<'app> {
BiomeCommand::Check {
apply,
apply_unsafe,
write,
fix,
unsafe_,
cli_options,
configuration,
paths,
Expand All @@ -97,6 +100,9 @@ impl<'app> CliSession<'app> {
CheckCommandPayload {
apply_unsafe,
apply,
write,
fix,
unsafe_,
cli_options,
configuration,
paths,
Expand Down

0 comments on commit 2434630

Please sign in to comment.