Skip to content

fix(grit): match namespace and multi-specifier import patterns#9667

Closed
raashish1601 wants to merge 1 commit intobiomejs:mainfrom
raashish1601:contributor-32/fix-import-patterns-7727
Closed

fix(grit): match namespace and multi-specifier import patterns#9667
raashish1601 wants to merge 1 commit intobiomejs:mainfrom
raashish1601:contributor-32/fix-import-patterns-7727

Conversation

@raashish1601
Copy link
Copy Markdown

Summary

Testing

  • git diff --check
  • Unable to run cargo test -p biome_grit_patterns ... in this environment because the drive only had about 0.8 GB free and rustc/link failed with os error 112 while creating target/debug

Fixes #7727.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 29, 2026

🦋 Changeset detected

Latest commit: 96dcbe0

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

@github-actions github-actions Bot added the L-Grit Language: GritQL label Mar 29, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 29, 2026

Walkthrough

This PR fixes GritQL pattern matching for import statements to align with grit apply behaviour. The fix extends the pattern matching logic to handle namespace imports (import * as c from "foo"), multiple named imports, and mixed type imports. Changes include updating GritCodeSnippet to safely clone and conditionally commit state across multiple pattern iterations, extending import-kind compatibility logic to support JS_IMPORT_NAMESPACE_CLAUSE interactions, adding slot remapping for namespace transformations, and expanding test coverage with various import syntaxes.

Possibly related PRs

Suggested labels

L-Grit, A-Tooling

Suggested reviewers

  • dyc3
  • ematipico
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the primary fix: extending GritQL pattern matching to handle namespace imports and multi-specifier imports.
Description check ✅ Passed The description directly relates to the changeset, outlining the three main changes and noting testing limitations due to disk space constraints.
Linked Issues check ✅ Passed The code changes successfully address all requirements from issue #7727: namespace imports and multi-specifier named imports are now matched by GritQL patterns.
Out of Scope Changes check ✅ Passed All changes are tightly scoped to the stated objectives: import pattern matching logic updates, test fixture expansion, and a changeset entry.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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.

🧹 Nitpick comments (1)
crates/biome_grit_patterns/tests/specs/ts/import_patterns.ts (1)

1-18: Please pin the $import binding as well.

crates/biome_grit_patterns/tests/specs/ts/import_patterns.grit:1 binds $import, but the current snapshot in crates/biome_grit_patterns/tests/specs/ts/import_patterns.snap:1-18 only checks whole-statement matched_ranges. With the new slot remapping in crates/biome_grit_patterns/src/grit_node_patterns.rs, this can still pass if namespace or multi-specifier imports bind the wrong subtree. A tiny rewrite/capture snapshot here would lock down the actual fix.

Based on learnings: "All code changes MUST include appropriate tests: lint rules require snapshot tests in 'tests/specs/{group}/{rule}/', formatters require snapshot tests with valid/invalid cases, parsers require test files covering valid and error cases, and bug fixes require tests that reproduce and validate the fix."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_grit_patterns/tests/specs/ts/import_patterns.ts` around lines 1
- 18, Update the test to also pin the $import binding and assert its matched
subtree so the snapshot validates the specific import node (not just
whole-statement matched_ranges): modify the pattern in
crates/biome_grit_patterns/tests/specs/ts/import_patterns.grit to capture
$import for each import variant, then update
crates/biome_grit_patterns/tests/specs/ts/import_patterns.snap to include the
captured $import matched_range(s) (or a small rewrite/capture snapshot showing
the $import subtree) so the new slot remapping in
crates/biome_grit_patterns/src/grit_node_patterns.rs is exercised and locked
down.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/biome_grit_patterns/tests/specs/ts/import_patterns.ts`:
- Around line 1-18: Update the test to also pin the $import binding and assert
its matched subtree so the snapshot validates the specific import node (not just
whole-statement matched_ranges): modify the pattern in
crates/biome_grit_patterns/tests/specs/ts/import_patterns.grit to capture
$import for each import variant, then update
crates/biome_grit_patterns/tests/specs/ts/import_patterns.snap to include the
captured $import matched_range(s) (or a small rewrite/capture snapshot showing
the $import subtree) so the new slot remapping in
crates/biome_grit_patterns/src/grit_node_patterns.rs is exercised and locked
down.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bef6a934-cc58-43bb-8243-8ff58a0c7b72

📥 Commits

Reviewing files that changed from the base of the PR and between c17e08e and 96dcbe0.

⛔ Files ignored due to path filters (1)
  • crates/biome_grit_patterns/tests/specs/ts/import_patterns.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (4)
  • .changeset/odd-cycles-match.md
  • crates/biome_grit_patterns/src/grit_code_snippet.rs
  • crates/biome_grit_patterns/src/grit_node_patterns.rs
  • crates/biome_grit_patterns/tests/specs/ts/import_patterns.ts

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 29, 2026

Merging this PR will degrade performance by 43.54%

❌ 6 regressed benchmarks
✅ 3 untouched benchmarks
⏩ 219 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
execute[or_pattern] 3.4 ms 4.6 ms -26.69%
execute[where_clause] 2.5 ms 3.2 ms -21.55%
execute_optimized[or_pattern] 585.1 µs 1,036.3 µs -43.54%
execute_optimized[code_snippet] 452.5 µs 800.1 µs -43.45%
execute_optimized[where_clause] 453.4 µs 763.1 µs -40.59%
execute[code_snippet] 2.1 ms 2.8 ms -25.28%

Comparing raashish1601:contributor-32/fix-import-patterns-7727 (96dcbe0) with main (c17e08e)2

Open in CodSpeed

Footnotes

  1. 219 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.

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

@Conaclos Conaclos added the M-Likely Agent Meta: this was likely an automated PR without a human in the loop label Mar 29, 2026
@ematipico ematipico closed this Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L-Grit Language: GritQL M-Likely Agent Meta: this was likely an automated PR without a human in the loop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 gritql patterns for import don't match all kinds of import statements

3 participants