5.0.0 β’ Published 10 months ago
@putout/plugin-declare v5.0.0
@putout/plugin-declare 
πPutout plugin adds ability to declare variable that was not defined before, including:
- maybe:
maybeArray,maybeFn,maybeEmptyArray; - wrap:
not,id,returns; - fresh-import:
freshImport,freshImportDefault; fixtures:readFixture;- properties of
Object; - wraptile;
- fullstore;
- currify;
- pipe-io;
- pullout;
- wait;
- simport;
- chalk;
- table;
Install
npm i putout @putout/plugin-declare -DAdd .putout.json with:
{
"plugins": {
"declare": "on"
}
}Rules
Use options:
- β
dismissfor variables you don't want to declare; - β
declarationsto 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]);fromEntries
β Example of incorrect code
fromEntries(['hello', 'world']);β Example of correct code
const {fromEntries} = Object;
fromEntries(['hello', 'world']);License
MIT