---
title: "lint/performance/prefer-static-closure"
pagination: false
---

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

<RuleId id="lint/performance/prefer-static-closure" />

Not in any set. Unsafe fix: it can change behaviour.

## What it does

Lambdas not (indirectly) referencing `$this` must be declared `static`.

## Configuration

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

- [`static_lambda`](https://cs.symfony.com/doc/rules/function_notation/static_lambda.html) (php-cs-fixer, risky)
- [`prefer-static-closure`](https://mago.carthage.software/1.61.0/en/tools/linter/rules/#prefer-static-closure) (mago-linter)

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