Skip to content

fix(react-best-practices): warn about Set/Map recreation in function scope - #180

Open
mvanhorn wants to merge 1 commit into
vercel-labs:mainfrom
mvanhorn:osc/54-set-map-recreation-warning
Open

fix(react-best-practices): warn about Set/Map recreation in function scope#180
mvanhorn wants to merge 1 commit into
vercel-labs:mainfrom
mvanhorn:osc/54-set-map-recreation-warning

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

Adds a warning about the common pitfall of recreating Set/Map inside functions called repeatedly, which negates the O(1) lookup benefit.

Why this matters

The current rule shows converting arrays to Set for O(1) lookups but doesn't warn about a common pitfall: creating the Set inside a function body that runs on every call (#54). This means Set construction (O(n)) runs every time, negating the performance benefit. An AI agent or junior developer following the rule literally could produce this anti-pattern.

Changes

  • Added a "Common Pitfall" section showing the anti-pattern of Set recreation inside functions
  • Added the correct pattern of hoisting Set to module level
  • Kept existing rule content unchanged (additive change only)

Testing

Reviewed rule formatting for consistency with other rule files in the repo.

Fixes #54

This contribution was developed with AI assistance (Claude Code).

@vercel

vercel Bot commented Mar 15, 2026

Copy link
Copy Markdown

@mvanhorn is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@HonzysClawdbot

Copy link
Copy Markdown

This PR adds a warning about Set/Map recreation in function scope - a common pitfall that negates the O(1) lookup benefit. ✅ CI is passing (Vercel Agent Review).

Fixes #54. Important safety addition - can be merged safely.

@mvanhorn

mvanhorn commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

Hey, checking in on my open agent-skills PRs:

All have passing CI. Let me know if any need changes.

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.

Problems with the rule "Use Set/Map for O(1) Lookups"

2 participants