-
-
Notifications
You must be signed in to change notification settings - Fork 724
fix(lint): extend matcher for GritCodeSnippet to cover edge case #7786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 3f20c4e The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
crates/biome_grit_patterns/tests/specs/ts/matchBacktickSnippet.snap
Outdated
Show resolved
Hide resolved
WalkthroughAdds Grit test snippets and corresponding TypeScript test lines that exercise matching of function-call shapes for backtick-delimited and string-literal patterns targeting Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ 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). (2)
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. Comment |
There was a problem hiding this 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_grit_patterns/src/pattern_compiler/snippet_compiler.rs (1)
497-515
: Good snapshot test; consider adding the call-form too.This nicely pins the CST for the identifier case. For extra confidence around the reported edge, add a sibling test for
buildConfig()
to cover the call-expression path here as well (you already have TS specs, but a unit keeps it close to the compiler).crates/biome_grit_patterns/src/grit_code_snippet.rs (1)
45-75
: Apply the suggested optimisations to avoid double-executing patterns and trim the O(n) traversal.The review is spot-on. The code does execute the exact-kind pattern twice (once in fast-path, again in the second loop if unsuccessful), and
node.children().count() == 1
is unnecessarily expensive. The narrowing of the single-child unwrap to only kinds that appear inself.patterns
is also a worthwhile safety improvement—currently it could attempt matching against any wrapper, but the suggested approach keeps it focused.Tests exist (matchBacktickSnippet and matchStringLiteral) to help validate your changes. Apply the suggested diff and run
cargo test -p biome_grit_patterns
locally to confirm nothing regresses.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
crates/biome_grit_patterns/tests/specs/ts/matchBacktickSnippet.snap
is excluded by!**/*.snap
and included by**
📒 Files selected for processing (2)
crates/biome_grit_patterns/src/grit_code_snippet.rs
(2 hunks)crates/biome_grit_patterns/src/pattern_compiler/snippet_compiler.rs
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
crates/biome_*/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place core crates under /crates/biome_*/
Files:
crates/biome_grit_patterns/src/pattern_compiler/snippet_compiler.rs
crates/biome_grit_patterns/src/grit_code_snippet.rs
**/*.rs
📄 CodeRabbit inference engine (CONTRIBUTING.md)
**/*.rs
: Format Rust files before committing (e.g., viajust f
which formats Rust)
Document rules, assists, and options with inline rustdoc in source
Files:
crates/biome_grit_patterns/src/pattern_compiler/snippet_compiler.rs
crates/biome_grit_patterns/src/grit_code_snippet.rs
🧬 Code graph analysis (2)
crates/biome_grit_patterns/src/pattern_compiler/snippet_compiler.rs (2)
crates/biome_grit_patterns/src/grit_node.rs (1)
node
(207-209)crates/biome_grit_patterns/src/grit_target_node.rs (1)
node
(639-641)
crates/biome_grit_patterns/src/grit_code_snippet.rs (1)
crates/biome_grit_patterns/src/pattern_compiler/snippet_compiler.rs (1)
node
(258-261)
⏰ 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). (3)
- GitHub Check: Check Dependencies
- GitHub Check: autofix
- GitHub Check: Test Node.js API
🔇 Additional comments (1)
crates/biome_grit_patterns/src/grit_code_snippet.rs (1)
10-10
: Remove unusedAstNode
import on line 10.The code doesn't use
AstNode
—methods likefirst_child()
andchildren()
are concrete implementations onGritTargetNode
, not trait methods. Drop the import to keep things tidy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
crates/biome_grit_patterns/src/grit_code_snippet.rs (2)
52-59
: Consider avoiding redundant pattern execution.When the exact-kind pattern exists but fails to execute on line 47, this loop will re-try the same pattern. Whilst not incorrect, it's wasteful.
Consider either:
- Tracking which pattern was already attempted and skipping it here, or
- Restructuring to avoid the redundancy
64-71
: Optimise the single-child check.The condition
node.children().count() == 1
iterates through all children, which is inefficient. Since you already havefirst_child()
, check whether a second child exists instead.Apply this diff to improve performance:
- if let Some(child) = node.first_child() && node.children().count() == 1 { + if let Some(child) = node.first_child() && node.children().nth(1).is_none() { let child_binding = GritResolvedPattern::from_node_binding(child); for (_, pattern) in &self.patterns { if pattern.execute(&child_binding, state, context, logs)? {
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/biome_grit_patterns/src/grit_code_snippet.rs
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
crates/biome_*/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place core crates under /crates/biome_*/
Files:
crates/biome_grit_patterns/src/grit_code_snippet.rs
**/*.rs
📄 CodeRabbit inference engine (CONTRIBUTING.md)
**/*.rs
: Format Rust files before committing (e.g., viajust f
which formats Rust)
Document rules, assists, and options with inline rustdoc in source
Files:
crates/biome_grit_patterns/src/grit_code_snippet.rs
🧬 Code graph analysis (1)
crates/biome_grit_patterns/src/grit_code_snippet.rs (1)
crates/biome_grit_patterns/src/pattern_compiler/snippet_compiler.rs (1)
node
(258-261)
🪛 GitHub Actions: autofix.ci
crates/biome_grit_patterns/src/grit_code_snippet.rs
[error] 75-75: Build failed due to syntax error: unexpected closing delimiter '}' (this delimiter might not be properly closed...).
🪛 GitHub Actions: Pull request Node.js
crates/biome_grit_patterns/src/grit_code_snippet.rs
[error] 75-75: unexpected closing delimiter: }
[error] 75-75: This error prevents building the crate. Could be caused by a mismatched or missing opening/closing delimiter in the surrounding code.
⏰ 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). (2)
- GitHub Check: Test (depot-windows-2022-16)
- GitHub Check: Lint project (depot-windows-2022)
🔇 Additional comments (1)
crates/biome_grit_patterns/src/grit_code_snippet.rs (1)
10-10
: Import addition looks good.The
AstNode
import is necessary for the new child-node unwrapping logic below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/biome_grit_patterns/src/grit_code_snippet.rs (1)
53-65
: Wrapper-node handling correctly addresses the reported issue.The logic properly unwraps single-child
JS_IDENTIFIER_EXPRESSION
nodes to match against the innerJS_REFERENCE_IDENTIFIER
, which aligns with the fix objective.Optional micro-optimisation: Line 57's
node.children().count() == 1
iterates all children. Since you've already gotfirst_child()
in hand, you could checkchild.next_sibling().is_none()
instead—but the current approach is perfectly clear and unlikely to be a bottleneck.- if node.kind() == GritTargetSyntaxKind::JsSyntaxKind(JsSyntaxKind::JS_IDENTIFIER_EXPRESSION) - && let Some(child) = node.first_child() - && node.children().count() == 1 + if node.kind() == GritTargetSyntaxKind::JsSyntaxKind(JsSyntaxKind::JS_IDENTIFIER_EXPRESSION) + && let Some(child) = node.first_child() + && child.next_sibling().is_none()
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.changeset/ripe-rabbits-build.md
(1 hunks)crates/biome_grit_patterns/src/grit_code_snippet.rs
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
crates/biome_*/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place core crates under /crates/biome_*/
Files:
crates/biome_grit_patterns/src/grit_code_snippet.rs
**/*.rs
📄 CodeRabbit inference engine (CONTRIBUTING.md)
**/*.rs
: Format Rust files before committing (e.g., viajust f
which formats Rust)
Document rules, assists, and options with inline rustdoc in source
Files:
crates/biome_grit_patterns/src/grit_code_snippet.rs
.changeset/*.md
📄 CodeRabbit inference engine (CONTRIBUTING.md)
.changeset/*.md
: In changesets, only use #### or ##### headers; other header levels are not allowed
Changesets should cover user-facing changes only; internal changes do not need changesets
Use past tense for what you did and present tense for current Biome behavior in changesets
When fixing a bug in a changeset, start with an issue link (e.g., “Fixed #1234: …”)
When referencing a rule or assist in a changeset, include a link to its page on the website
Include code blocks in changesets when applicable to illustrate changes
End every sentence in a changeset with a period
Files:
.changeset/ripe-rabbits-build.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 Node.js API
- GitHub Check: Check Dependencies
- GitHub Check: Test (depot-ubuntu-24.04-arm-16)
- GitHub Check: Test (depot-windows-2022-16)
- GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
- GitHub Check: Lint project (depot-windows-2022)
- GitHub Check: End-to-end tests
- GitHub Check: autofix
- GitHub Check: lint
🔇 Additional comments (3)
crates/biome_grit_patterns/src/grit_code_snippet.rs (3)
4-4
: LGTM – imports support the new functionality.The additions of
JsSyntaxKind
andAstNode
are necessary for the kind check and node traversal in the wrapper-handling logic.Also applies to: 11-11
46-51
: Fast-path optimisation looks good.The exact-kind matching with early return is a sensible optimisation. The
if let
pattern with&&
chaining is clean and idiomatic.
67-67
: Correct fallback behaviour.Returning
Ok(false)
when neither the fast-path nor wrapper handling succeeds is the expected fallback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.changeset/ripe-rabbits-build.md
(1 hunks)crates/biome_grit_patterns/src/grit_code_snippet.rs
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
.changeset/*.md
📄 CodeRabbit inference engine (CONTRIBUTING.md)
.changeset/*.md
: In changesets, only use #### or ##### headers; other header levels are not allowed
Changesets should cover user-facing changes only; internal changes do not need changesets
Use past tense for what you did and present tense for current Biome behavior in changesets
When fixing a bug in a changeset, start with an issue link (e.g., “Fixed #1234: …”)
When referencing a rule or assist in a changeset, include a link to its page on the website
Include code blocks in changesets when applicable to illustrate changes
End every sentence in a changeset with a period
Files:
.changeset/ripe-rabbits-build.md
crates/biome_*/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place core crates under /crates/biome_*/
Files:
crates/biome_grit_patterns/src/grit_code_snippet.rs
**/*.rs
📄 CodeRabbit inference engine (CONTRIBUTING.md)
**/*.rs
: Format Rust files before committing (e.g., viajust f
which formats Rust)
Document rules, assists, and options with inline rustdoc in source
Files:
crates/biome_grit_patterns/src/grit_code_snippet.rs
🧬 Code graph analysis (1)
crates/biome_grit_patterns/src/grit_code_snippet.rs (1)
crates/biome_grit_patterns/src/pattern_compiler/snippet_compiler.rs (1)
node
(258-261)
⏰ 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). (8)
- GitHub Check: Test Node.js API
- GitHub Check: Documentation
- GitHub Check: Test (depot-windows-2022-16)
- GitHub Check: Test (depot-ubuntu-24.04-arm-16)
- GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
- GitHub Check: Check Dependencies
- GitHub Check: Lint project (depot-windows-2022)
- GitHub Check: autofix
🔇 Additional comments (4)
crates/biome_grit_patterns/src/grit_code_snippet.rs (4)
4-4
: Imports look correct.Both
JsSyntaxKind
(used at line 55) andAstNode
(providesfirst_child
/next_sibling
methods used at lines 56-57) are necessary for the new logic.Also applies to: 11-11
46-51
: Fast path optimisation is sound.Checking exact kind match first and returning early on success is a sensible performance improvement.
53-65
: Wrapper-node handling correctly addresses the issue.The logic properly checks for a single-child
JS_IDENTIFIER_EXPRESSION
, unwraps to the child, and attempts matching across all patterns. This directly fixes thebuildConfig()
detection issue described in #7601.
67-67
: Fallback behaviour is correct.Returning
false
when neither fast path nor wrapper match succeeds maintains the expected default behaviour.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
For
$fn($args)
is compiled into aGritNodePattern
with kindJS_CALL_EXPRESSION
.$fn
binds to aJS_IDENTIFIER_EXPRESSION
node.`buildConfig` creates GritCodeSnippet with these patterns
Given CST for
buildConfig()
isThe node kind of
buildConfig
isJS_IDENTIFIER_EXPRESSION
which is not part of the available patterns.My fix is just making
GritCodeSnippet
's matcher more flexible by detecting whenJS_IDENTIFIER_EXPRESSION
has a single child and unwraps toJS_REFERENCE_IDENTIFIER
.I'm not pleased with the fix. Without the fix, there are other workarounds
There could be more principled approach. With on-going effort in js plugin, I'm not sure if it's worth diving into that now.
Fixes: #7601