Skip to content

feat(js/useImportExtensions): add extensionMappings option#7762

Merged
dyc3 merged 1 commit intonextfrom
dyc3/import-extentions-mappings
Nov 14, 2025
Merged

feat(js/useImportExtensions): add extensionMappings option#7762
dyc3 merged 1 commit intonextfrom
dyc3/import-extentions-mappings

Conversation

@dyc3
Copy link
Copy Markdown
Contributor

@dyc3 dyc3 commented Oct 15, 2025

Summary

Adds a new option to useImportExtensions to be a more precisely configurable version of forcejsextensions.

Open to suggestions for a better name for the option, I don't really like it but couldn't come up with anything else.

fixes #7734

Test Plan

added tests

Docs

updated the rule docs

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Oct 15, 2025

🦋 Changeset detected

Latest commit: 44c1024

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

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

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

@github-actions github-actions Bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Oct 15, 2025
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Oct 15, 2025

CodSpeed Performance Report

Merging #7762 will not alter performance

Comparing dyc3/import-extentions-mappings (44c1024) with next (7f5bcf4)

Summary

✅ 53 untouched
⏩ 85 skipped1

Footnotes

  1. 85 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Base automatically changed from next to main October 23, 2025 10:03
@dyc3 dyc3 force-pushed the dyc3/import-extentions-mappings branch from 4ff68cd to 47d3b66 Compare November 13, 2025 14:14
@dyc3 dyc3 changed the base branch from main to next November 13, 2025 14:14
@dyc3 dyc3 marked this pull request as ready for review November 13, 2025 14:15
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 13, 2025

Walkthrough

Adds an extensionMappings option to the useImportExtensions lint: a configurable map of source extensions to replacement extensions. Persists the new extension_mappings field in UseImportExtensionsOptions, updates extension-resolution in get_extensionless_import to consult the mapping (used when a resolved extension exists and forceJsExtensions is false), and adds tests exercising a "ts" -> "js" mapping.

Possibly related PRs

Suggested reviewers

  • arendjr
  • ematipico

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a new extensionMappings option to the useImportExtensions rule.
Description check ✅ Passed The description adequately explains the motivation (providing finer control over extension mappings), references the linked issue (#7734), mentions tests and documentation updates, and discusses the implementation.
Linked Issues check ✅ Passed The PR fully implements the objective from issue #7734: adds extensionMappings option to allow custom file extension mappings (e.g., .ts to .js), enabling targeted mapping without invalidating non-JS asset imports.
Out of Scope Changes check ✅ Passed All changes directly support the extensionMappings feature: option struct, rule implementation, test files, and configuration. No unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dyc3/import-extentions-mappings

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47d3b66 and 44c1024.

⛔ Files ignored due to path filters (5)
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/bar.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/foo.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalidWithExtensionMappings.ts.snap is excluded by !**/*.snap and included by **
  • packages/@biomejs/backend-jsonrpc/src/workspace.ts is excluded by !**/backend-jsonrpc/src/workspace.ts and included by **
  • packages/@biomejs/biome/configuration_schema.json is excluded by !**/configuration_schema.json and included by **
📒 Files selected for processing (7)
  • .changeset/six-plants-lie.md (1 hunks)
  • crates/biome_js_analyze/src/lint/correctness/use_import_extensions.rs (2 hunks)
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/bar.ts (1 hunks)
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/foo.ts (1 hunks)
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalidWithExtensionMappings.options.json (1 hunks)
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalidWithExtensionMappings.ts (1 hunks)
  • crates/biome_rule_options/src/use_import_extensions.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/bar.ts
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalidWithExtensionMappings.options.json
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/foo.ts
  • crates/biome_rule_options/src/use_import_extensions.rs
  • .changeset/six-plants-lie.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). (10)
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: autofix
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: End-to-end tests
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Check Dependencies
🔇 Additional comments (3)
crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalidWithExtensionMappings.ts (1)

1-2: Test coverage looks good.

The test appropriately exercises both extensionless imports and imports with explicit source extensions when extension mappings are configured.

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

