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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
/crates/biome_html_analyze/src/{lint,assist,syntax}/*.rs linguist-generated=true text=auto eol=lf
/crates/biome_html_analyze/src/options.rs linguist-generated=true text=auto eol=lf
/crates/biome_html_analyze/src/registry.rs linguist-generated=true text=auto eol=lf
/crates/biome_html_parser/benches/fixtures/** linguist-vendored text=auto eol=lf

# Other
/crates/biome_unicode_table/src/tables.rs linguist-generated=true text=auto eol=lf
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/biome_html_formatter/benches/fixtures
69 changes: 68 additions & 1 deletion crates/biome_html_formatter/benches/html_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use biome_html_formatter::{HtmlFormatOptions, format_node};
use biome_html_parser::{HtmlParseOptions, parse_html};
use biome_html_syntax::{HtmlFileSource, HtmlRoot};
use biome_rowan::AstNode;
use biome_string_case::StrLikeExtension;
use biome_test_utils::BenchCase;
use criterion::{BenchmarkId, Criterion, Throughput, black_box, criterion_group, criterion_main};
use std::collections::HashMap;
use std::{collections::HashMap, fs, path::Path};

#[cfg(target_os = "windows")]
#[global_allocator]
Expand All @@ -22,11 +23,51 @@ static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
#[cfg(all(target_env = "musl", target_os = "linux", target_arch = "aarch64"))]
#[global_allocator]
static GLOBAL: std::alloc::System = std::alloc::System;
fn load_fixtures() -> Vec<(String, String, String)> {
let fixtures_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("benches/fixtures");
let mut cases = Vec::new();

fn visit(dir: &Path, root: &Path, cases: &mut Vec<(String, String, String)>) {
if let Ok(entries) = fs::read_dir(dir) {
for entry in entries.flatten() {
let path = entry.path();
if path.is_dir() {
visit(&path, root, cases);
} else if path.is_file() {
if matches!(path.extension().and_then(|e| e.to_str()), Some(ext) if ext.eq_ignore_ascii_case("md"))
{
continue;
}
let rel = path.strip_prefix(root).unwrap_or(&path);
let group = rel
.iter()
.next()
.and_then(|s| s.to_str())
.unwrap_or("root")
.to_string();
let name = path
.file_name()
.and_then(|s| s.to_str())
.unwrap_or_default()
.to_string();
if let Ok(content) = fs::read_to_string(&path) {
cases.push((group, name, content));
}
}
}
}
}

visit(&fixtures_root, &fixtures_root, &mut cases);
cases
}

fn bench_formatter(criterion: &mut Criterion) {
let mut all_suites = HashMap::new();
all_suites.insert("html", include_str!("libs-html.txt"));
let mut libs = vec![];
libs.extend(all_suites.values().flat_map(|suite| suite.lines()));
let fixtures = load_fixtures();

let mut group = criterion.benchmark_group("html_formatter");

Expand Down Expand Up @@ -60,6 +101,32 @@ fn bench_formatter(criterion: &mut Criterion) {
Err(e) => println!("{e:?}"),
}
}
// Benchmark local fixtures with group names included in the benchmark ID
for (group_name, name, content) in fixtures {
let code = &content;
let ext = name
.rsplit('.')
.next()
.unwrap_or_default()
.to_ascii_lowercase_cow();
let file_source = HtmlFileSource::try_from_extension(&ext).unwrap_or_default();
let parsed = parse_html(code, HtmlParseOptions::from(&file_source));
group.throughput(Throughput::Bytes(code.len() as u64));
let id = format!("{}/{}", group_name, name);
group.bench_with_input(BenchmarkId::new(&id, "format"), code, |b, _| {
fn format(root: HtmlRoot) -> Printed {
let formatted =
format_node(HtmlFormatOptions::default(), root.syntax(), false).unwrap();
let printed = formatted.print();
drop(formatted);
printed.expect("Document to be valid")
}
b.iter(|| {
black_box(format(parsed.tree()));
})
});
}

group.finish();
}

Expand Down
1 change: 1 addition & 0 deletions crates/biome_html_parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ biome_unicode_table = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
biome_string_case = { workspace = true }
biome_test_utils = { workspace = true }
camino = { workspace = true }
Comment on lines 28 to 31
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Find biome_string_case location and check workspace configuration
find . -name "Cargo.toml" -path "*/biome_string_case/*" | head -5

# Check if biome_string_case is defined in workspace
rg "biome_string_case" -g 'Cargo.toml' -B 2 -A 2 | head -40

# Check the workspace root Cargo.toml for dependency definitions
head -100 Cargo.toml | grep -A 50 "dependencies"

# See how other crates handle dev-dependencies
rg "\[dev-dependencies\]" -A 10 -g 'Cargo.toml' crates/ | head -60

Repository: biomejs/biome

Length of output: 10350


Switch biome_string_case to a path dev-dependency.

Dev-dependencies should use path-based references to avoid requiring published versions. Change line 29 from workspace to path.

Suggested change
-biome_string_case = { workspace = true }
+biome_string_case = { path = "../biome_string_case" }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[dev-dependencies]
biome_string_case = { workspace = true }
biome_test_utils = { workspace = true }
camino = { workspace = true }
[dev-dependencies]
biome_string_case = { path = "../biome_string_case" }
biome_test_utils = { workspace = true }
camino = { workspace = true }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_html_parser/Cargo.toml` around lines 28 - 31, Update the
dev-dependency entry for biome_string_case in the crate's Cargo.toml to use a
path-based reference instead of workspace = true: replace the existing
biome_string_case = { workspace = true } with a path-based specification (e.g.,
biome_string_case = { path = "../biome_string_case" }) so the dev-dependency
points at the local crate; leave the other dev-dependencies (biome_test_utils,
camino) unchanged.

criterion = { package = "codspeed-criterion-compat", version = "*" }
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_html_parser/benches/fixtures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `real/` contains pages from real websites, saved as HTML files with no modifications.
- `synthetic/` contains HTML files that were created specifically for testing purposes.
Loading