npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2026 – Pkg Stats / Ryan Hefner

@putout/plugin-variables

v1.6.1

Published

🐊Putout plugin adds ability to find and remove useless

Readme

@putout/plugin-variables NPM version

A variable is a named reference to a value.

(c) MDN

🐊Putout plugin adds ability to transform variables.

Install

npm i @putout/plugin-variables -D

Rules

Config

{
    "rules": {
        "variables/apply-declarations-order": "on",
        "variables/convert-const-to-let": "on",
        "variables/extract-keywords": "on",
        "variables/reuse-duplicate-init": "on",
        "variables/remove-useless-assignment": "on",
        "variables/remove-useless-declaration": ["on", {
            "maxLength": 20
        }],
        "variables/remove-useless-duplicate": "on",
        "variables/remove-useless-rename": "on",
        "variables/remove-useless-remove": "on",
        "variables/remove-unused": "on",
        "variables/split-declarations": "on"
    }
}

apply-declarations-order

Helps to reuse duplicate init. Checkout in 🐊Putout Editor.

❌ Example of incorrect code

const {env} = require('node:process');
const process = require('node:process');

βœ… Example of correct code

const process = require('node:process');
const {env} = process;

assignment

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

while (!(files = readDirectory(parentDir)).length) {}

βœ… Example of correct code

while (!readDirectory(parentDir).length) {}

reuse-duplicate-init

Functions are one of the fundamental building blocks it contains set of statements that performs a calculations, takes some input and returns an output. To use a function, you must define it somewhere in the scope from which you wish to call it.

(c) MDN

🐊Putout plugin adds ability to reuse duplicate init.

❌ Example of incorrect code

const putout = require('putout');

const {
    a,
    b,
    operator,
} = putout;

const {replaceWith} = operator;

βœ… Example of correct code

const putout = require('putout');

const {
    a,
    b,
    operator,
} = putout;

const {replaceWith} = operator;

remove-useless-rename

❌ Example of incorrect code

function hi(a) {
    const b = a;
}

βœ… Example of correct code

function hi(b) {}

remove

❌ Example of incorrect code

const child_process = require('node:child_process');

const {exec, spawn} = child_process;

βœ… Example of correct code

const {exec, spawn} = require('node:child_process');

remove

Check it out in 🐊Putout Editor.

❌ Example of incorrect code

const a = 5;
const b = a;

const c = 5;

d = c;

βœ… Example of correct code

const b = 5;

d = 5;

remove-useless-declaration

Check it out in 🐊Putout Editor.

❌ Example of incorrect code

function x() {
    const a = 5;
    return a;
}

const z = b.c.replace('x', 'y');

b.c = z;

βœ… Example of correct code

function x() {
    return 5;
}

b.c = b.c.replace('x', 'y');

remove-useless-duplicate

Check it out in 🐊Putout Editor.

❌ Example of incorrect code

const DestructuringErrors = function DestructuringErrors(a, b) {
    return [a, b];
};

βœ… Example of correct code

function DestructuringErrors(a, b) {
    return [a, b];
}

bc = b.c.replace('x', 'y');

remove-unreferenced

❌ Example of incorrect code

let a;
let b;

a = 5;
b = 6;

console.log(a);

βœ… Example of correct code

let a;

a = 5;

console.log(a);

split-declarations

  • The let statement declares a block-scoped local variable, optionally initializing it to a value.
  • const statements are also block-scoped. The value of a constant can't be changed through reassignment, and it can't be redeclared. However, if a constant is an object or array its properties or items can be updated or removed.

(c) MDN

Add ability to find and split variable declarations because (re)moving a line is simpler and less error prone then changing coma (,) to colon (;). For the same reason, diff of changed declarations are more comfortable to read.

❌ Example of incorrect code

let a, b;

βœ… Example of correct code

let a;
let b;

Comparison

Linter | Rule | Fix --------|-------|------------| 🐊 Putout | remove-debugger | βœ… ⏣ ESLint | no-var | βœ…

convert-const-to-let

The TypeError object represents an error when attempting to modify a value that cannot be changed.

(c) MDN

Convert const to let to avoid TypeError. Check out in 🐊Putout Editor.

❌ Example of incorrect code

let a = 5;

a = 3;

βœ… Example of correct code

let a = 5;

a = 3;

remove-unused

A variable is a container for a value, like a number we might use in a sum, or a string that we might use as part of a sentence.

(c) MDN

🐊Putout plugin adds ability to find and remove the variables that are declared, but:

  • not passed as argument to a function;
  • not used as operand in expression;

That is unused variables. Most likely it is a leftovers due to incomplete transforming of the code. Such variables take up space and gives no value so they must be removed.

☝️Remember, when you writing a transform you can skip all parts related to removing unused variables and just reuse current plugin it will make your code simpler and less error prone.

☝️No, you cannot just look at referenced and constant fields to determine if you can remove variable and here is why one of the biggest plugins exists.

❌ Example of incorrect code

const a = 'hello';
const b = 'world';

console.log(a);

βœ… Example of correct code

const a = 'hello';
console.log(a);

Comparison

Linter | Rule | Fix --------|-------|------------| 🐊 Putout| remove-unused-variables| βœ… ⏣ ESLint | no-unused-vars | ❌

extract-keywords

The JavaScript exceptions "unexpected token" occur when the parser does not see a token it recognizes at the given position, so it cannot make sense of the structure of the program. This might be a simple typo.

(c) MDN

Extract keywords from variables. Check out in 🐊Putout Editor.

-export const isTemplateMiddle = (a) => a?.type === 'TemplateMiddle',
+export const isTemplateMiddle = (a) => a?.type === 'TemplateMiddle';
export const isTemplateTail = (a) => a?.type === 'TemplateTail';

-const a 5;
+const a = 5;

-export const packContent = (content) {
+export const packContent = (content) => {
    console.log(a);
}

License

MIT