Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@putout/plugin-declare-undefined-variables

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@putout/plugin-declare-undefined-variables

🐊Putout plugin adds ability to declare undefined variables

  • 8.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@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

Keywords

FAQs

Package last updated on 06 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc