refactor: replace for-in loops with Object.entries and enable guard-for-in - #90
Conversation
@standard-server/aws-lambda
@standard-server/core
@standard-server/fastify
@standard-server/fetch
@standard-server/node
@standard-server/peer
@standard-server/shared
commit: |
…ith `Object.entries` and enable `guard-for-in` Turn on ESLint's `guard-for-in` rule so any future `for...in` loop must filter out inherited properties. Rather than adding `Object.hasOwn` guards to the existing loops, rewrite them over `Object.entries` (or `Object.values` where only the value is read), which iterates own enumerable properties only and drops the separate value lookup. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JkQExPkUtiRfuLoFyXpqGD
1c8326d to
624382e
Compare
Object.entries and enable guard-for-in
Object.entries and enable guard-for-inObject.entries and enable guard-for-in
Merging this PR will not alter performance
Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — full PR (#90), all 7 files and the single commit 1c8326d.
eslint.config.js— enablesguard-for-inaserror;pnpm lintis clean, and a repo-wide grep confirms nofor...inloops remain, so the rule cannot trip CI on existing code.packages/aws-lambda/src/headers.ts—toStandardHeaders(2),getEventHeader(2), andtoLambdaHeaders(1) switch toObject.entriesdestructuring.packages/aws-lambda/src/url.ts—toStandardUrl's two loops destructure[key, values], dropping the repeated index lookup.packages/core/src/utils.ts—mergeStandardHeaderspullsbValuestraight from the entries tuple;Object.hasOwnstill gates inherited keys.packages/fastify/src/response.ts/packages/node/src/response.ts— response header loops converted,undefinedfiltering unchanged.packages/shared/src/object.ts—hasAnyDefinedValueusesObject.values, matching the JSDoc ("own property with a defined value").
The refactor is behaviorally neutral for the objects these paths actually see (plain literals, JSON.parse results, and null-prototype Object.create(null) maps). The one real semantic shift — inherited enumerable properties are no longer visited — is the PR's stated goal and, given the Object.hasOwn guard in mergeStandardHeaders and the own-property intent of hasAnyDefinedValue, is a strict improvement. Verified locally: pnpm lint passes and the 324 tests in aws-lambda/core/shared/node/fastify pass.
DeepSeek Flash (default — pick a model for stronger reviews) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — new head 624382e since the prior review.
The diff for 624382e is byte-for-byte identical to 1c8326d (verified by comparing the two formatted diffs); the only change is the commit subject. No new code to review — the prior approval stands.
DeepSeek Flash (default — pick a model for stronger reviews) | 𝕏

Summary
Refactored all
for-inloops throughout the codebase to useObject.entries()for more explicit and safer object iteration. This change improves code clarity and enables stricter linting rules.Key Changes
for-inloops toObject.entries()when iterating over headers and multiValueHeadersfor-inloops toObject.entries()when iterating over query parametershasAnyDefinedValue()to useObject.values()instead offor-inwith key lookupfor-inloop inmergeStandardHeaders()toObject.entries(), eliminating redundant variable assignmentfor-inloop toObject.entries()when setting response headersfor-inloop toObject.entries()when setting response headersguard-for-inESLint rule to prevent futurefor-inusage without explicit checksImplementation Details
for (const [key, value] of Object.entries(...))makes variable sources explicithttps://claude.ai/code/session_01JkQExPkUtiRfuLoFyXpqGD