80-104: Documentation is clear and addresses prior feedback.

The documentation clearly explains the new option and its fallback behaviour. The example is practical for the TypeScript bundling use case.

Based on learnings


286-295: Extension mapping logic is sound.

The precedence (forceJsExtensions → extensionMappings → resolved extension) is sensible and maintains backwards compatibility. The implementation correctly handles the fallback case when no mapping exists.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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)
.changeset/six-plants-lie.md (1)

1-17: LGTM!

The changelog clearly documents the new feature with a helpful example. The trailing comma on line 13 is valid JSON but you might consider removing it to avoid confusion.

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

285-289: Consider documenting option precedence.

The implementation correctly applies extension mappings. However, when both forceJsExtensions and extensionMappings are configured, forceJsExtensions takes precedence (line 283). Consider documenting this interaction in the rule documentation to avoid confusion.

For example, you could add a note in the extensionMappings section:

 /// map TypeScript imports to JavaScript extensions.
 ///
+/// Note: If `forceJsExtensions` is set to `true`, it takes precedence over
+/// `extensionMappings`.
+///
 /// This is useful if you are bundling your code to JavaScript into a package
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f5bcf4 and 47d3b66.

⛔ Files ignored due to path filters (5)
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/bar.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/foo.ts.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalidWithExtensionMappings.ts.snap is excluded by !**/*.snap and included by **
  • packages/@biomejs/backend-jsonrpc/src/workspace.ts is excluded by !**/backend-jsonrpc/src/workspace.ts and included by **
  • packages/@biomejs/biome/configuration_schema.json is excluded by !**/configuration_schema.json and included by **
📒 Files selected for processing (7)
  • .changeset/six-plants-lie.md (1 hunks)
  • crates/biome_js_analyze/src/lint/correctness/use_import_extensions.rs (2 hunks)
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/bar.ts (1 hunks)
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/foo.ts (1 hunks)
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalidWithExtensionMappings.options.json (1 hunks)
  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalidWithExtensionMappings.ts (1 hunks)
  • crates/biome_rule_options/src/use_import_extensions.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-05T14:43:29.581Z
Learnt from: dyc3
Repo: biomejs/biome PR: 7081
File: packages/@biomejs/biome/configuration_schema.json:7765-7781
Timestamp: 2025-08-05T14:43:29.581Z
Learning: The file `packages/biomejs/biome/configuration_schema.json` is auto-generated and should not be manually edited or reviewed for schema issues; any changes should be made at the code generation source.

Applied to files:

  • crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalidWithExtensionMappings.options.json
🔇 Additional comments (7)
crates/biome_rule_options/src/use_import_extensions.rs (2)

2-2: LGTM!

The FxHashMap import and serde attribute cleanup are appropriate.

Also applies to: 10-10


13-16: LGTM!

The new field is well-documented and properly configured.

crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalidWithExtensionMappings.ts (1)

1-2: LGTM!

The test cases appropriately exercise both scenarios: missing extension and incorrect extension with the mapping active.

crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/foo.ts (1)

1-1: LGTM!

Simple test fixture, looks good.

crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/bar.ts (1)

1-1: LGTM!

Simple test fixture, looks good.

crates/biome_js_analyze/tests/specs/correctness/useImportExtensions/invalidWithExtensionMappings.options.json (1)

1-18: LGTM!

The test configuration correctly sets up the extension mapping for testing.

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

80-101: LGTM!

The documentation for the new option is clear and helpful.

@dyc3 dyc3 requested review from a team November 13, 2025 17:12
@dyc3 dyc3 force-pushed the dyc3/import-extentions-mappings branch from a2fae21 to 44c1024 Compare November 14, 2025 14:21
@dyc3 dyc3 merged commit 5901d79 into next Nov 14, 2025
17 checks passed
@dyc3 dyc3 deleted the dyc3/import-extentions-mappings branch November 14, 2025 14:48
@github-actions github-actions Bot mentioned this pull request Feb 14, 2026
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.

💅 useImportExtensions with forcejsextensions: true invalidates .css, .vue, .svelte imports

3 participants