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

chore: deprecate --apply and --apply-unsafe options #2918

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
The `biome migrate --fix` has the same behavior as `biome migrate --write`.

This change allows these commands to write modifications in the same options.
With this change, the `--apply` and `--apply-unsafe` options are deprecated.

Contributed by @unvalley

Expand Down
24 changes: 18 additions & 6 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::changed::{get_changed_files, get_staged_files};
use crate::cli_options::{cli_options, CliOptions, ColorsArg};
use crate::diagnostics::DeprecatedConfigurationFile;
use crate::diagnostics::{DeprecatedArgument, DeprecatedConfigurationFile};
use crate::execute::Stdin;
use crate::logging::LoggingKind;
use crate::{CliDiagnostic, CliSession, LoggingLevel, VERSION};
Expand Down Expand Up @@ -91,11 +91,11 @@ pub enum BiomeCommand {
#[bpaf(long("fix"), switch, hide_usage)]
fix: bool,

/// Alias for `--write`, writes safe fixes, formatting and import sorting
/// Alias for `--write`, writes safe fixes, formatting and import sorting (deprecated, use `--write`)
#[bpaf(long("apply"), switch, hide_usage)]
apply: bool,

/// Alias for `--write --unsafe`, writes safe and unsafe fixes, formatting and import sorting
/// Alias for `--write --unsafe`, writes safe and unsafe fixes, formatting and import sorting (deprecated, use `--write --unsafe`)
#[bpaf(long("apply-unsafe"), switch, hide_usage)]
apply_unsafe: bool,

Expand Down Expand Up @@ -164,11 +164,11 @@ pub enum BiomeCommand {
#[bpaf(long("fix"), switch, hide_usage)]
fix: bool,

/// Alias for `--write`, writes safe fixes
/// Alias for `--write`, writes safe fixes (deprecated, use `--write`)
#[bpaf(long("apply"), switch, hide_usage)]
apply: bool,

/// Alias for `--write --unsafe`, writes safe and unsafe fixes
/// Alias for `--write --unsafe`, writes safe and unsafe fixes (deprecated, use `--write --unsafe`)
#[bpaf(long("apply-unsafe"), switch, hide_usage)]
apply_unsafe: bool,

Expand Down Expand Up @@ -641,7 +641,7 @@ pub(crate) struct FixFileModeOptions {
/// - [FixFileMode]: if safe or unsafe fixes are requested
pub(crate) fn determine_fix_file_mode(
options: FixFileModeOptions,
_console: &mut dyn Console,
console: &mut dyn Console,
) -> Result<Option<FixFileMode>, CliDiagnostic> {
let FixFileModeOptions {
apply,
Expand All @@ -651,6 +651,18 @@ pub(crate) fn determine_fix_file_mode(
unsafe_,
} = options;

if apply || apply_unsafe {
let (deprecated, alternative) = if apply {
("--apply", "--write")
} else {
("--apply-unsafe", "--write --unsafe")
};
let diagnostic = DeprecatedArgument::new(markup! {
"The argument "<Emphasis>{deprecated}</Emphasis>" is deprecated, it will be removed in the next major release. Use "<Emphasis>{alternative}</Emphasis>" instead."
});
console.error(markup! {{PrintDiagnostic::simple(&diagnostic)}});
}

check_fix_incompatible_arguments(options)?;

let safe_fixes = apply || write || fix;
Expand Down
42 changes: 30 additions & 12 deletions crates/biome_cli/tests/cases/handle_astro_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ fn lint_stdin_successfully() {
}

#[test]
fn lint_stdin_apply_successfully() {
fn lint_stdin_write_successfully() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

Expand All @@ -501,7 +501,7 @@ fn lint_stdin_apply_successfully() {
let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(["lint", "--apply", "--stdin-file-path", "file.astro"].as_slice()),
Args::from(["lint", "--write", "--stdin-file-path", "file.astro"].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");
Expand All @@ -519,15 +519,15 @@ fn lint_stdin_apply_successfully() {

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"lint_stdin_apply_successfully",
"lint_stdin_write_successfully",
fs,
console,
result,
));
}

#[test]
fn lint_stdin_apply_unsafe_successfully() {
fn lint_stdin_write_unsafe_successfully() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

Expand All @@ -538,7 +538,16 @@ fn lint_stdin_apply_unsafe_successfully() {
let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(["lint", "--apply-unsafe", "--stdin-file-path", "file.astro"].as_slice()),
Args::from(
[
"lint",
"--write",
"--unsafe",
"--stdin-file-path",
"file.astro",
]
.as_slice(),
),
);

assert!(result.is_ok(), "run_cli returned {result:?}");
Expand All @@ -556,7 +565,7 @@ fn lint_stdin_apply_unsafe_successfully() {

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"lint_stdin_apply_unsafe_successfully",
"lint_stdin_write_unsafe_successfully",
fs,
console,
result,
Expand Down Expand Up @@ -599,7 +608,7 @@ fn check_stdin_successfully() {
}

#[test]
fn check_stdin_apply_successfully() {
fn check_stdin_write_successfully() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

Expand All @@ -608,7 +617,7 @@ fn check_stdin_apply_successfully() {
let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(["check", "--apply", "--stdin-file-path", "file.astro"].as_slice()),
Args::from(["check", "--write", "--stdin-file-path", "file.astro"].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");
Expand All @@ -626,15 +635,15 @@ fn check_stdin_apply_successfully() {

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"check_stdin_apply_successfully",
"check_stdin_write_successfully",
fs,
console,
result,
));
}

#[test]
fn check_stdin_apply_unsafe_successfully() {
fn check_stdin_write_unsafe_successfully() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

Expand All @@ -643,7 +652,16 @@ fn check_stdin_apply_unsafe_successfully() {
let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(["check", "--apply-unsafe", "--stdin-file-path", "file.astro"].as_slice()),
Args::from(
[
"check",
"--write",
"--unsafe",
"--stdin-file-path",
"file.astro",
]
.as_slice(),
),
);

assert!(result.is_ok(), "run_cli returned {result:?}");
Expand All @@ -661,7 +679,7 @@ fn check_stdin_apply_unsafe_successfully() {

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"check_stdin_apply_unsafe_successfully",
"check_stdin_write_unsafe_successfully",
fs,
console,
result,
Expand Down
34 changes: 22 additions & 12 deletions crates/biome_cli/tests/cases/handle_svelte_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ fn lint_stdin_successfully() {
}

#[test]
fn lint_stdin_apply_successfully() {
fn lint_stdin_write_successfully() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

Expand All @@ -385,7 +385,7 @@ fn lint_stdin_apply_successfully() {
let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(["lint", "--apply", "--stdin-file-path", "file.svelte"].as_slice()),
Args::from(["lint", "--write", "--stdin-file-path", "file.svelte"].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");
Expand All @@ -403,15 +403,15 @@ fn lint_stdin_apply_successfully() {

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"lint_stdin_apply_successfully",
"lint_stdin_write_successfully",
fs,
console,
result,
));
}

#[test]
fn lint_stdin_apply_unsafe_successfully() {
fn lint_stdin_write_unsafe_successfully() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

Expand All @@ -422,7 +422,16 @@ fn lint_stdin_apply_unsafe_successfully() {
let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(["lint", "--apply-unsafe", "--stdin-file-path", "file.svelte"].as_slice()),
Args::from(
[
"lint",
"--write",
"--unsafe",
"--stdin-file-path",
"file.svelte",
]
.as_slice(),
),
);

assert!(result.is_ok(), "run_cli returned {result:?}");
Expand All @@ -440,7 +449,7 @@ fn lint_stdin_apply_unsafe_successfully() {

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"lint_stdin_apply_unsafe_successfully",
"lint_stdin_write_unsafe_successfully",
fs,
console,
result,
Expand Down Expand Up @@ -485,7 +494,7 @@ fn check_stdin_successfully() {
}

#[test]
fn check_stdin_apply_successfully() {
fn check_stdin_write_successfully() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

Expand All @@ -496,7 +505,7 @@ fn check_stdin_apply_successfully() {
let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(["check", "--apply", "--stdin-file-path", "file.svelte"].as_slice()),
Args::from(["check", "--write", "--stdin-file-path", "file.svelte"].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");
Expand All @@ -514,15 +523,15 @@ fn check_stdin_apply_successfully() {

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"check_stdin_apply_successfully",
"check_stdin_write_successfully",
fs,
console,
result,
));
}

#[test]
fn check_stdin_apply_unsafe_successfully() {
fn check_stdin_write_unsafe_successfully() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

Expand All @@ -536,7 +545,8 @@ fn check_stdin_apply_unsafe_successfully() {
Args::from(
[
"check",
"--apply-unsafe",
"--write",
"--unsafe",
"--stdin-file-path",
"file.svelte",
]
Expand All @@ -559,7 +569,7 @@ fn check_stdin_apply_unsafe_successfully() {

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"check_stdin_apply_unsafe_successfully",
"check_stdin_write_unsafe_successfully",
fs,
console,
result,
Expand Down
Loading