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
5 changes: 5 additions & 0 deletions .changeset/some-badgers-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Improved performance for [`noImportCycles`](https://biomejs.dev/linter/rules/no-import-cycles/) by explicitly excluding node_modules from the cycle detection. The performance improvement is directly proportional to how big your dependency tree is.
16 changes: 16 additions & 0 deletions crates/biome_js_analyze/src/lint/suspicious/no_import_cycles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ impl Rule for NoImportCycles {
}

let resolved_path = resolved_path.as_path()?;

// Don't check for cycles through node_modules imports.
if is_node_modules_path(resolved_path) {
return None;
}

let imports = ctx.module_info_for_path(resolved_path)?;

find_cycle(ctx, resolved_path, imports)
Expand Down Expand Up @@ -252,6 +258,11 @@ fn find_cycle(
continue;
};

// Skip node_modules paths — we don't traverse into dependencies.
if is_node_modules_path(path) {
continue;
}

if !seen.insert(resolved_path.clone()) {
continue;
}
Expand Down Expand Up @@ -295,3 +306,8 @@ fn find_cycle(

None
}

/// Returns `true` if the given path is inside a `node_modules` directory.
fn is_node_modules_path(path: &Utf8Path) -> bool {
path.components().any(|c| c.as_str() == "node_modules")
}
Loading