Pluggable and configurable JavaScript Linter, code transformer and formatter with superpowers : built-in support of js, jsx, ts, markdown, yaml, toml, jso
Pluggable and configurable JavaScript Linter, code transformer and formatter with superpowers : built-in support of js, jsx, ts, markdown, yaml, toml, jso
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 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 lots 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:
are also supported. Here is how it looks like:
CommonJS to ESMCheck out couple variants of plugins that does the same: linting debugger statement:
export const report = () => `Avoid 'debugger' statement`;
export const replace = () => ({
debugger: '',
});Choose wisely, competitors cannot even fix…
Putout in addition to own format .putout.json supports both eslint.config.js and .eslintrc.json, it has ability to autodect format you use.
Also it works good with monorepository, since it uses eslint.config.js that is closer to linting file, instead of cwd of ESLint run.
If I have seen further, it is by standing upon the shoulders of giants.
(c) Isaac Newton
Putout on the other hand can make more drastic code transformations that directly affects your codebase making it a better place to code :
To install Putout as a development dependency, run:
npm i putout -D Make sure that you are running a relatively recent (≥16) version of Node.
Grown-ups never understand anything by themselves, and it is tiresome for children to be always and forever explaining things to them.
(c) Antoine de Saint-Exupéry
Putout tries to be clear and likes a lot to explain things. So when you write putout --help most likely you will hear gladly purr :
…To skip prefix node_modules/.bin/, update your $PATH variable in with .bashrc:
echo 'PATH="$PATH:node_modules/.bin"' >> ~/.bashrc
source ~/.bashrcTo find possible transform places in a folder named lib, run:
putout libTo find possible transform places in multiple folders, such as folders named lib and test, run:
putout lib testTo apply the transforms, use --fix:
putout lib test --fixDevelopers, myself included, usually prefer to make all code changes manually, so that nothing happens to our code without reviewing it first. That is until we trust a tool to make those changes safely for us. An example is WebStorm, which we trust when renaming a class or a method. Since Putout may still feel like a new tool, not all of us will be able to trust it immediately.
A good way to gain trust is two run without --fix option, and observe error messages. Another way is to use traditional version control tactics. Before running Putout you should do a git commit. Then after running Putout, you’ll be able to inspect the changes it made using git diff and git status. You still have the chance to run git checkout -- . at any time to revert all the changes that Putout has made. If you need more fine-grained control, you can also use git add -p or git add -i to interactively stage only the changes you want to keep.
Putout supports the following environment variables:
PUTOUT_CONFIG_FILE - path to configuration file;PUTOUT_FILES - files that should be processed split by comma (,);Example:
PUTOUT_FILES=lib,test putout --fixWhen you need to run Putout in Deno, use @putout/bundle:
import putout from 'https://esm.sh/@putout/bundle';
import removeDebugger from 'https://esm.sh/@putout/plugin-remove-debugger?alias=putout:@putout/bundle';
import declare from 'https://esm.sh/@putout/plugin-declare?alias=putout:@putout/bundle';
putout('isFn(fn); debugger', {
plugins: [
['remove-debugger', removeDebugger],
['declare', declare],
],
});
// returns
({
code: `const isFn = a => typeof a === 'function';\nisFn(fn);`,
places: [],
});When you need to change configuration file use Ruler instead of editing the file manually.
Ruler can:
putout --enable [rule];putout --disable [rule];putout --enable-all;putout --disable-all;☝️Remember, Ruler should never be used with --fix, because unclear things makes Putout angry and you can find him barking at you:
'--fix' cannot be used with ruler toggler ('--enable', '--disable')You may want to convert your CommonJS to ESM since node v12 supports it without a flag.
CommonJS to ESMpackage.jsonWell, if you have no type field or type=commonjs your package will be
converted to CommonJS automatically. To convert to ESM just set type=module.
.cjs or .mjs filesThey will be converted automatically to CommonJS and ESM accordingly.
Let's suppose you have a file called index.js:
const unused = 5;
module.exports = function() {
return promise();
};
async function promise(a) {
return Promise.reject(Error('x'));
}You call putout --fix index.js and see that file is changed:
'use strict';
module.exports = async function() {
return await promise();
};
async function promise() {
throw Error('x');
}But for some reason you don't want so many changes.
☝️ Remember, safe mode of eslint-plugin-putout has the most dangerous rules disabled, so it can be used as auto fix on each save in your IDE.
So, if you want to convert it to ESM keeping everything else untouched use Ruler: it can easily disable all rules Putout finds.
putout index.js --disable-all will find next errors:
…It will create config file .putout.json:
{
"rules": {
"variables/remove-unused": "off",
"convert-to-arrow-function": "off",
"nodejs/add-missing-strict-mode": "off",
"promises/convert-reject-to-throw":No open issues yet, or sync has not completed.