Skip to content

refactor: enable guard-for-in ESLint rule - #15

Merged
dinwwwh merged 2 commits into
mainfrom
claude/eslint-guard-for-in-v4uak7
Sep 15, 2026
Merged

dinwwwh merged 2 commits into
mainfrom
claude/eslint-guard-for-in-v4uak7

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Sep 15, 2026

Copy link
Copy Markdown
Member

Summary

Enable the guard-for-in ESLint rule to enforce safer iteration over object properties.

Changes

  • Added 'guard-for-in': 'error' to the ESLint configuration to require hasOwnProperty() checks when iterating over object properties with for...in loops

Details

The guard-for-in rule helps prevent bugs by ensuring that for...in loops 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

dinwwwh and others added 2 commits September 15, 2026 01:52
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

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Enable guard-for-in — adds 'guard-for-in': 'error' to the first antfu({...}) rules block in eslint.config.js, requiring hasOwnProperty/Object.hasOwn guards (or index-style iteration) on for...in loops.

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.

Pullfrog  | View workflow run | Using DeepSeek Flash (default — pick a model for stronger reviews) | 𝕏

@dinwwwh dinwwwh changed the title Enable guard-for-in ESLint rule refactor: enable guard-for-in ESLint rule Sep 15, 2026
@dinwwwh
dinwwwh merged commit 2dd521d into main Sep 15, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant