refactor(validate): drop always-true if (validate.body) guard in body proxy#1392
Conversation
…dy proxy `validatedRequest` returns the unwrapped request when `validate.body` is unset, so the lazy body-validation Proxy is only ever created when `validate.body` is truthy. The Proxy's `get` handler then re-checked `if (validate.body)` — a guard that is always true at that point — adding a dead branch and a nesting level. Remove it (behaviour-preserving; the existing `validate.body!` assertion already assumed non-null) and note the invariant in a comment. All 38 validate tests pass; tsc, oxlint, and oxfmt clean.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe proxy ChangesRequest body validation proxy
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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 |
What
Removes an always-true
if (validate.body)guard inside the lazy body-validationProxycreated byvalidatedRequest, flattening one level of nesting and a deadbranch.
Why it's safe / why the guard is redundant
validatedRequestreturns the unwrapped request whenvalidate.bodyis unset:So by the time the
Proxy'sgethandler runs,validate.bodyis always truthy— the inner
if (validate.body)can never be false. The handler already relies onthis (it uses the non-null assertion
validate.body!inside). Removing the guardis behaviour-preserving and lets the body-prop checks sit one level shallower.
Why a reviewer might not have caught it
The redundant guard reads as ordinary defensiveness; it's only visible as dead once
you trace that the enclosing function early-returns for the
!validate.bodycase,so the proxy is conditionally constructed.
Scope
Internal helper only — no public API, signature, or behaviour change. All 38
validatetests pass;tsc --noEmit,oxlint, andoxfmtare clean.Summary by CodeRabbit
Release Notes
Bug Fixes
.json()method for accessing request bodies.Performance