Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@arendjr
Copy link
Contributor

@arendjr arendjr commented Sep 5, 2025

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 noUndeclaredDependencies have been updated so they are now correctly validated. This shows that multi-file analysis also works with package.json manifests.

Docs

N/A

@arendjr arendjr requested review from a team September 5, 2025 08:20
@changeset-bot
Copy link

changeset-bot bot commented Sep 5, 2025

⚠️ No Changeset found

Latest commit: 202edb5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 5, 2025

Walkthrough

  • Updates documentation comments for the noUndeclaredDependencies rule: switches to package.json-based examples, clarifies what imports are ignored, and adds a fuller devDependencies example with multi-file scenarios; no runtime or API changes.
  • Enhances get_added_paths panic output to include the parsed content alongside diagnostics; logic unchanged.
  • Refactors rules test harness: introduces get_test_services(file_source, files) to build JsAnalyzerServices from a ModuleGraph and ProjectLayout, adds JSON manifest parsing for package.json and tsconfig.json, replaces previous setup calls, normalises file paths, and tweaks diagnostic messages.

Possibly related PRs

Suggested labels

A-Tooling, A-Linter, L-JSON

Suggested reviewers

  • siketyan
  • ematipico
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added A-Linter Area: linter A-Tooling Area: internal tools L-JavaScript Language: JavaScript and super languages labels Sep 5, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 readable

Great 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 exemptions

Good 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.js to 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.js if the author writes file=/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 manifests

Two 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 a continue (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.

📥 Commits

Reviewing files that changed from the base of the PR and between daa4a66 and 202edb5.

📒 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.rs
  • crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs
  • xtask/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.rs
  • crates/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.rs
  • crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs
  • xtask/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 testable

The package.json + single offending import produces exactly one diagnostic. Nicely done.

xtask/rules_check/src/lib.rs (3)

21-21: Import addition is fine

Brings parse_json into scope; all good.


450-450: Confirm behaviour when the code-under-test isn’t in file_system

get_test_services builds the layout/graph from test_files only. For code blocks without file=..., we rely on the layout (e.g. package.json) being sufficient for ctx.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 message

Including the code-block path makes triage easier.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 5, 2025

CodSpeed Performance Report

Merging #7401 will not alter performance

Comparing arendjr:initialise-project-layout-in-test-examples (202edb5) with main (b43b704)1

Summary

✅ 133 untouched benchmarks

Footnotes

  1. No successful run was found on main (daa4a66) during the generation of this report, so b43b704 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@arendjr arendjr merged commit 56af34b into biomejs:main Sep 5, 2025
30 checks passed
kedevked pushed a commit to kedevked/biome that referenced this pull request Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter A-Tooling Area: internal tools L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant