---
title: "lint/operators/prefer-coalesce"
pagination: false
---

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

<RuleId id="lint/operators/prefer-coalesce" />

In the [`modernize`](/docs/rules/sets/modernize) set. Safe fix.

## What it does

Use `null` coalescing operator `??` where possible.

## Configuration

```toml title="pun.toml"
[lint.rules]
"operators/prefer-coalesce" = "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.

## Replaces

- [`ternary_to_null_coalescing`](https://cs.symfony.com/doc/rules/operator/ternary_to_null_coalescing.html) (php-cs-fixer)

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