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 πŸ™

Β© 2024 – Pkg Stats / Ryan Hefner

putout

v36.12.0

Published

🐊 Pluggable and configurable code transformer with built-in ESLint, Babel and support of js, jsx, typescript, flow, markdown, yaml and json

Downloads

72,601

Readme

Putout NPM version Build Status Coverage Status

Perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away.

(c) Antoine de Saint ExupΓ©ry

putout

🐊Putout is a JavaScript Linter, pluggable and configurable code transformer, drop-in ESLint replacement with built-in code printer and ability to fix syntax errors. It has a lot of transformations that keeps your codebase in a clean state, removing any code smell and making code readable according to best practices.

The main target is JavaScript, but:

  • βœ… JSX;
  • βœ… TypeScript;
  • βœ… Flow;
  • βœ… Yaml;
  • βœ… Markdown;
  • βœ… JSON;
  • βœ… Ignore;

are also supported. Here is how it looks like:

putout

πŸ€·β€οΈ In doubt about using 🐊Putout?

Check out couple variants of plugins that does the same: linting debugger statement:

'use strict';

module.exports.report = () => 'Unexpected "debugger" statement';

module.exports.replace = () => ({
    debugger: '',
});

Choose wisely, competitors cannot even fix… 🀫

πŸ™ Whom should I thank for this project exist?

If I have seen further, it is by standing upon the shoulders of giants.

(c) Isaak Newton

  • πŸ’ͺ ESLint for stable releases and future proof API.
  • πŸ’ͺ Babel for amazing API documented in Handbook and responsiveness of a team.
  • πŸ’ͺ Prettier for minimalistic options and uniform codestyle.
  • πŸ’ͺ jscodeshift for making codemods simple and popular.

🀷 Why does this project exist?

☝️ 🐊Putout on the other hand can make more drastic code transformations that directly affects your codebase making it a better place to code πŸ’».

It can:

  • βœ… remove unused variables;
  • βœ… remove unused for-of variables;
  • βœ… remove unused typescripts types;
  • βœ… remove unreferenced variables;
  • βœ… remove unused private fields;
  • βœ… remove unused expressions;
  • βœ… remove useless variables;
  • βœ… remove useless Object.assign();
  • βœ… remove useless replace();
  • βœ… remove useless map;
  • βœ… remove useless mapped types;
  • βœ… remove useless mapping modifiers;
  • βœ… remove useless continue;
  • βœ… remove useless operand;
  • βœ… remove useless array constructor;
  • βœ… remove useless conditions;
  • βœ… remove useless type conversion;
  • βœ… remove useless functions;
  • βœ… remove useless Array.from;
  • βœ… remove useless spread;
  • βœ… remove useless arguments;
  • βœ… remove useless escape;
  • βœ… remove useless async;
  • βœ… remove useless await;
  • βœ… remove useless typeof;
  • βœ… remove useless template expressions;
  • βœ… remove useless for-of;
  • βœ… remove useless array.entries();
  • βœ… remove debugger statement;
  • βœ… remove iife;
  • βœ… remove nested blocks;
  • βœ… remove process.exit call;
  • βœ… remove console.log calls;
  • βœ… remove empty block statements;
  • βœ… remove empty patterns;
  • βœ… remove strict mode directive from esm;
  • βœ… remove constant conditions;
  • βœ… remove boolean from assertion;
  • βœ… remove boolean from logical expressions;
  • βœ… remove duplicates from TypeScript Union;
  • βœ… remove unreachable code;
  • βœ… remove duplicate keys;
  • βœ… remove useless typescripts types;
  • βœ… remove duplicate typescripts interface keys;
  • βœ… replace test.only to test calls;
  • βœ… replace test.skip to test calls;
  • βœ… reuse duplicate init;
  • βœ… split variable declarations;
  • βœ… split nested destructuring;
  • βœ… simplify assignment;
  • βœ… simplify ternary;
  • βœ… simplify logical expressions;
  • βœ… if absent strict mode directive in commonjs add it;
  • βœ… convert const to let (when needed to avoid TypeError);
  • βœ… convert apply to spread;
  • βœ… convert bitwise to logical operator;
  • βœ… convert concat to flat;
  • βœ… convert esm to commonjs (enabled for *.cjs);
  • βœ… convert commonjs to esm (enabled for *.mjs);
  • βœ… convert template with one expression to string;
  • βœ… convert equal to strict equal;
  • βœ… convert indexOf to includes;
  • βœ… convert replace to replaceAll;
  • βœ… convert assignment to arrow function;
  • βœ… convert forEach to for...of;
  • βœ… convert map to for...of;
  • βœ… convert reduce to for...of;
  • βœ… convert Math.sqrt() to Math.hypot();
  • βœ… extract sequence expressions;
  • βœ… extract object properties;
  • βœ… add return await;
  • βœ… remove useless Promise.resolve;
  • βœ… convert Promise.reject to throw;
  • βœ… declare before reference;
  • βœ… declare undefined variables;
  • βœ… declare imports first;
  • βœ… apply as type assertions;
  • βœ… apply utility types;
  • βœ… apply array.at;
  • βœ… apply filter(Boolean);
  • βœ… apply isArray;
  • βœ… apply if condition;
  • βœ… apply await import;
  • βœ… apply comparison order;
  • βœ… apply flatMap();
  • βœ… apply template literals;
  • βœ… merge duplicate imports;
  • βœ… merge duplicate functions;

