refactor: enable guard-for-in ESLint rule - #15
Merged
Merged
Conversation
Enable the core `guard-for-in` rule and add a `ForInStatement` selector to `no-restricted-syntax` so that iterating over an object steers contributors toward `Object.keys()`, `Object.entries()`, or `Object.values()` instead of `for...in`. The antfu preset already configures `no-restricted-syntax` with its own selectors; overriding a rule replaces its options, so those selectors are carried over explicitly to keep the existing restrictions intact. No source changes were needed: the codebase already iterates objects via `Object.keys()`/`Object.entries()` and contains no `for...in` loops. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HgmAA3VgHHTxew3CjB6KSM
Remove the `no-restricted-syntax` override that banned `for...in` outright. The preset's own `no-restricted-syntax` selectors apply again unchanged, and `guard-for-in` stays enabled so any `for...in` loop must filter its body. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HgmAA3VgHHTxew3CjB6KSM
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
- Enable
guard-for-in— adds'guard-for-in': 'error'to the firstantfu({...})rules block ineslint.config.js, requiringhasOwnProperty/Object.hasOwnguards (or index-style iteration) onfor...inloops.
I verified the rule was previously off — @antfu/eslint-config does not set it, and eslint --print-config now reports severity 2. No for...in loops exist in tracked source (all loops are for...of), and a repo-wide pnpm run lint passes at this head, so enabling the rule introduces no new violations.
DeepSeek Flash (default — pick a model for stronger reviews) | 𝕏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Enable the
guard-for-inESLint rule to enforce safer iteration over object properties.Changes
'guard-for-in': 'error'to the ESLint configuration to requirehasOwnProperty()checks when iterating over object properties withfor...inloopsDetails
The
guard-for-inrule helps prevent bugs by ensuring thatfor...inloops include a check to filter out inherited properties from the prototype chain. This is a best practice for object property iteration in JavaScript.https://claude.ai/code/session_01HgmAA3VgHHTxew3CjB6KSM