8.0.3 β€’ Published 1 year ago

@putout/plugin-declare-undefined-variables v8.0.3

Weekly downloads
960
License
MIT
Repository
github
Last release
1 year ago

@putout/plugin-declare-undefined-variables NPM version

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

  • is types: isFn, isString, isNumber, isObject, isBool, isUndefined, isSymbol and isNull;
  • maybe: maybeArray, maybeFn, maybeEmptyArray;
  • wrap: not,id, returns;
  • fresh-import: freshImport, freshImportDefault;
  • fixtures: readFixture(name);
  • properties of Object;
  • wraptile;
  • fullstore;
  • currify;
  • pipe-io;
  • pullout;
  • simport;
  • chalk;
  • table;

Renamed to @putout/plugin-declare.

Install

npm i putout @putout/plugin-declare-undefined-variables -D

Add .putout.json with:

{
    "plugins": {
        "declare-undefined-variables": "on"
    }
}

Rules

Use options:

  • βœ… dismiss for variables you don't want to declare;
  • βœ… declarations to declare variables;
{
    "rules": {
        "declare-undefined-variables": ["on", {
            "declarations": {
                "hello": "import {hello} from 'world'"
            },
            "dismiss": [
                "assert",
                "entries",
                "parse",
                "stringify",
                "defineProperty",
                "isArray",
                "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);

isArray

❌ Example of incorrect code

isArray(array);

βœ… Example of correct code

const {isArray} = Array;
isArray(array);

noop

❌ Example of incorrect code

noop();

βœ… Example of correct code

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

Types

❌ Example of incorrect code

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),
];

License

MIT

8.0.1

1 year ago

8.0.3

1 year ago

8.0.2

1 year ago

8.0.0

1 year ago

7.2.0

2 years ago

7.1.1

2 years ago

7.1.0

2 years ago

7.0.1

2 years ago

6.5.0

2 years ago

6.6.0

2 years ago

6.8.1

2 years ago

6.8.0

2 years ago

6.4.0

2 years ago

7.0.0

2 years ago

6.7.0

2 years ago

6.1.0

2 years ago

6.3.0

2 years ago

5.15.0

2 years ago

5.13.0

2 years ago

5.16.0

2 years ago

6.0.0

2 years ago

6.2.0

2 years ago

5.14.0

2 years ago

5.12.0

2 years ago

5.10.0

2 years ago

5.9.0

2 years ago

5.8.0

3 years ago

5.7.0

3 years ago

5.6.0

3 years ago

5.5.0

3 years ago

5.4.0

3 years ago

5.3.0

3 years ago

5.2.0

3 years ago

5.1.0

3 years ago

5.0.0

3 years ago

4.3.0

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.0

3 years ago

3.2.0

3 years ago

4.0.0

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.6.0

3 years ago

2.5.0

3 years ago

2.4.0

3 years ago

2.3.1

3 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

1.9.0

3 years ago

2.0.0

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.3.0

3 years ago

1.0.0

3 years ago