Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/petite-mice-say.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [`#7912`](https://github.com/biomejs/biome/issues/7912), where Biome incorrectly added a leading newline to the code contained inside the Astro frontmatter.
5 changes: 5 additions & 0 deletions .changeset/tricky-masks-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed a regression where formatting wasn't correctly applied when applying safe/unsafe fixes via the Biome linter.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub(crate) fn analyze_with_guard<'ctx>(
.guard()
.fix_file(
*fix_mode,
false,
features_supported.supports_format(),
categories,
only.clone(),
skip.clone(),
Expand Down
53 changes: 53 additions & 0 deletions crates/biome_cli/tests/cases/handle_astro_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,3 +748,56 @@ fn does_not_throw_parse_error_for_return_full_support() {
result,
));
}

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

fs.insert(
"biome.json".into(),
r#"{ "html": { "experimentalFullSupportEnabled": true, "formatter": { "enabled": true } } }"#.as_bytes(),
);

let astro_file_path = Utf8Path::new("file.astro");
fs.insert(
astro_file_path.into(),
r#"---
const title = "Hello World";
---

<html>
<head>
<title>{title}</title>
</head>
<body>
<h1>{title}</h1>
</body>
</html>"#
.as_bytes(),
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(
[
"lint",
"--write",
"--only=suspicious/noDebugger",
astro_file_path.as_str(),
]
.as_slice(),
),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"issue_7912",
fs,
console,
result,
));
}
2 changes: 1 addition & 1 deletion crates/biome_cli/tests/cases/included_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const UNFORMATTED: &str = " statement( ) ";
const FORMATTED: &str = "statement();\n";

const FIX_BEFORE: &str = "(1 >= -0)";
const FIX_AFTER: &str = "(1 >= 0)";
const FIX_AFTER: &str = "1 >= 0;\n";

const UNORGANIZED: &str = r#"import * as something from "../something";
import { lorem, foom, bar } from "foo";"#;
Expand Down
6 changes: 3 additions & 3 deletions crates/biome_cli/tests/cases/overrides_linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use bpaf::Args;
use camino::Utf8Path;

const FIX_BEFORE: &str = "(1 >= -0)";
const FIX_AFTER: &str = "(1 >= 0)";
const FIX_AFTER: &str = "1 >= 0;\n";

const DEBUGGER_BEFORE: &str = "debugger";
const DEBUGGER_BEFORE: &str = "debugger;\n";
const DEBUGGER_AFTER: &str = "";

const SIMPLE_NUMBERS_BEFORE: &str = "({ 0x1: 1 });";
const SIMPLE_NUMBERS_AFTER: &str = "({ 1: 1 });";
const SIMPLE_NUMBERS_AFTER: &str = "({ 1: 1 });\n";

