+
Skip to content

Conversation

siketyan
Copy link
Member

Summary

Fixed #7162

Type-only imports are no longer required to be declared in the dependencies section.

Test Plan

Added a snapshot test.

Docs

Updated the doc comment.

@siketyan siketyan requested review from a team August 10, 2025 08:28
@siketyan siketyan self-assigned this Aug 10, 2025
Copy link

changeset-bot bot commented Aug 10, 2025

🦋 Changeset detected

Latest commit: 0ae5ff0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Contributor

coderabbitai bot commented Aug 10, 2025

Walkthrough

This change updates the noUndeclaredDependencies lint rule in the @biomejs/biome crate to treat type-only imports as satisfied by devDependencies. A helper is_type_import was added and the dev-dependency availability check treats type-only imports as available. Tests and a changeset entry were added to demonstrate a type-only import (e.g. import type { SetRequired } from "type-fest";) is no longer reported when listed in devDependencies. No public API surface changes were introduced.

Assessment against linked issues

Objective (issues) Addressed Explanation
Update noUndeclaredDependencies to ignore type-only imports (#7162)
Ensure type-only imports are allowed if declared in devDependencies (#7162)
Add/adjust tests to verify correct handling of type-only imports (#7162)

Suggested labels

A-Parser

✨ Finishing Touches
🧪 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. Examples:
    • @coderabbitai explain this code block.
  • 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 src/utils.ts and explain its main purpose.
    • @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 comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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.

Documentation and Community

  • 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 L-JavaScript Language: JavaScript and super languages labels Aug 10, 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: 2

🧹 Nitpick comments (5)
crates/biome_js_analyze/tests/specs/correctness/noUndeclaredDependencies/valid.ts (1)

41-42: Great addition to validate type-only import handling.

This cleanly asserts the rule’s behaviour without coupling to specific exports. Consider adding a second variant (e.g. import type * as ns from "type-fest";) in a follow-up to broaden coverage.

.changeset/two-badgers-cut.md (1)

9-9: Optional: tidy punctuation to match writing guidelines.

The label lines end with a colon; the style guide asks for full stops. If you want to appease linters, swap the trailing colons for full stops.

Also applies to: 18-18

crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs (3)

45-50: Doc example is helpful; please clarify the option interaction.

State explicitly that type-only imports are allowed even when devDependencies is disabled via rule options (if that’s the intended behaviour).

Example tweak:

 /// If you have declared `type-fest` in the `devDependencies` section:
@@
 /// import type { SetRequired } from "type-fest";
 /// ```
+///
+/// Note: Type-only imports are always permitted and treated as `devDependencies`,
+/// regardless of the `devDependencies` option for this rule.

147-158: Reuse the helper for consistency.

You can use is_type_import(node) here rather than duplicating type_token() access, improving cohesion.

-            if let Some(import_clause) = node.parent::<AnyJsImportClause>()
-                && import_clause.type_token().is_some()
+            if is_type_import(node)
             {
                 let package_name = format!("@types/{package_name}");

269-274: Helper reads well; minor naming nit.

Consider is_type_only_import for precision, but not a blocker.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7424b9a and 7fdcae8.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/correctness/noUndeclaredDependencies/valid.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • .changeset/two-badgers-cut.md (1 hunks)
  • crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs (3 hunks)
  • crates/biome_js_analyze/tests/specs/correctness/noUndeclaredDependencies/valid.package.json (1 hunks)
  • crates/biome_js_analyze/tests/specs/correctness/noUndeclaredDependencies/valid.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
crates/biome_*/**/*

📄 CodeRabbit Inference Engine (CLAUDE.md)

Core crates must be located in /crates/biome_*/

Files:

  • crates/biome_js_analyze/tests/specs/correctness/noUndeclaredDependencies/valid.ts
  • crates/biome_js_analyze/tests/specs/correctness/noUndeclaredDependencies/valid.package.json
  • crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs
.changeset/*.md

📄 CodeRabbit Inference Engine (CONTRIBUTING.md)

.changeset/*.md: When creating a changeset, use just new-changeset and do not create changeset files manually. Changesets are stored in the .changeset folder.
Changeset descriptions should be user-facing, use past or present tense as appropriate, reference issues and rules with links, include code blocks when applicable, and end every sentence with a full stop.

Files:

  • .changeset/two-badgers-cut.md
**/*.{rs,toml}

📄 CodeRabbit Inference Engine (CLAUDE.md)

Format code (Rust + TOML) using just format

Format Rust and TOML files using just f (alias for just format).

Files:

  • crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs
**/*.rs

📄 CodeRabbit Inference Engine (CONTRIBUTING.md)

**/*.rs: Use Rust's doctest feature by writing code examples in doc comments, which are run during the testing phase.
Use the insta crate for snapshot testing in Rust, and manage snapshots with cargo insta accept, cargo insta reject, or cargo insta review.
Use the dbg!() macro in Rust for debugging during test runs, and pass --show-output to cargo to display debug output.
If your PR involves new features or changes to existing features, update documentation accordingly, using inline rustdoc for rules, assists, and options.
When releasing a new version, update all version: "next" fields in rule metadata to the new version number.

Files:

  • crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs
🪛 LanguageTool
.changeset/two-badgers-cut.md

[uncategorized] ~9-~9: Loose punctuation mark.
Context: ... no longer reported: package.json: ```json { "devDependencies": { "t...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~18-~18: Loose punctuation mark.
Context: ..."type-fest": "*" } } **`foo.ts`**:ts import type { SetRequired } from ...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ 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). (24)
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test Node.js API
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_html_parser)
  • GitHub Check: Bench (biome_html_formatter)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: autofix
🔇 Additional comments (2)
crates/biome_js_analyze/tests/specs/correctness/noUndeclaredDependencies/valid.ts (1)

39-40: Fixture import looks good.

Covers a regular declared dependency case alongside the new type-only case. No concerns.

crates/biome_js_analyze/tests/specs/correctness/noUndeclaredDependencies/valid.package.json (1)

13-14: Dev dependency addition is appropriate.

Adding "type-fest" under devDependencies matches the new rule semantics and the test.

Comment on lines +118 to 121
let is_dev_dependency_available =
// Type-only imports are always considered as dev dependencies.
is_type_import(node) || ctx.options().dev_dependencies.is_available(path);
let is_peer_dependency_available = ctx.options().peer_dependencies.is_available(path);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Confirm intended semantics; consider tests for devDependencies: false.

is_dev_dependency_available becomes true for type-only imports unconditionally. This means type-only imports are allowed in files where devDependencies would otherwise be disallowed by options/globs. If intentional, add explicit tests to lock this in; if not, we should gate by options.

I can help add tests covering:

  • devDependencies: false (global) with import type — should be allowed if declared in dev deps.
  • Glob-restricted availability where file does not match the glob — still allowed for import type.

Run this to check if such tests already exist:


🏁 Script executed:

#!/bin/bash
# Find tests/options referencing noUndeclaredDependencies + devDependencies
rg -n 'noUndeclaredDependencies' -A 40 crates/ | rg -n '"devDependencies":'

Length of output: 504


Add missing test for import type when devDependencies are disabled
We have specs for "devDependencies": false, but none exercise a type-only import. Since is_type_import(...) currently bypasses the dev-deps check unconditionally, please add a test in
crates/biome_js_analyze/tests/specs/correctness/noUndeclaredDependencies that covers:

• Valid: with "devDependencies": false, a file containing

import type { Foo } from 'dev-only-module';

is allowed.
• (Optionally) A glob-restricted devDependency case still permitting import type.

If this behaviour isn’t intended, gate the is_type_import branch behind the devDependencies option instead.

🤖 Prompt for AI Agents
In crates/biome_js_analyze/src/lint/correctness/no_undeclared_dependencies.rs
around lines 118 to 121, the code currently allows type-only imports to bypass
the devDependencies check unconditionally. To fix this, add a test in
crates/biome_js_analyze/tests/specs/correctness/noUndeclaredDependencies that
verifies with "devDependencies": false, a file importing type-only from a
dev-only module is allowed. Optionally, add a test for glob-restricted
devDependencies allowing type-only imports. If this behavior is unintended,
modify the code to check the devDependencies option before allowing type-only
imports.

Copy link

codspeed-hq bot commented Aug 10, 2025

CodSpeed Performance Report

Merging #7171 will improve performances by 7.26%

Comparing siketyan:fix/GH-7162 (0ae5ff0) with main (52f8ebc)

Summary

⚡ 1 improvements
✅ 127 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
db_17847247775464589309.json[uncached] 14.7 ms 13.7 ms +7.26%

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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 (1)
.changeset/two-badgers-cut.md (1)

5-5: Tighten phrasing and drop redundant colons for readability.

Minor wordsmithing and formatting nits to make it crisper and also satisfy picky linters complaining about “loose punctuation”.

-Fixed [#7162](https://github.com/biomejs/biome/issues/7162): The `noUndeclaredDependencies` rule now considers a type-only import as a dev dependency.
+Fixed [#7162](https://github.com/biomejs/biome/issues/7162): The `noUndeclaredDependencies` rule now treats type-only imports as dev dependencies.

-**`package.json`**:
+**`package.json`**

-**`foo.ts`**:
+**`foo.ts`**

-Note that you still need to declare the package in the `devDependencies` section in `package.json`.
+You still need to declare the package under `devDependencies` in `package.json`.

Also applies to: 9-9, 18-18, 23-23

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7fdcae8 and 0ae5ff0.

📒 Files selected for processing (1)
  • .changeset/two-badgers-cut.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
.changeset/two-badgers-cut.md

[uncategorized] ~9-~9: Loose punctuation mark.
Context: ... no longer reported: package.json: ```json { "devDependencies": { "t...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~18-~18: Loose punctuation mark.
Context: ..."type-fest": "*" } } **`foo.ts`**:ts import type { SetRequired } from ...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ 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). (24)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Documentation
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_html_formatter)
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_html_parser)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Check Dependencies
  • GitHub Check: autofix
  • GitHub Check: Test Node.js API
🔇 Additional comments (1)
.changeset/two-badgers-cut.md (1)

1-24: Clear and helpful changeset.

Nice, link is correct and the example is spot on. Reads well.

@ematipico ematipico merged commit 5241690 into biomejs:main Aug 13, 2025
30 checks passed
@github-actions github-actions bot mentioned this pull request Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 noUndeclaredDependencies should ignore type-only imports

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载