From dd9b57d518c57c88a8274620e66a8edf2b65d35a Mon Sep 17 00:00:00 2001 From: cadunass Date: Thu, 9 Oct 2025 00:45:49 -0300 Subject: [PATCH 1/3] feat(cli): expose formatWithErrors via --format-with-errors flag The formatWithErrors option can now be set via CLI using the --format-with-errors flag. This flag was previously only available in the configuration file. --- .changeset/icy-views-lick.md | 13 +++++ crates/biome_cli/tests/commands/check.rs | 35 ++++++++++++ crates/biome_cli/tests/commands/format.rs | 35 ++++++++++++ ..._with_syntax_errors_when_flag_enabled.snap | 54 +++++++++++++++++++ .../main_commands_check/check_help.snap | 2 + .../snapshots/main_commands_ci/ci_help.snap | 2 + .../main_commands_format/format_help.snap | 2 + ..._with_syntax_errors_when_flag_enabled.snap | 41 ++++++++++++++ crates/biome_configuration/src/formatter.rs | 2 +- 9 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 .changeset/icy-views-lick.md create mode 100644 crates/biome_cli/tests/snapshots/main_commands_check/check_format_with_syntax_errors_when_flag_enabled.snap create mode 100644 crates/biome_cli/tests/snapshots/main_commands_format/should_format_file_with_syntax_errors_when_flag_enabled.snap diff --git a/.changeset/icy-views-lick.md b/.changeset/icy-views-lick.md new file mode 100644 index 000000000000..2d054915007b --- /dev/null +++ b/.changeset/icy-views-lick.md @@ -0,0 +1,13 @@ +--- +"@biomejs/biome": patch +--- + +The `formatWithErrors` option can now be set via CLI using the `--format-with-errors` flag. + +This flag was previously only available in the configuration file. It allows formatting to proceed on files with syntax errors, which is useful during development when you want to auto-format code while fixing syntax issues. + +Example: +```shell +biome format --format-with-errors=true --write file.js +``` + diff --git a/crates/biome_cli/tests/commands/check.rs b/crates/biome_cli/tests/commands/check.rs index 6c8e39fc84b2..7fedfad28813 100644 --- a/crates/biome_cli/tests/commands/check.rs +++ b/crates/biome_cli/tests/commands/check.rs @@ -3251,3 +3251,38 @@ fn check_does_not_enable_assist() { result, )); } + +#[test] +fn check_format_with_syntax_errors_when_flag_enabled() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let invalid = Utf8Path::new("invalid.js"); + fs.insert(invalid.into(), "while ) {}".as_bytes()); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from( + [ + "check", + "--format-with-errors=true", + "--write", + invalid.as_str(), + ] + .as_slice(), + ), + ); + + assert!(result.is_err(), "run_cli returned {result:?}"); + + assert_file_contents(&fs, invalid, "while ) {}\n"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "check_format_with_syntax_errors_when_flag_enabled", + fs, + console, + result, + )); +} diff --git a/crates/biome_cli/tests/commands/format.rs b/crates/biome_cli/tests/commands/format.rs index a953a9b49f78..68478f8391d5 100644 --- a/crates/biome_cli/tests/commands/format.rs +++ b/crates/biome_cli/tests/commands/format.rs @@ -3549,3 +3549,38 @@ fn should_not_format_file_with_syntax_errors() { result, )); } + +#[test] +fn should_format_file_with_syntax_errors_when_flag_enabled() { + let fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let invalid = Utf8Path::new("invalid.js"); + fs.insert(invalid.into(), "while ) {}".as_bytes()); + + let (fs, result) = run_cli( + fs, + &mut console, + Args::from( + [ + "format", + "--format-with-errors=true", + "--write", + invalid.as_str(), + ] + .as_slice(), + ), + ); + + assert!(result.is_err(), "run_cli returned {result:?}"); + + assert_file_contents(&fs, invalid, "while ) {}\n"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "should_format_file_with_syntax_errors_when_flag_enabled", + fs, + console, + result, + )); +} diff --git a/crates/biome_cli/tests/snapshots/main_commands_check/check_format_with_syntax_errors_when_flag_enabled.snap b/crates/biome_cli/tests/snapshots/main_commands_check/check_format_with_syntax_errors_when_flag_enabled.snap new file mode 100644 index 000000000000..eec4334f47a1 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_commands_check/check_format_with_syntax_errors_when_flag_enabled.snap @@ -0,0 +1,54 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: redactor(content) +--- +## `invalid.js` + +```js +while ) {} + +``` + +# Termination Message + +```block +check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Some errors were emitted while applying fixes. + + + +``` + +# Emitted Messages + +```block +invalid.js:1:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `(` but instead found `)` + + > 1 │ while ) {} + │ ^ + + i Remove ) + + +``` + +```block +invalid.js:1:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `(` but instead found `)` + + > 1 │ while ) {} + │ ^ + + i Remove ) + + +``` + +```block +Checked 1 file in