---
title: "lint/style/prefer-dir-constant"
pagination: false
---

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

<RuleId id="lint/style/prefer-dir-constant" />

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

## What it does

Replaces `dirname(__FILE__)` expression with equivalent `__DIR__` constant.

## Configuration

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

- [`dir_constant`](https://cs.symfony.com/doc/rules/language_construct/dir_constant.html) (php-cs-fixer, risky)

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