@putout/plugin-declare-before-reference

3.0.0 • Public • Published

@putout/plugin-declare-before-reference NPM version

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.

Install

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

Rule

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

❌ Example of incorrect code

const {remove} = operator;

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

✅ Example of correct code

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

const {remove} = operator;

Comparison

Linter Rule Fix
🐊 Putout declare-before-reference
ESLint no-use-before-define

License

MIT

/@putout/plugin-declare-before-reference/

    Package Sidebar

    Install

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

    Weekly Downloads

    4,123

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    7.12 kB

    Total Files

    4

    Last publish

    Collaborators

    • coderaiser