-
-
Notifications
You must be signed in to change notification settings - Fork 794
fix(noInvalidUseBeforeDeclaration): don't report use before ambient var declaration #8104
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
fix(noInvalidUseBeforeDeclaration): don't report use before ambient var declaration #8104
Conversation
🦋 Changeset detectedLatest commit: cbd209d 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 |
WalkthroughThe PR updates the noInvalidUseBeforeDeclaration lint: it skips TypeScript declaration files by checking Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
6f3c4c2 to
fe1f34b
Compare
CodSpeed Performance ReportMerging #8104 will not alter performanceComparing Summary
Footnotes
|
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 (1)
crates/biome_js_analyze/src/lint/correctness/no_invalid_use_before_declaration.rs (1)
223-225: Optional: Simplify by adding to the pattern list above.The block wrapper is unnecessary—you could just append this variant to the
|pattern chain at lines 219–222.Apply this diff to simplify:
AnyJsBindingDeclaration::JsArrayBindingPatternElement(_) | AnyJsBindingDeclaration::JsArrayBindingPatternRestElement(_) | AnyJsBindingDeclaration::JsObjectBindingPatternProperty(_) | AnyJsBindingDeclaration::JsObjectBindingPatternRest(_) -| AnyJsBindingDeclaration::JsObjectBindingPatternShorthandProperty(_) => { - Ok(Self::Variable) -} +| AnyJsBindingDeclaration::JsObjectBindingPatternShorthandProperty(_) -AnyJsBindingDeclaration::JsVariableDeclarator(declarator) => { +| AnyJsBindingDeclaration::JsVariableDeclarator(declarator) => { if let Some(var_decl) = declarator.declaration()
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/biome_js_analyze/src/lint/correctness/no_invalid_use_before_declaration.rs(3 hunks)
⏰ 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). (13)
- GitHub Check: Bench (biome_js_analyze)
- GitHub Check: Bench (biome_js_formatter)
- GitHub Check: Bench (biome_js_parser)
- GitHub Check: Check Dependencies
- GitHub Check: Lint project (depot-windows-2022)
- GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
- GitHub Check: Test (depot-windows-2022-16)
- GitHub Check: Documentation
- GitHub Check: Test (depot-ubuntu-24.04-arm-16)
- GitHub Check: End-to-end tests
- GitHub Check: Validate rules documentation
- GitHub Check: autofix
- GitHub Check: Test Node.js API
🔇 Additional comments (3)
crates/biome_js_analyze/src/lint/correctness/no_invalid_use_before_declaration.rs (3)
6-7: LGTM! Required imports for the fix.The new imports support the declaration file check and ambient declaration detection.
85-91: Good optimisation! Skipping declaration files entirely.Declaration files (
.d.ts) only contain ambient declarations, so this early exit is both correct and efficient.
226-237: Excellent fix! Ambient declarations are now correctly excluded.The parent-chain check properly identifies
declarevariables, which are hoisted and can be used before their declaration point. ReturningErr(())ensures they skip validation at line 105.
Summary
This is a small fix of an issue I met on a personal project.
Basically
noInvalidUseBeforeDeclarationreported the following code as invalid:While it is valid because
cis an ambient variable that is hoisted.Test Plan
I added a test.
Docs
I added a changeset.