@putout/plugin-declare
🐊Putout plugin adds ability to declare variables
Last updated 2 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @putout/plugin-declare 
SYNC missed versions from official npm registry.

@putout/plugin-declare NPM version

🐊Putout plugin adds ability to declare variable that was not defined before, including:

Install

npm i putout @putout/plugin-declare -D

Add .putout.json with:

{
    "plugins": {
        "declare": "on"
    }
}

Rules

Use options:

  • βœ… dismiss for variables you don't want to declare;
  • βœ… declarations to declare variables;
{
    "rules": {
        "declare": ["on", {
            "declarations": {
                "hello": "import {hello} from 'world'"
            },
            "dismiss": [
                "assert",
                "entries",
                "parse",
                "stringify",
                "defineProperty",
                "noop",
                "join",
                "keys",
                "values",
                "stopAll",
                "once",
                "putout",
                "simport"
            ]
        }]
    }
}

assign

❌ Example of incorrect code

const hello = 'world';
const object = {};

assign(object, {
    hello,
});

βœ… Example of correct code

const hello = 'world';
const object = {};
const {assign} = Object;

assign(object, {
    hello,
});

keys

❌ Example of incorrect code

const hello = 'world';
const object = {};

const allKeys = keys(object);

βœ… Example of correct code

const hello = 'world';
const object = {};
const {keys} = Object;

const allKeys = keys(object);

values

❌ Example of incorrect code

const object = {};
const allValues = values(object);

βœ… Example of correct code

const {values} = Object;

const object = {};
const allValues = values(object);

noop

❌ Example of incorrect code

noop();

βœ… Example of correct code

const noop = () => {};
noop();

Types

❌ Example of incorrect code

const isFn = (a) => typeof a === 'function';

if (isFn(fn))
    fn();

βœ… Example of correct code

const isFn = (a) => typeof a === 'function';

if (isFn(fn))
    fn();

Maybe

❌ Example of incorrect code

const a = [...maybeArray(b)];

βœ… Example of correct code

const {isArray} = Array;
const maybeArray = (a) => isArray(a) ? a : [a];

const a = [...maybeArray(b)];

entries

❌ Example of incorrect code

entries([1, 2, 3]);

βœ… Example of correct code

const {isArray} = Array;
const entries = (a) => isArray(a) ? a.entries() : Object.entries();

entries([1, 2, 3]);

License

MIT

Current Tags

  • 4.0.0                                ...           latest (8 months ago)

11 Versions

  • 4.0.0                                ...           8 months ago
  • 3.1.0                                ...           9 months ago
  • 3.0.0                                ...           a year ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.2.1                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (12)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE