chore: initialise project layout in test examples#7401
Conversation
|
Walkthrough
Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (5)
crates/biome_test_utils/src/lib.rs (1)
205-213: Panic output: include path and truncate the source to keep CI readableGreat idea to show the source on parse failures. Two tweaks:
- Include the file path in the message.
- Truncate very long content to avoid log spam.
Apply this diff:
let parsed = biome_js_parser::parse(&content, file_source, JsParserOptions::default()); let diagnostics = parsed.diagnostics(); + // Keep logs readable if the file is huge + let mut display_content = content.clone(); + if display_content.len() > 8 * 1024 { + display_content.truncate(8 * 1024); + display_content.push_str("… [truncated]"); + } assert!( diagnostics.is_empty(), - "Unexpected diagnostics: {diagnostics:?}\nWhile parsing:\n{content}" + "Unexpected diagnostics while parsing {path}:\n{diagnostics:?}\n\nSource:\n{display_content}" ); parsed.try_tree()crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs (2)
46-61: Docs: valid example covers key exemptionsGood coverage of declared dep, Node built‑ins, relative import, and an alias.
Small nit: consider also showing an '@/components' example since it’s mentioned above.
87-120: Docs: devDependencies example reads well; broaden the glob?Looks great and exercises multi‑file. You might want
**/tests/**/*.test.jsto cover nested suites.xtask/rules_check/src/lib.rs (2)
228-233: Normalise file= paths more robustly (absolute, backslashes, leading slashes)Current logic can yield paths like
///index.jsif the author writesfile=/index.js, and it doesn’t handle Windows backslashes. Normalise once and ensure a single leading slash.Apply this diff:
- let path = file - .trim_start_matches("./") - .trim_start_matches("../") - .trim(); - test.file_path = Some(format!("/{path}")); + let normalized = file + .trim() + .replace('\\', "/"); + let normalized = normalized + .trim_start_matches("./") + .trim_start_matches("../") + .trim_start_matches('/'); + test.file_path = Some(format!("/{}", normalized));
967-1018: Harden manifest ingestion: surface JSON errors and don’t panic on unknown manifestsTwo refinements for resilience and debuggability:
- If manifest parsing fails, panic with a helpful message (so docs break loudly and early).
- Replace
unimplemented!for unknown manifests with acontinue(ignore gracefully).Apply this diff:
if biome_path.is_manifest() { match biome_path.file_name() { Some("package.json") => { - let parsed = parse_json(src, JsonParserOptions::default()); + let parsed = parse_json(src, JsonParserOptions::default()); + if parsed.has_errors() { + panic!("Failed to parse manifest {} (package.json) in test files", path_buf); + } layout.insert_serialized_node_manifest( path_buf.parent().unwrap().into(), &parsed.syntax().as_send().unwrap(), ); } Some("tsconfig.json") => { - let parsed = parse_json( + let parsed = parse_json( src, JsonParserOptions::default() .with_allow_comments() .with_allow_trailing_commas(), ); + if parsed.has_errors() { + panic!("Failed to parse manifest {} (tsconfig.json) in test files", path_buf); + } layout.insert_serialized_tsconfig( path_buf.parent().unwrap().into(), &parsed.syntax().as_send().unwrap(), ); } - _ => unimplemented!("Unhandled manifest: {biome_path}"), + _ => continue, } } else { added_paths.push(biome_path); }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs(2 hunks)crates/biome_test_utils/src/lib.rs(1 hunks)xtask/rules_check/src/lib.rs(6 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{rs,toml}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Format Rust and TOML files before committing (use
just f/just format).
Files:
crates/biome_test_utils/src/lib.rscrates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rsxtask/rules_check/src/lib.rs
crates/biome_*/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place core crates under /crates/biome_*/
Files:
crates/biome_test_utils/src/lib.rscrates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs
crates/biome_*_{syntax,parser,formatter,analyze,factory,semantic}/**
📄 CodeRabbit inference engine (CLAUDE.md)
Maintain the per-language crate structure: biome_{lang}_{syntax,parser,formatter,analyze,factory,semantic}
Files:
crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs
🧠 Learnings (7)
📚 Learning: 2025-08-11T11:46:05.836Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_diagnostics/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:46:05.836Z
Learning: Applies to crates/biome_diagnostics/**/*.rs : Use helper advice types from biome_diagnostics::v2 (CodeFrameAdvice, CommandAdvice, DiffAdvice, LogAdvice) when suitable
Applied to files:
crates/biome_test_utils/src/lib.rs
📚 Learning: 2025-08-11T11:46:05.836Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_diagnostics/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:46:05.836Z
Learning: Applies to crates/biome_diagnostics/**/*.rs : Types implementing Diagnostic must also implement Debug (e.g., use #[derive(Debug, Diagnostic)])
Applied to files:
crates/biome_test_utils/src/lib.rs
📚 Learning: 2025-09-05T06:39:46.267Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-09-05T06:39:46.267Z
Learning: Applies to crates/biome_analyze/crates/**/lib/src/**/*.rs : Code blocks in rule docs must specify a language; invalid examples use `,expect_diagnostic` and must emit exactly one diagnostic; use `ignore` sparingly
Applied to files:
crates/biome_test_utils/src/lib.rscrates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rsxtask/rules_check/src/lib.rs
📚 Learning: 2025-09-05T06:39:46.267Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-09-05T06:39:46.267Z
Learning: Applies to crates/biome_analyze/crates/**/lib/src/**/*.rs : When showing rule-specific configuration in docs, use `json`/`jsonc` with `,options` (or `,full_options` for full biome.json); follow the modifier order `<lang>[,expect_diagnostic][,(options|full_options|use_options)][,ignore][,file=path]`
Applied to files:
crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs
📚 Learning: 2025-09-05T06:39:46.267Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-09-05T06:39:46.267Z
Learning: Applies to crates/biome_analyze/crates/**/lib/src/**/*.rs : Rule documentation (Rust doc comments) must start with a single-line summary, include `## Examples` with `### Invalid` first then `### Valid`, and document options under `## Options`
Applied to files:
crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs
📚 Learning: 2025-09-05T06:39:46.267Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-09-05T06:39:46.267Z
Learning: Applies to crates/biome_analyze/crates/**/lib/src/**/*.rs : Set the `language` field in `declare_lint_rule!` appropriately (js, jsx, ts, tsx)
Applied to files:
crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs
📚 Learning: 2025-09-05T06:39:46.267Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-09-05T06:39:46.267Z
Learning: Applies to crates/biome_analyze/crates/**/lib/src/**/*.rs : In `declare_lint_rule!`, set `version: "next"` for new or changing rules
Applied to files:
crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs
🧬 Code graph analysis (1)
xtask/rules_check/src/lib.rs (2)
crates/biome_json_parser/src/lib.rs (1)
parse_json(23-26)crates/biome_test_utils/src/lib.rs (1)
get_added_paths(196-217)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (25)
- GitHub Check: autofix
- GitHub Check: Check Dependencies
- GitHub Check: Lint project (depot-windows-2022)
- GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
- GitHub Check: Documentation
- GitHub Check: Test (depot-windows-2022-16)
- GitHub Check: Test Node.js API
- GitHub Check: Test (depot-ubuntu-24.04-arm-16)
- GitHub Check: Bench (biome_js_parser)
- GitHub Check: Bench (biome_package)
- GitHub Check: Bench (biome_module_graph)
- GitHub Check: Bench (biome_html_formatter)
- GitHub Check: Bench (biome_configuration)
- GitHub Check: Bench (biome_html_parser)
- GitHub Check: Bench (biome_json_parser)
- GitHub Check: Bench (biome_json_analyze)
- GitHub Check: Bench (biome_json_formatter)
- GitHub Check: Bench (biome_graphql_formatter)
- GitHub Check: Bench (biome_css_analyze)
- GitHub Check: Bench (biome_graphql_parser)
- GitHub Check: Bench (biome_js_formatter)
- GitHub Check: Bench (biome_css_formatter)
- GitHub Check: Bench (biome_js_analyze)
- GitHub Check: Bench (biome_css_parser)
- GitHub Check: Parser conformance
🔇 Additional comments (4)
crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs (1)
34-41: Docs: invalid example is clear and testableThe package.json + single offending import produces exactly one diagnostic. Nicely done.
xtask/rules_check/src/lib.rs (3)
21-21: Import addition is fineBrings parse_json into scope; all good.
450-450: Confirm behaviour when the code-under-test isn’t in file_system
get_test_servicesbuilds the layout/graph fromtest_filesonly. For code blocks withoutfile=..., we rely on the layout (e.g. package.json) being sufficient forctx.package_path. Please confirm that rules depending on project context (like this one) operate correctly when the analyzed file isn’t part of the in‑memory FS.
621-624: Better failure messageIncluding the code-block path makes triage easier.
CodSpeed Performance ReportMerging #7401 will not alter performanceComparing Summary
Footnotes |
Summary
This adds one more improvement on top of #7399 so that the project layout is also initialised with rule documentation examples for multi-file analysis.
cc @ryan-m-walker
Test Plan
The examples for
noUndeclaredDependencieshave been updated so they are now correctly validated. This shows that multi-file analysis also works withpackage.jsonmanifests.Docs
N/A