Uh oh!
There was an error while loading. Please reload this page.
Prevent unsafe try/catch autofix suggestions for VariableDeclaration in fetch-body and JSON.parse rules - #51017
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
PR TriageCategory: bug (lint rule refinement) · Risk: low · Score: 42/100 (impact 15, urgency 10, quality 17) Recommendation: Draft PR narrowing autofix scope for two ESLint rules to avoid unsafe try/catch suggestions. No CI run yet (draft). No reviews posted yet. Small, isolated diff (4 files).
|
There was a problem hiding this comment.
Pull request overview
Adds scope-aware suggestion guards while preserving diagnostics.
Changes:
- Suppresses unsafe wrapping when declared bindings are used later.
- Adds regression tests for both ESLint rules.
Show a summary per file
| File | Description |
|---|---|
require-json-parse-try-catch.ts | Adds suggestion safety gate. |
require-json-parse-try-catch.test.ts | Tests later variable usage. |
require-fetch-response-body-try-catch.ts | Adds equivalent safety gate. |
require-fetch-response-body-try-catch.test.ts | Tests fetch-body scope safety. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Balanced
| if (stmt.type !== AST_NODE_TYPES.VariableDeclaration || stmt.kind === "var") { | ||
| return true; |
There was a problem hiding this comment.
Fixed in d64588a. Suggestions are now suppressed for VariableDeclaration nodes unless they are standalone statement-list entries (Program/BlockStatement/SwitchCase), so export const ... and for (...) declaration contexts no longer receive wrap suggestions.
| if (stmt.type !== AST_NODE_TYPES.VariableDeclaration || stmt.kind === "var") { | ||
| return true; |
There was a problem hiding this comment.
Fixed in d64588a. Added the same standalone-statement guard to this rule, so suggestions are withheld for export const ... and for-header VariableDeclaration contexts where replacing with a TryStatement would be invalid.
gh-aw-bot
commented
Aug 7, 2026
@copilot Please triage this PR, refresh the branch if possible, and run the Branch refresh is requested if GitHub can update it cleanly. Run context: https://github.com/github/gh-aw/actions/runs/31183485569
|
pelikhan
commented
Aug 7, 2026
/matt |
…tions Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /codebase-design and /diagnosing-bugs — approving with minor suggestions.
📋 Key Themes & Highlights
Key Themes
- Code duplication:
canSuggestWrapStatementis identical in both rule files; a shared utility would prevent the two implementations drifting. - Range-check edge case: The write-reference for the declaring identifier sits inside the statement range, so it won't false-positive — but worth an explicit test to document that invariant.
Positive Highlights
- ✅ Correct diagnosis: wrapping a
const/letin atryblock strands the binding — the fix targets the right abstraction level. - ✅
varcarved out correctly (function-scoped, so wrapping is safe). - ✅ Regression tests added for both rules with the exact motivating code pattern.
- ✅ Diagnostic is preserved; only the suggestion is suppressed — great UX decision.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 21.3 AIC · ⊞ 7.1K
Comment /matt to run again
Completed triage and pr-finisher pass. Addressed the open review feedback in d64588a, validated locally (fmt/lint/test-unit/test/recompile), and branch is already up to date with main. |
🎉 This pull request is included in a new release. Release: |
Both
require-fetch-response-body-try-catchandrequire-json-parse-try-catchcould suggest wrapping aconst/letdeclaration intry/catch, which can move the binding into block scope and break later references. This change keeps diagnostics intact while making suggestions scope-safe.Suggestion safety gate for
VariableDeclarationVariableDeclarationwrappable statements is unchanged.Rule parity across both implementations
require-fetch-response-body-try-catchrequire-json-parse-try-catchRegression coverage for scope-stranding case
@copilotPlease triage this PR, refresh the branch if possible, and run thepr-finisherskill before handing back to maintainers.Branch refresh is requested if GitHub can update it cleanly.
Run context: https://github.com/github/gh-aw/actions/runs/31183485569> Generated by 👨🍳 PR Sous Chef · gpt54 · 11.6 AIC · ⊞ 5.9K · ◷