README
Putout
🐊Putout
find and fix problems in your JavaScript
, JSX
, Typescript
, Flow
, Yaml,
Jsonand
Markdown`. 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
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 fromesm
; - remove
constant conditions
; - remove
boolean
fromassertion
; - remove
boolean
fromlogical expressions
; - remove
duplicates
fromlogical expressions
; - remove
duplicates
from TypeScriptUnion
; - remove
unreachable code
; - remove
duplicate keys
; - remove useless
typescripts
types; - remove duplicate
typescripts
interface keys; - replace
test.only
totest
calls; - replace
test.skip
totest
calls; - reuse duplicate
init
; - split
variable declarations
; - split
nested destructuring
; - simplify
assignment
; - simplify
ternary
; - simplify
logical expressions
; - if absent
strict mode
directive incommonjs
add it; - convert
apply
tospread
; - convert
bitwise
tological
operator; - convert
concat
toflat
; - convert
esm
tocommonjs
(enabled for*.cjs
); - convert
commonjs
toesm
(enabled for*.mjs
); - convert
template
with oneexpression
tostring
; - convert
equal
tostrict equal
; - convert
indexOf
toincludes
; - convert
replace
toreplaceAll
(disabled, stage 4); - convert
assignment
toarrow function
; - convert
forEach
tofor-of
; - convert
map
tofor-of
; - extract sequence expressions;
- extract object properties;
- add
return await
; - remove useless
Promise.resolve
; - convert
Promise.reject
tothrow
; - declare
undefined variables
; - apply
as
type assertions; - apply
utility types
; - apply
array.at
(not bundled); - apply
filter(Boolean)
; - apply isArray;
- apply
if condition
; - apply
await import
;
Why?
- because eslint avoids fixes that could change the runtime behavior.
- because babel produces throw-away code;
- because pretier it is a formatter;
- because jscodeshift has no
config
andplugins
support.
The main difference of putout
is saving code transformation results directly into source code in a day-to-day baisis.
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' localy and 'dump' on CI
-s, --staged add staged files when in git repository
--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 '.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
To find erros:
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 (splitted 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 toESLint
config file;
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 plugins
, there is two types: with prefix official @putout/plugin-
and user plugins with prefix putout-plugin-
. To use your plugin create plugin as npm
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 example of work.
API
putout(source, options)
const putout = require('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);
`;
License
MIT