Skip to content
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
14 changes: 14 additions & 0 deletions .changeset/icy-views-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@biomejs/biome": minor
---

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
```

35 changes: 35 additions & 0 deletions crates/biome_cli/tests/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
}
35 changes: 35 additions & 0 deletions crates/biome_cli/tests/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
}
Original file line number Diff line number Diff line change
@@ -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 <TIME>. Fixed 1 file.
Found 2 errors.
```
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ The configuration that is contained inside the file `biome.json`
1 MiB
--files-ignore-unknown=<true|false> Tells Biome to not emit diagnostics when handling files
that doesn't know
--format-with-errors=<true|false> Stores whether formatting should be allowed to proceed if
a given file has syntax errors
--indent-style=<tab|space> The indent style.
--indent-width=NUMBER The size of the indentation, 2 by default
--line-ending=<lf|crlf|cr|auto> The type of line ending.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ The configuration that is contained inside the file `biome.json`
1 MiB
--files-ignore-unknown=<true|false> Tells Biome to not emit diagnostics when handling files
that doesn't know
--format-with-errors=<true|false> Stores whether formatting should be allowed to proceed if
a given file has syntax errors
--indent-style=<tab|space> The indent style.
--indent-width=NUMBER The size of the indentation, 2 by default
--line-ending=<lf|crlf|cr|auto> The type of line ending.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Run the formatter on a set of files.
Usage: format [--write] [--staged] [--changed] [--since=REF] [PATH]...

Generic options applied to all files
--format-with-errors=<true|false> Stores whether formatting should be allowed to proceed if
a given file has syntax errors
--indent-style=<tab|space> The indent style.
--indent-width=NUMBER The size of the indentation, 2 by default
--line-ending=<lf|crlf|cr|auto> The type of line ending.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
---
## `invalid.js`

```js
while ) {}

```

# Termination Message

```block
format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Some errors were emitted while running checks.



```

# Emitted Messages

```block
invalid.js:1:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× expected `(` but instead found `)`

> 1 │ while ) {}
│ ^

i Remove )


```

```block
Formatted 1 file in <TIME>. Fixed 1 file.
Found 1 error.
```
2 changes: 1 addition & 1 deletion crates/biome_configuration/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct FormatterConfiguration {

/// Stores whether formatting should be allowed to proceed if a given file
/// has syntax errors
#[bpaf(hide)]
#[bpaf(long("format-with-errors"), argument("true|false"))]
#[serde(skip_serializing_if = "Option::is_none")]
pub format_with_errors: Option<FormatWithErrorsEnabled>,

Expand Down
Loading