---
title: "lint/style/prefer-str-contains"
pagination: false
---

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

<RuleId id="lint/style/prefer-str-contains" />

In the [`modernize`](/docs/rules/sets/modernize) set. Unsafe fix: it can change behaviour.

## What it does

Replace `strpos()` and `stripos()` calls with `str_starts_with()` or `str_contains()` if possible.

## Configuration

```toml title="pun.toml"
[lint.rules]
"style/prefer-str-contains" = "error"
```

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

## Options

| Name | Type | Allowed values | Default | Upstream name |
| --- | --- | --- | --- | --- |
| `modernize-stripos` | `bool` | Any | `false` | `modernize_stripos` |

## Replaces

- [`modernize_strpos`](https://cs.symfony.com/doc/rules/alias/modernize_strpos.html) (php-cs-fixer, risky)
- [`str-contains`](https://mago.carthage.software/1.61.0/en/tools/linter/rules/#str-contains) (mago-linter)
- [`str-starts-with`](https://mago.carthage.software/1.61.0/en/tools/linter/rules/#str-starts-with) (mago-linter)

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