---
title: "lint/complexity/prefer-in-array"
pagination: false
---

{/* Generated by scripts/gen-rule-docs.py. Edit mapping.toml, not this file. */}

<RuleId id="lint/complexity/prefer-in-array" />

In the [`code-quality`](/docs/rules/sets/code-quality) set. Safe fix.

## What it does

Use in_array() instead of repeated `||`/`&&` comparisons, array_search() checks and foreach loops.

## Configuration

```toml title="pun.toml"
[lint.rules]
"complexity/prefer-in-array" = "error"
```

To skip it in some files or lines, add an [override](/docs/configuration/pun-toml#lint) or an [ignore comment](/docs/configuration/ignore-comments).

## Options

| Name | Type | Allowed values | Default | Upstream name |
| --- | --- | --- | --- | --- |
| `checks` | `list` | `array-search`, `foreach`, `repeated-or` | `["array-search", "foreach", "repeated-or"]` | None (Pun's own) |

## Replaces

- [`ForeachToInArray`](https://getrector.com/rule-detail/foreach-to-in-array-rector) (rector)
- [`RepeatedOrEqualToInArray`](https://getrector.com/rule-detail/repeated-or-equal-to-in-array-rector) (rector)
- [`SimplifyArraySearch`](https://getrector.com/rule-detail/simplify-array-search-rector) (rector)

## Merged rules

These old IDs are now this rule. A config that still names one stops with an error. See [merged rules](/docs/migrate/merged-rules).

- `lint/complexity/prefer-in-array-over-search`
- `lint/complexity/prefer-in-array-over-foreach`

[More lint/complexity rules](/docs/rules/lint/complexity) · [Edit this page](https://github.com/shipfastlabs/pun/edit/main/crates/pun-config/rules/mapping.toml)
