putout

🐊 Pluggable and configurable JavaScript Linter, code transformer and formatter with built-in ESLint and Babel support for js, jsx typescript, flow, markdown, yaml and json. Write declarative codemods in a simplest possible way 😏

MIT License

Downloads
3.6M
Stars
646
Committers
23
putout - putout v20.10.2

Published by coderaiser about 3 years ago

🐞 fix

  • (putout) --help -> --disable-all -> save them 'putout.json'-> save them to 'putout.json'

πŸ”₯ feature

putout - putout v20.10.1

Published by coderaiser about 3 years ago

🐞 fix

  • (putout) cli: parse-options: --rulesdir when no package.json or .putout.json found

πŸ”₯ feature

  • (@putout/operator-add-argument) add support of labaled statement
  • (@putout/operator-add-argument) add support of options
  • (@putout/operator-add-argument) exclude blocks that is not a function
  • (@putout/plugin-tape) declare-t: simplify
putout - putout v20.10.0

Published by coderaiser about 3 years ago

πŸ”₯ feature

  • (@putout/plugin-putout) declare: add addArgument
  • (@putout/plugin-putout) add-missing-argument: add compare
  • (@putout/operator-add-argument) add
  • (@putout/plugin-putout) add-missing-argument: add support of case where it is not test
  • (@putout/plugin-putout) add add-missing-argument
  • (eslint-plugin-putout) no-unresolved: add support of dynamic import
  • (@putout/plugin-declare-undefined-variables) add support of eslint
  • (eslint-plugin-putout) ts: disable no-var
  • (@putout/plugin-putout) declare: operator: add support of declare
putout - putout v20.9.0

Published by coderaiser about 3 years ago

New rule remove-useless-constructor added πŸŽ‰

image

Wrapper classes have surprising behaviour, such as new Boolean(false) evaluating to true.

https://google.github.io/styleguide/tsguide.html#primitive-types-wrapper-classes

New putout plugin adds ability to remove useless constructors. Use it with remove-useless-new to get event more benefit πŸ”₯.

❌ Incorrect code example

const s = String('hello');
const b = Boolean(false);
const n = Number(5);

βœ… Correct code Example

const s = 'hello';
const b = false;
const n = 5;

πŸ”₯ feature

  • (@putout/plugin-putout) check-replace-code: add support of top level comparison __a, "hello"
  • (@putout/compare) add support of top level comparison __a === "hello world"
  • (@putout/plugin-remove-useless-constructor) add
putout - putout v20.8.0

Published by coderaiser about 3 years ago

🐞 fix

  • feature(@putout/engine-runner) add ability to pass options to fix

πŸ”₯ feature

  • (@putout/plugin-tape) use isSimpleRegExp from operator
  • (package) @putout/plugin-regexp v3.0.0
  • (@putout/plugin-regexp) drop support of putout < 20
  • (@putout/plugin-putout) declare: add isSimpleRegExp
  • (@putout/operator-regexp) add
  • (package) estrace v3.0.2
  • (@putout/plugin-tape) declare: add Test, Stub
  • (@putout/plugin-tape) declare-t: add support of empty body
  • (@putout/engine-runner) add ability to pass options to fix
  • (@putout/operator-declare) add ability to pass options with declarations
  • (eslint-plugin-putout) add evaluate (https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/evaluate)
putout - putout v20.7.1

Published by coderaiser about 3 years ago

πŸ”₯ feature

  • (@putout/plugin-putout) declare: use operator.declare
  • (@putout/plugin-tape) use operator.declare
  • (package) @putout/plugin-declare-undefined-variables v5.0.0
  • (@putout/plugin-declare-undefined-variables) rm export declare: drop supoport of putout < 20.7
putout - putout v20.7.0

Published by coderaiser about 3 years ago

πŸ”₯ feature

  • (@putout/operator-declare) add
putout - putout v20.6.1

Published by coderaiser about 3 years ago

🐞 fix

  • (@putout/plugin-declare-undefined-variables) declare: template.ast -> template.ast.fresh
  • (@putout/plugin-merge-duplicate-imports) report: Avoid duplicate imports
  • (@putout/plugin-merge-duplicate-imports) importKind -> importKind=type

πŸ”₯ feature

  • (putout) *.md: disable declare-undefined-variables
  • (@putout/cli-ruller) add support of tuple
  • (@putout/plugin-declare-undefined-variables) add support of putout
  • (@putout/eslint-config) add dot-notation (https://eslint.org/docs/rules/dot-notation)
  • (@putout/plugin-merge-duplicate-imports) drop support of node < 14
putout - putout v20.6.0

Published by coderaiser about 3 years ago

πŸ”₯ feature

  • (package) @putout/plugin-reuse-duplicate-init v2.0.0
  • (package) @putout/plugin-tape v4.0.0
  • (package) @putout/plugin-reuse-duplicate-init v2.0.0
  • (@putout/plugin-reuse-duplicate-init) drop support of node < 14
  • (package) @putout/plugin-tape v4.0.0
  • (@putout/plugin-tape) drop support of putout < 20
  • (@putout/plugin-tape) merge declare-stub with declare-test
  • (@putout/plugin-tape) add declare-test
putout - putout v20.5.2

Published by coderaiser about 3 years ago

A lot new rules in patch release πŸ’₯

Usually I don't write release notes for patch releases, but the case of today is unusual.

πŸ€·β€β™‚οΈ Why is it a patch if so much changes?

That's simple, because this release has only one change of putout core, and this is a fix of a bug related to converting ESM to CommonJS and vice versa, which are enabled by default for some time 🎈.

To the point! When there is no .putout.json file but there is package.json with type=module rule convert-commonjs-to-esm was disabled (!). But it should not so it was a bug 🐜 which is proudly fixed with https://github.com/coderaiser/putout/commit/4121ffabac657ae1d42f7e27e89aac03b79dd70f.

🐊 Putout has new rules

Adding new rules never was a major change, especially when plugin added for a long time, and rules are small, but very useful addition. So @putout/plugin-tape made for supertape, mock-import and overall writing tests more pleasant, has a couple new gamers πŸ”₯:

convert-deep-equal-to-equal

Use equal when comparing with primitives, deepEqual for Objects and Arrays;

❌ Incorrect code example

const test = require('supertape');
const {stub} = test;

test('some message', (t) => {
    t.deepEqual(x, 5);
    t.end();
});

βœ… Correct code example

const test = require('supertape');
const {stub} = test;

test('some message', (t) => {
    t.equal(x, 5);
    t.end();
});

convert-equal-to-called-once

No need to use equal, supertape supports calledOnce.

❌ Incorrect code example

const test = require('supertape');
const {stub} = test;

test('some message', (t) => {
    const fn = stub();
    
    fn();
    
    t.equal(fn.callCount, 1);
    t.end();
});

βœ… Correct code example

const test = require('supertape');
const {stub} = test;

test('some message', (t) => {
    const fn = stub();
    
    fn();
    
    t.calledOnce(fn);
    t.end();
});

add-stop-all

When you write test mocking ESM with mockImport() never forget to call stopAll() when you no longer need it. This leads to bugs in tests which are hard to find, each test should be checked with the one which pass when called alone but fail when called with others.

❌ Incorrect code example

test('stop-all: should be called', () => {
    mockImport('fs/promises', {
        readFile: stub(),
    });
    
    t.end();
});

βœ… Correct code example

test('stop-all: should be called', () => {
    mockImport('fs/promises', {
        readFile: stub(),
    });
    
    stopAll();
    
    t.end();
});

There was also plenty of fixes and improvements of plugins, more info hereπŸ‘‡.

🐞 fix

  • (putout) parse-options: convert to esm/commonjs when no .putout.json found, but package.json
  • (@putout/plugin-tape) convert-deep-equal-to-equal: exclude regexp
  • (@putout/plugin-tape) add-t-end: t.end() not last operation
  • (@putout/cli-match) match exists with the same pattern
  • (@putout/plugin-merge-destructuring-properties) add crawl for @putout/plugin-putout/declare

πŸ”₯ feature

  • (@putout/plugin-convert-commonjs-to-esm) commons: report: improve message
  • (@putout/plugin-convert-commonjs-to-esm) commons: add support of top level require
  • (@putout/plugin-convert-commonjs-to-esm) require: exclude package.json
  • (@putout/plugin-tape) declare-t: add support of upper scope
  • (@putout/plugin-tape) add convert-deep-equal-to-equal
  • (@putout/plugin-tape) add convert-equal-to-called-once
  • (@putout/plugin-convert-equal-to-not-ok) add support of undefined
  • (@putout/plugin-tape) convert-equal-to-ok: report: more details
  • (@putout/plugin-tape) convert-equal-to-not-ok: report: more details
  • (@putout/plugin-tape) convert-equal-to-not-ok: add support of deep-equal
  • (@putout/plugin-tape) convert-equal-to-ok: add support of t.deepEqual()
  • (@putout/plugin-putout) apply-processors-destructuring: add support of t.end()
  • (@putout/plugin-putout) apply-processors-destructuring: add support of noProcess
  • (@putout/plugin-tape) add-t-end: add support of async
  • (@putout/plugin-tape) add add-stop-all
  • (@putout/plugin-putout) declare: add template
  • (@putout/plugin-declare-undefined-variables) add support of path from node.js
putout - putout v20.5.1

Published by coderaiser about 3 years ago

πŸ”₯ feature

  • (package) @putout/plugin-declare-undefined-variables v4.1.0
putout - putout v20.5.0

Published by coderaiser about 3 years ago

🐞 fix

  • (@putout/test) leack of plugins used in t.transform()
  • (@putout/plugin-tape) apply-with-name: not declared
  • (@putout/plugin-declare-undefined-variables) get back record, to have eslint-plugin-putout support

πŸ”₯ feature

  • (package) @putout/compare v8.0.0
  • (package) @putout/traverse v4.0.0
  • (@putout/traverse) drop support of node < 14
  • (@putout/compare) getTemplateValues: add validation of input
  • (@putout/plugin-tape) add remove-useless-t-end
  • (@putout/plugin-putout) declare: add addTemplateValues
  • (@putout/plugin-tape) add-t-end
  • (@putout/plugin-declare-undefined-variables) add support of once
  • (@putout/plugin-putout) declare add precalculated json with types (@putout/plugin-declare-undefined-variables v4.0.0)
  • (@putout/plugin-declare-undefined-variables) add fs/promises
  • (@putout/plugin-declare-undefined-variables) add support of noop
  • (@putout/plugin-declare-undefined-variables) simplify declarations
  • (@putout/plugin-tape) add sync-with-name
  • (@putout/plugin-tape) add apply-with-name
  • (@putout/plugin-declare-undefined-variables) add support of Object.defineProperty
putout - putout v20.4.0

Published by coderaiser about 3 years ago

πŸ”₯ feature

  • (@putout/plugin-remove-useless-new) add
  • (@putout/plugin-putout) declare: types: add support of types checkers provided by babel
  • (@putout/plugin-declare-undefined-variables) add readFileSync, writeFile, writeFileSync
  • (@putout/plugin-declare-undefined-variables) move out node.js API
  • (@putout/plugin-tape) add remove-useless-not-called-args
  • (@putout/plugin-putout) declare: add support of types, isIdentifier
putout - putout v20.3.2

Published by coderaiser about 3 years ago

πŸ”₯ feature

  • (package) @putout/plugin-declare-undefined-variables v3.0.0
  • (package) @putout/plugin-declare-undefined-variables v3.0.0
  • (@putout/plugin-declare-undefined-variables) drop support of putout < 20
  • (@putout/plugin-declare-undefined-variables) speed up using ReferencedIdentifier
  • (@putout/plugin-declare-undefined-variables) add support of isArray
  • (package) @putout/plugin-remove-useless-variables v5.0.0
  • (package) @putout/plugin-tape v3.5.0
  • (package) @putout/plugin-remove-useless-variables v5.0.0
  • (package) @putout/plugin-remove-empty v6.0.0
  • (package) espree v9.0.0
putout - putout v20.3.1

Published by coderaiser about 3 years ago

πŸ”₯ feature

  • (package) @putout/plugin-putout v7.0.0
  • (@putout/plugin-putout) drop support of putout < 20
  • (@putout/plugin-putout) declare: add
  • (@putout/plugin-declare-undefined-variables) add support of lazy building of nodes
  • (@putout/plugin-declare-undefined-variables) export declare
putout - putout v20.3.0

Published by coderaiser about 3 years ago

Autodetect package type

Hi folks! Conversion between ESM and CommonJS package systems became simpler then ever πŸŽ‰

”There is surely nothing other than the single purpose of the present moment. A man’s whole life is a succession of moment after moment. If one fully understands the present moment, there will be nothing else to do, and nothing else to pursue. Live being true to the single purpose of the moment.”

(c) Yamamoto Tsunetomo "Hagakure"

While reading options putout checks package type and if it's empty or commonjs it enables @putout/plugin-convert-esm-to-commonjs. If type=module putout enables @putout/plugin-convert-commonjs-to-esm for *.js files.

🐞 fix

  • (@putout/plugin-convert-esm-to-commonjs) duplicate report

πŸ”₯ feature

  • (@putout/plugin-remove-useless-escape) "\+" -> "+"
  • (@putout/plugin-remove-useless-escape) regexp: add support of slash
  • (putout) add ability to detect package type (module/commonjs) and apply matching converters
  • (@putout/plugin-declare-undefined-variables) values -> Object.values
  • (@putout/plugin-remove-useless-escape) add support of regexp
  • (@putout/plugin-tape) add remove-default-messages
  • (@putout/plugin-tape) convert-match-regexp-to-string: add support of notMatch
  • (@putout/tape) add declare-t
  • (@putout/plugin-tape) convert-called-with-no-args-to-called-with: add support of identifier used as second arg
  • (eslint-plugin-putout) no-unresolved: add support of "main" entry of "package.json"
putout - putout v20.2.0

Published by coderaiser about 3 years ago

🐞 fix

  • chore(nycrc) exclude: fixture -> *fixture

πŸ”₯ feature

  • (eslint-plugin-putout) no-resolve: add support of import directory
  • (putout) export putout/eslint
  • (eslint-plugin-putout) add no-unresolved
  • (@putout/plugin-declare-undefined-variables) add support of basename, dirname, extname from path
  • (package) @putout/plugin-remove-useless-async v4.0.0
  • (@putout/plugin-remove-useless-async) drop support of node < 14
  • (@putout/plugin-remove-useless-async) report: Useless async should be avoided -> Avoid useless async
  • (@putout/plugin-declare-undefined-variables) add support of reImport, stopAll
  • (@putout/plugin-remove-duplicate-keys) add support of rename while destructuring
  • (eslint-plugin-putout) safe: disable remove-unused-for-of-variables
putout - putout v20.1.0

Published by coderaiser about 3 years ago

Help is getting better πŸŽ‰

”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

A little bit magic from @egilll and now we have Applying a single rule chapter and putout --help looks this way 🎈 :

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 list]    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 [file name]         read .putout.json and convert 'rules' to 'match' using 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