#[test]
fn does_handle_included_file_and_disable_linter() {
Expand Down
6 changes: 3 additions & 3 deletions crates/biome_cli/tests/cases/suppressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use biome_fs::{FileSystemExt, MemoryFileSystem};
use bpaf::Args;
use camino::Utf8Path;

const SUPPRESS_BEFORE: &str = "(1 >= -0)";
const SUPPRESS_BEFORE: &str = "1 >= -0;\n";
const SUPPRESS_AFTER: &str =
"// biome-ignore lint/suspicious/noCompareNegZero: ignored using `--suppress`\n(1 >= -0)";
"// biome-ignore lint/suspicious/noCompareNegZero: ignored using `--suppress`\n1 >= -0;\n";

const SUPPRESS_WITH_REASON: &str =
"// biome-ignore lint/suspicious/noCompareNegZero: We love Biome\n(1 >= -0)";
"// biome-ignore lint/suspicious/noCompareNegZero: We love Biome\n1 >= -0;\n";

#[test]
fn ok() {
Expand Down
8 changes: 4 additions & 4 deletions crates/biome_cli/tests/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const NO_DEBUGGER: &str = "debugger;";
const NEW_SYMBOL: &str = "new Symbol(\"\");";

const FIX_BEFORE: &str = "(1 >= -0)";
const FIX_AFTER: &str = "(1 >= 0)";
const FIX_AFTER: &str = "1 >= 0;\n";

const APPLY_SUGGESTED_BEFORE: &str = "let a = 4;
debugger;
Expand Down Expand Up @@ -306,7 +306,7 @@ function _f() { arguments; }

let expected = "const a = 4;
console.log(a);
function _f() { arguments; }
function _f() {\n\targuments;\n}
";

let test1 = Utf8Path::new("test1.js");
Expand Down Expand Up @@ -516,7 +516,7 @@ fn should_disable_a_rule_group() {
.read_to_string(&mut buffer)
.unwrap();

assert_eq!(buffer, "(1 >= -0)");
assert_eq!(buffer, "1 >= -0;\n");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
Expand Down Expand Up @@ -3593,7 +3593,7 @@ function _f() { arguments; }

let expected = "const a = 4;
console.log(a);
function _f() { arguments; }
function _f() {\n\targuments;\n}
";
let test1 = Utf8Path::new("test1.js");
fs.insert(test1.into(), source.as_bytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ check ━━━━━━━━━━━━━━━━━━━━━━━━
# Emitted Messages

```block
file.astro:16:20 lint/a11y/useGenericFontNames ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
file.astro:17:15 lint/a11y/useGenericFontNames ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Generic font family missing.

15 │ <style>
> 16#id { font-family: comic-sans } .class { background: red}
^^^^^^^^^^
17</style>
18
16 │ <style>#id {
> 17 font-family: comic-sans;
^^^^^^^^^^
18}
19.class {

i Consider adding a generic font family as a fallback.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
---
## `biome.json`

```json
{
"html": {
"experimentalFullSupportEnabled": true,
"formatter": { "enabled": true }
}
}
```

## `file.astro`

```astro
---
const title = "Hello World";
---

<html>
<head>
<title>{title}</title>
</head>
<body>
<h1>{title}</h1>
</body>
</html>

```

# Emitted Messages

```block
Checked 1 file in <TIME>. Fixed 1 file.
```
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ check ━━━━━━━━━━━━━━━━━━━━━━━━
# Emitted Messages

```block
file.svelte:12:20 lint/a11y/useGenericFontNames ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
file.svelte:16:15 lint/a11y/useGenericFontNames ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Generic font family missing.

11 │ <style>
> 12#id { font-family: comic-sans } .class { background: red}
^^^^^^^^^^
13</style>
14
15 │ <style>#id {
> 16 font-family: comic-sans;
^^^^^^^^^^
17}
18.class {

i Consider adding a generic font family as a fallback.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ check ━━━━━━━━━━━━━━━━━━━━━━━━
# Emitted Messages

```block
file.svelte:17:20 lint/a11y/useGenericFontNames ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
file.svelte:21:15 lint/a11y/useGenericFontNames ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Generic font family missing.

16 │ <style>
> 17#id { font-family: comic-sans } .class { background: red}
^^^^^^^^^^
18</style>
19
20 │ <style>#id {
> 21 font-family: comic-sans;
^^^^^^^^^^
22}
23.class {

i Consider adding a generic font family as a fallback.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ check ━━━━━━━━━━━━━━━━━━━━━━━━
# Emitted Messages

```block
file.vue:12:20 lint/a11y/useGenericFontNames ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
file.vue:16:15 lint/a11y/useGenericFontNames ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Generic font family missing.

11 │ <style>
> 12#id { font-family: comic-sans } .class { background: red}
^^^^^^^^^^
13</style>
14
15 │ <style>#id {
> 16 font-family: comic-sans;
^^^^^^^^^^
17}
18.class {

i Consider adding a generic font family as a fallback.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ check ━━━━━━━━━━━━━━━━━━━━━━━━
# Emitted Messages

```block
file.vue:17:20 lint/a11y/useGenericFontNames ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
file.vue:21:15 lint/a11y/useGenericFontNames ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Generic font family missing.

16 │ <style>
> 17#id { font-family: comic-sans } .class { background: red}
^^^^^^^^^^
18</style>
19
20 │ <style>#id {
> 21 font-family: comic-sans;
^^^^^^^^^^
22}
23.class {

i Consider adding a generic font family as a fallback.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,25 @@ check ━━━━━━━━━━━━━━━━━━━━━━━━
# Emitted Messages

```block
file.html:7:48 lint/suspicious/noDuplicateProperties ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
file.html:7:2 lint/suspicious/noDuplicateProperties ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Duplicate properties can lead to unexpected behavior and may override previous declarations unintentionally.

6 │ </script>
> 7 │ <style>#id .class div { background-color: red; background-color: red; } </style>
│ ^^^^^^^^^^^^^^^^
8 │
5 │ <style>#id .class div {
6 │ background-color: red;
> 7 │ background-color: red;
│ ^^^^^^^^^^^^^^^^
8 │ }
9 │ </style>

i background-color is already defined here.

6 │ </script>
> 7 │ <style>#id .class div { background-color: red; background-color: red; } </style>
│ ^^^^^^^^^^^^^^^^
8 │
4 │ </script>
5 │ <style>#id .class div {
> 6 │ background-color: red;
│ ^^^^^^^^^^^^^^^^
7 │ background-color: red;
8 │ }

i Remove or rename the duplicate property to ensure consistent styling.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
snapshot_kind: text
---
## `biome.json`

Expand All @@ -18,7 +17,8 @@ snapshot_kind: text
## `test2.js`

```js
(1 >= 0)
1 >= 0;

```

# Emitted Messages
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
snapshot_kind: text
---
## `biome.json`

Expand All @@ -23,7 +22,8 @@ snapshot_kind: text
## `test.js`

```js
(1 >= 0)
1 >= 0;

```

# Emitted Messages
Expand Down
Loading
Loading