---
title: "lint/operators/prefer-coalesce-assign-over-fallback"
pagination: false
---

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

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

In the [`modernize`](/docs/rules/sets/modernize) set. Safe fix where types prove it, unsafe otherwise.

## What it does

Suggests the null coalescing assignment operator (`??=`) when the right operand of `??` assigns to the same variable or property as its left operand.

## Configuration

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

## Replaces

- [`prefer-null-coalescing-assignment`](https://mago.carthage.software/1.61.0/en/tools/linter/rules/#prefer-null-coalescing-assignment) (mago-linter)

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