🐞 fix

  • (eslint-plugin-putout) putout/ide -> putout/safe

πŸ”₯ feature

  • (help) improve help (#81) (thanks a lot to @egilll πŸŽ‰!)
  • (@putout/plugin-declare-undefined-variables) add support of Object.keys
  • (@putout/plugin-tape) add convert-called-with-args
  • (@putout/engine-loader) add ☝️ when cannot determine plugin type
  • (@putout/engine-runner) add support of "include" not a function in Includer
  • (package) @putout/plugin-eslint v2.0.0
  • (@putout/plugin-eslint) drop support of putout < 20
  • (@putout/plugin-eslint) add convert-ide-to-safe
putout - putout v20.0.1

Published by coderaiser about 3 years ago

🐞 fix

  • (eslint-plugin-putout) putout/ide -> putout/safe

πŸ”₯ feature

  • (package) @putout/plugin-eslint v2.0.0
  • (@putout/plugin-eslint) drop support of putout < 20
  • (@putout/plugin-eslint) add covert-ide-to-safe
  • (@putout/engine-loader) parse-rules: validation: add ☝️
  • (package) eslint-plugin-putout v10.0.0
putout - Putout v20

Published by coderaiser about 3 years ago

Hi folks πŸŽ‰!

This release has not much breaking changes, but mostly clean up of exports section of package.json, clean up of help, adding peaces of documentation, and improving error handling. More on this belowπŸ‘‡.

Among the maxims on Lord Naoshige’s wall there was this one: β€˜β€˜Matters of great concern should be treated lightly.” Master lttei commented, β€œMatters of small concern should be treated seriously.”

(c) Yamamoto Tsunetomo β€œHagakure”

☣️ Breaking changes

putout/lib/parse-options -> putout/parse-options in exports of package.json

Since Visual Code already supports node v14 there is no reason to keep an alias (https://github.com/coderaiser/putout/issues/48).

putout/ide -> putout/safe in eslint-plugin-putout

eslint-plugin-putout preset ide was renamed to safe:

{
    "extends": [
-        "plugin:putout/ide"
+        "plugin:putout/safe"
    ],
    "plugins": [
        "putout"
    ]
}

Do you think that you need to make changes by hand :)? Worry not! Putout get you covered with @putout/plugin-eslint rule convert-ide-to-safe πŸŽ‰ .

🧹 Help cleanup

From --help output was removed a couple default options:

--no-flow                   disable flow (default)
--cache                     enable cache to speed up processing (default)

Since they do nothing πŸ€·β€β™‚οΈ.

πŸ”₯ Exit Codes

There is a bunch of exit codes used by Putout internally, the time is came to document all of them, you can find it in section Exit Codes, and import in your code with:

import {OK} from 'putout/exit-codes';

πŸ‘‡ Validate options passed to nested plugins

While working with ESTrace @retorquere trap into a problem:

const putout = require('putout')
const fs = require('fs')

async function main() {
    const estrace = await import('estrace/plugin');
    const source = { code: fs.readFileSync('./hello.js', 'utf-8') }
    const {code} = putout(source.code, {
        fixCount: 1,
        rules: {
            'estrace/trace': ['on', {
                url: './hello.js',
                exclude: [ 'FunctionExpression', 'ArrowFunctionExpression' ]
            }],
        },
        plugins: [
            [ 'estrace/trace', estrace ],
        ],
    });
    
    console.log(code)
}

The thing is when plugin used with a name estrace/trace and the rule has the same name, and the rule is nested, options go's nowhere.
This behavior was fixed, and now putout throws with:

Error: ☝️Rule "estrace/trace" cannot be applied to nested plugin "estrace/trace"
    at module.exports (/Users/coderaiser/putout/packages/engine-loader/lib/validate-rules.js:25:23)
    at module.exports.loadPlugins (/Users/coderaiser/putout/packages/engine-loader/lib/index.js:84:5)
    at transform (/Users/coderaiser/estrace/node_modules/putout/lib/putout.js:93:21)
    at module.exports (/Users/coderaiser/estrace/node_modules/putout/lib/putout.js:53:20)
    at main (/Users/coderaiser/estrace/1.cjs:7:18)

Fix is changed plugin name to estrace or changing rule to estrace/trace/trace.

☝️ Improved error message when visitor provided to Traverser is not a function

When you forgot to pass a function to Traverser visitor:

module exports.traverse: () => ({
    'async (__a) => __b': 'async ({process}) => __b',
}),

You will see something like this:

☝️ Looks like provided visitor is not a function: "async ({process}) => __b". More on using Traverser: https://git.io/JqcMn

And even more! @putout/plugin-putout get you covered with: convert-traverse-to-replace rule.

So most likely [Replacer](Traverser was meant to be used:

module exports.replacer: () => ({
    'async (__a) => __b': 'async ({process}) => __b',
}),

Added 🐊 to error messages

Now, when you have a typo, or trap on something not obvious, Putout will not only help you, but also show how it looks like: 🐊.

coderaiser@localcmd:~/putout/packages$ putout --helo
🐊 Invalid option `--helo`. Perhaps you meant `--help`

πŸ’£ Improved documentation of @putout/test

That's right, @putout/test now has examples to all provided API 🎈 .

🐞 fix

  • (eslint-plugin-putout) package: description: plagin -> plugin
  • (putout) export: putout/lib/parse-options -> putout/parse-options (#48)
  • (@putout/plugin-putout-config) examples
  • (@putout/test) homepage
  • (@putout/engine-runner) rm "☝️ " -> "☝️""
  • docs(@putout/test) add Autofix

πŸ”₯ feature

  • (eslint-plugin-putout) drop support of putout < 20
  • (putout) add ability to import exit codes enum
  • (package) improve description
  • (putout) help: remove enabled by default options
  • (putout) cli: add 🐊 to error messages
  • (putout) cli: add ability to exit with error when ruler toggler used without a path
  • (@putout/plugin-putout-config) add remove-empty
  • (@putout/plugin-putout) add apply-processors-destructuring
  • (@putout/engine-runner) add ☝️
  • (@putout/plugin-putout) add convert-traverse-to-replace
  • (@putout/engine-runner) improve error message when visitor provided to Traverser is not a function (https://github.com/coderaiser/putout/tree/v19.7.1/packages/engine-runner#traverser)
  • (eslint-plugin-putout) ide: disable remove-unused-expressions
  • (@putout/plugin-tape) add convert-called-with-no-args-to-called-with
  • (@putout/plugin-putout) check-replace-code: __array: add support of CallExpression
  • (@putout/engine-loader) validate-rules: throw when passing options to nested plugin (instead of go nowhere) (coderaiser/estrace#4)
  • (@putout/engine-runner) throw error when no visitor
Package Rankings
Top 1.65% on Npmjs.org
Badges
Extracted from project README
NPM version Build Status Coverage Status DeepScan putout npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm npm