πPutout plugin adds ability move declarations before references
npm install @putout/plugin-declare-before-reference[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
πPutout plugin adds ability to apply declare before reference to avoid ReferenceError.
The rule is similar to ESLint's 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 with a bunch of nested declarations.
```
npm i @putout/plugin-declare-before-reference
`json`
{
"rules": {
"declare-before-reference": "on"
}
}
`js
const {remove} = operator;
const {types, operator} = require('putout');
`
`js
const {types, operator} = require('putout');
const {remove} = operator;
`
Linter | Rule | Fix
--------|-------|------------|
π Putout | declare-before-reference | β
β£ ESLint | no-use-before-define` | β
MIT