Skip to content

Conversation

patrickshipe
Copy link
Contributor

Summary

The useImportExtensions rule was incorrectly transforming import "./sub/index" to import "./sub/index/index.ts" - we shouldn't be adding an extra index to the path if the import is already explicitly referencing an index file.

Test Plan

Added testing for this scenario

Docs

Copy link

changeset-bot bot commented Aug 13, 2025

🦋 Changeset detected

Latest commit: 69058c5

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 13, 2025

Walkthrough

Added detection for import paths that end with a bare "index" (import_path_ends_with_index) and adjusted the rewrite logic so index resolution only rewrites to "index.{extension}" when the original path did not already explicitly end with "index". Paths that explicitly end with "index" are preserved (with any extension adjustments handled in the alternate branch). A test import "./sub/index" was added to invalid.ts to cover the case, and a changeset was included to patch @biomejs/biome for this behaviour correction.

Possibly related issues

Suggested reviewers

  • siketyan

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: .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 969429e and 23baeb8.

📒 Files selected for processing (1)
  • .changeset/petite-pans-fetch.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/petite-pans-fetch.md
⏰ 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: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: End-to-end tests
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Documentation
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Check Dependencies
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_html_parser)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_html_formatter)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Test Node.js API
  • GitHub Check: autofix
✨ 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.
  • 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 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 L-JavaScript Language: JavaScript and super languages labels Aug 13, 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 (2)
crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalid.ts (1)

3-3: Great addition; please also cover dynamic and CJS variants.

To fully exercise the fix, add:

  • import('./sub/index')
  • require('./sub/index')

These mirror the existing dynamic cases for './sub/foo' and ensure consistent behaviour across import forms.

crates/biome_js_analyze/src/lint/correctness/use_import_extensions.rs (1)

256-276: Simplify and harden index-path reconstruction.

The current split/next_back/fold approach is a bit brittle. Trimming known suffixes and appending once is simpler and avoids accidental double slashes.

Apply this diff to simplify the construction:

-        let mut path_parts = path.as_str().split('/');
-
-        // Remove trailing slash and useless path segment.
-        if module_path.ends_with('/') || module_path.ends_with("/.") {
-            path_parts.next_back();
-        }
-        if module_path.ends_with("/./") {
-            path_parts.next_back();
-        }
-
-        let mut new_path = path_parts.fold(String::new(), |mut result, part| {
-            result.push_str(part);
-            result.push('/');
-
-            result
-        });
-
-        new_path.push_str("index.");
-        new_path.push_str(extension);
-        new_path
+        // Remove trailing slash and trailing `/.` or `/./`, then append `/index.{ext}`
+        let base = path
+            .as_str()
+            .trim_end_matches('/')
+            .trim_end_matches("/.")
+            .trim_end_matches("/./");
+        let mut new_path = String::from(base);
+        if !new_path.ends_with('/') {
+            new_path.push('/');
+        }
+        new_path.push_str("index.");
+        new_path.push_str(extension);
+        new_path

This keeps behaviour identical for ./sub, ./sub/, ./sub/., and ./sub/./, but is easier to reason about.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between df6f35e and 20fbbee.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalid.ts.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (2)
  • crates/biome_js_analyze/src/lint/correctness/use_import_extensions.rs (1 hunks)
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalid.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
crates/biome_*/**/*

📄 CodeRabbit Inference Engine (CLAUDE.md)

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

Files:

  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalid.ts
  • crates/biome_js_analyze/src/lint/correctness/use_import_extensions.rs
**/*.{rs,toml}

📄 CodeRabbit Inference Engine (CLAUDE.md)

Format code (Rust + TOML) using just format

Format Rust and TOML files before committing (use just f/just format).

Files:

  • crates/biome_js_analyze/src/lint/correctness/use_import_extensions.rs
🔇 Additional comments (1)
crates/biome_js_analyze/src/lint/correctness/use_import_extensions.rs (1)

254-257: Correct guard to avoid duplicating “index”.

The import_path_ends_with_index check paired with is_index_file cleanly prevents rewriting ./sub/index into ./sub/index/index.{ext}. This aligns with the rule’s intent while preserving the existing behaviour for directory-like imports (e.g. ./sub/).

If you want to be doubly sure we didn’t regress directory cases, I can add tests for ./sub/index/ to confirm we still rewrite to ./sub/index/index.{ext} only when an actual directory index/ exists. Want me to open a follow-up?

Copy link

codspeed-hq bot commented Aug 13, 2025

CodSpeed Performance Report

Merging #7209 will not alter performance

Comparing patrickshipe:fix-import-ext-index (23baeb8) with main (8a8e2e6)

Summary

✅ 132 untouched benchmarks

Copy link
Contributor

@arendjr arendjr left a comment

Choose a reason for hiding this comment

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

Thank you!

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

@patrickshipe
Copy link
Contributor Author

Thank you @patrickshipe . Can you please commit a changeset? https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md#create-a-changeset

Done!

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/petite-pans-fetch.md (1)

5-6: Enhance the changeset per repo conventions (present behaviour, example, link).

Add a present-tense behaviour sentence, a small example, and a link to the PR. Optional: slightly crisper wording.

-Fixed an issue with the `useImportExtensions` rule that overcorrected explicit imports of index files.
+Resolved an overcorrection in the `useImportExtensions` rule when importing explicit index files.
+
+Imports that explicitly reference an index file are now preserved and no longer rewritten to nested index paths.
+
+#### Example
+```ts
+// Before (incorrect rewrite)
+// import "./sub/index" -> "./sub/index/index.ts"
+```
+```ts
+// Now
+import "./sub/index";
+```
+
+See PR: https://github.com/biomejs/biome/pull/7209.
📜 Review details

Configuration used: .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 20fbbee and 69058c5.

📒 Files selected for processing (1)
  • .changeset/petite-pans-fetch.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
.changeset/*.md

📄 CodeRabbit Inference Engine (CONTRIBUTING.md)

.changeset/*.md: Create changesets with just new-changeset; store them in .changeset/ with correct frontmatter (package keys and change type).
In changeset descriptions, follow content conventions: user-facing changes only; past tense for what you did; present tense for current behavior; link issues for fixes; link rules/assists; include representative code blocks; end every sentence with a period.
When adding headers in a changeset, only use #### or ##### levels.

Files:

  • .changeset/petite-pans-fetch.md
🪛 LanguageTool
.changeset/petite-pans-fetch.md

[style] ~4-~4: Consider using a different verb for a more formal wording.
Context: --- "@biomejs/biome": patch --- Fixed an issue with the useImportExtensions...

(FIX_RESOLVE)

🔇 Additional comments (1)
.changeset/petite-pans-fetch.md (1)

1-3: Frontmatter looks good.

Package and change type are correctly specified for a patch release.

@arendjr arendjr merged commit 679b70e into biomejs:main Aug 19, 2025
30 checks passed
@github-actions github-actions bot mentioned this pull request Aug 19, 2025
ematipico pushed a commit that referenced this pull request Aug 26, 2025
SkyBird233 pushed a commit to SkyBird233/biomejs that referenced this pull request Aug 28, 2025
SkyBird233 pushed a commit to SkyBird233/biomejs that referenced this pull request Aug 28, 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.

4 participants