# @putout/plugin-declare-before-reference

> 🐊Putout plugin adds ability move declarations before references

Latest version **10.5.0** (published 2026-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @putout/plugin-declare-before-reference
pnpm add @putout/plugin-declare-before-reference
yarn add @putout/plugin-declare-before-reference
bun add @putout/plugin-declare-before-reference
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 10.5.0 |
| Published | 2026-04-27 |
| First published | 2022-04-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 0 |
| Unpacked size | 9.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 804 |
| Author | coderaiser |
| Maintainers | coderaiser |
| Keywords | putout, putout-plugin, putout-plugin-apply, plugin, declare-before-reference |

## Links

- npm: https://www.npmjs.com/package/@putout/plugin-declare-before-reference
- Repository: https://github.com/coderaiser/putout
- Homepage: http://github.com/coderaiser/putout/tree/master/packages/plugin-declare-before-reference#readme
- Issues: https://github.com/coderaiser/putout/issues
- npm.io page: https://npm.io/package/@putout/plugin-declare-before-reference

## Recent versions

- 10.5.0 (latest) — 2026-04-27
- 10.4.0 — 2026-03-21
- 10.3.2 — 2026-03-09
- 10.3.1 — 2026-03-08
- 10.3.0 — 2026-03-08
- 10.2.0 — 2026-03-06
- 10.1.0 — 2026-02-28
- 10.0.0 — 2026-02-22
- 9.0.1 — 2025-12-27
- 9.0.0 — 2025-12-27
- 8.3.0 — 2025-11-12
- 8.2.0 — 2025-06-01
- 8.1.0 — 2025-05-04
- 8.0.0 — 2025-05-04
- 7.0.0 — 2025-04-27
- … 14 more at https://npm.io/package/@putout/plugin-declare-before-reference/versions

## README

# @putout/plugin-declare-before-reference [![NPM version][NPMIMGURL]][NPMURL]

[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-declare-before-reference.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/@putout/plugin-declare-before-reference "npm"

> The `ReferenceError` object represents an error when a variable hasn't yet been initialized in the current scope is referenced.
>
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)

🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to apply declare before reference to avoid `ReferenceError`.

The rule is similar to **ESLint's** [no-use-before-define](https://eslint.org/docs/rules/no-use-before-define), but it's auto fixable,
and ignores:

- ✅ Function declarations
- ✅ Class declarations
- ✅ Different scopes

Also it works only on top level and helps to [@operator/declare](https://github.com/coderaiser/putout/tree/master/packages/operator-declare#readme) with a bunch of nested declarations.

## Install

```
npm i @putout/plugin-declare-before-reference
```

## Rule

```json
{
    "rules": {
        "declare-before-reference": "on"
    }
}
```

## ❌ Example of incorrect code

```js
const {remove} = operator;

const {types, operator} = require('putout');
```

## ✅ Example of correct code

```js
const {types, operator} = require('putout');

const {remove} = operator;
```

## Comparison

Linter | Rule | Fix
--------|-------|------------|
🐊 **Putout** | [`declare-before-reference`](https://github.com/coderaiser/putout/tree/master/packages/plugin-declare-before-reference#readme) | ✅
⏣ **ESLint** | [`no-use-before-define`](https://eslint.org/docs/rules/no-use-before-define) | ❌

## License

MIT

---
_Source: https://npm.io/package/@putout/plugin-declare-before-reference · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
