Prefer Set Has
Developmentprefer-set-hasPrefer Set Has is an Agent Skill for development published in the LedgerHQ/ledger-live repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Prefer Set.has() over Array.includes() for constant allowlists/blocklists. Read this when reviewing or writing membership checks in TypeScript files.
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Inspect the Agent Skill at https://github.com/LedgerHQ/ledger-live/blob/HEAD/.agents/skills/prefer-set-has/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/prefer-set-has, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
Prefer Set.has() over Array.includes()
When checking membership in a constant list of known values (allowlists, blocklists, enum-like sets), use a Set with .has() instead of an array with .includes().
// ❌ BAD
const ALLOWED = ["a", "b", "c"];
if (ALLOWED.includes(value)) { … }
// ✅ GOOD
const ALLOWED = new Set(["a", "b", "c"]);
if (ALLOWED.has(value)) { … }
Why: Set.has() is O(1) vs .includes() O(n), communicates "membership test" intent more clearly, and avoids accidental mutation of the backing array.
When .includes() is fine: Searching within a dynamic or short-lived array (e.g. function parameters, user input) where creating a Set would add noise.