Install

npm i putout -D

Usage

Usage: putout [options] [path]
Options:
   -h, --help                  display this help and exit
   -v, --version               output version information and exit
   -f, --format [formatter]    use a specific output format, the default is: 'progress-bar' locally and 'dump' on CI
   -s, --staged                add staged files when in git repository
   -i, --interactive           set lint options using interactive menu
   --fix                       apply fixes of errors to code
   --fix-count [count = 10]    count of fixes rounds
   --rulesdir                  use additional rules from directory
   --transform [replacer]      apply Replacer, for example 'var __a = __b -> const __a = __b', read about Replacer https://git.io/JqcMn
   --plugins [plugins]         a comma-separated list of plugins to use
   --enable [rule]             enable the rule and save it to '.putout.json' walking up parent directories
   --disable [rule]            disable the rule and save it to '.putout.json' walking up parent directories
   --enable-all                enable all found rules and save them to '.putout.json' walking up parent directories
   --disable-all               disable all found rules (set baseline) and save them to '.putout.json' walking up parent directories
   --match [pattern]           read '.putout.json' and convert 'rules' to 'match' according to 'pattern'
   --flow                      enable flow
   --fresh                     generate a fresh cache
   --no-config                 avoid reading '.putout.json'
   --no-ci                     disable the CI detection
   --no-cache                  disable the cache
   --no-worker                 disable worker thread

To find errors:

putout lib test

To fix errors:

putout lib test --fix

Plugins

By default 🐊Putout uses all enabled by default plugins, anyways it can be run with a couple mentioned plugins (split with ","):

putout lib --plugins remove-debugger,remove-unused-variables

Environment variables

🐊Putout supports next environment variables:

  • PUTOUT_FILES - files that should be processed by putout, divided by ",";
  • PUTOUT_CONFIG_FILE - path to 🐊Putout config file;
  • ESLINT_CONFIG_FILE - path to ESLint config file;
  • NO_ESLINT - do not run ESLint after 🐊Putout;
  • NO_ESLINT_WARNINGS - do not show ESLint warnings;
PUTOUT_FILES=lib,test putout --fix

Configuration

To configure create .putout.json file and override any of default options.

Match

When you need to match paths to rules you can use match section for this purpose in .putout.json:

{
    "match": {
        "server": {
            "remove-process-exit": true
        }
    }
}

Ignore

When you need to ignore some routes no metter what, you can use ignore section in .putout.json:

{
    "ignore": ["test/fixture"]
}

Plugins

🐊Putout supports two types of plugins, prefix with:

  • βœ… @putout/plugin-;
  • βœ… putout-plugin-;

To use your plugin createnpm package with keywords putout, putout-plugin and add it to .putout.json.

For example if you need to remove-something create 🐊Putout plugin with name putout-plugin-remove-something and it to package.json:

{
    "plugins": ["remove-something"]
}

Codemods

🐊Putout supports codemodes in the similar to plugins way, just create a directory ~/.putout and put your plugins there. Here is example: convert-tape-to-supertape and this is examples of work.

API

All examples works both in ESM and CommonJS.

CommonJS:

const putout = require('putout');

ESM:

import {putout} from 'putout';

putout(source, options)

import {putout} from 'putout';

const source = `
    const t = 'hello';
    const m = t + '!';
    console.log(t);
`;

putout(source, {
    plugins: ['remove-unused-variables'],
});

// returns
`
const t = 'hello';
console.log(t);
`;

putoutAsync(source, options)

import {putoutAsync} from 'putout';

const source = `
    const t = 'hello';
    const m = t + '!';
    console.log(t);
`;

await putoutAsync(source, {
    plugins: ['remove-unused-variables'],
});

// returns
`
const t = 'hello';
console.log(t);
`;

License

MIT