---
title: "lint/classes/require-class-matches-file"
pagination: false
---

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

<RuleId id="lint/classes/require-class-matches-file" />

In the [`code-quality`](/docs/rules/sets/code-quality) set. Unsafe fix: it can change behaviour. Intent: correctness.

## What it does

Classes must be in a path that matches their namespace, be at least one namespace deep and the class name should match the file name.

## Configuration

```toml title="pun.toml"
[lint.rules]
"classes/require-class-matches-file" = "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 |
| --- | --- | --- | --- | --- |
| `dir` | `string` | Any | Not set | `dir` |

## Replaces

- [`psr_autoloading`](https://cs.symfony.com/doc/rules/basic/psr_autoloading.html) (php-cs-fixer, risky)
- [`file-name`](https://mago.carthage.software/1.61.0/en/tools/linter/rules/#file-name) (mago-linter)

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