# @putout/plugin-putout [![NPM version][NPMIMGURL]][NPMURL] [NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-putout.svg?style=flat&longCache=true [NPMURL]: https://npmjs.org/package/@putout/plugin-putout "npm" 🐊[**Putout**](https://github.com/coderaiser/putout) plugin helps with plugins development. ## Install ``` npm i @putout/plugin-putout -D ``` ## Rules - ✅ [add-await-to-progress](#add-await-to-progress); - ✅ [add-crawl-file](#add-crawl-file); - ✅ [add-path-arg-to-filter](#add-path-arg-to-filter); - ✅ [add-path-arg-to-fix](#add-path-arg-to-fix); - ✅ [add-path-arg-to-match](#add-path-arg-to-match); - ✅ [add-path-arg-to-visitors](#add-path-arg-to-visitors); - ✅ [add-places-to-compare-places](#add-places-to-compare-places); - ✅ [add-push-arg](#add-push-arg); - ✅ [add-test-args](#add-test-args); - ✅ [add-track-file](#add-track-file); - ✅ [add-traverse-args](#add-traverse-args); - ✅ [apply-async-formatter](#apply-async-formatter); - ✅ [apply-create-nested-directory](#apply-create-nested-directory); - ✅ [apply-create-test](#apply-create-test); - ✅ [apply-declare](#apply-declare); - ✅ [apply-destructuring](#apply-destructuring); - ✅ [apply-destructuring-to-options](#apply-destructuring); - ✅ [apply-engine-node-version](#apply-engine-node-version); - ✅ [apply-exports](#apply-exports); - ✅ [apply-exports-to-add-args](#apply-exports-to-add-args); - ✅ [apply-exports-to-match-files](#apply-exports-to-match-files); - ✅ [apply-exports-to-rename-files](#apply-exports-to-rename-files); - ✅ [apply-fixture-name-to-message](#apply-fixture-name-to-message); - ✅ [apply-for-of-to-track-file](#apply-for-of-to-track-file); - ✅ [apply-get-binding](#apply-get-binding); - ✅ [apply-insert-after](#apply-insert-after); - ✅ [apply-insert-before](#apply-insert-before); - ✅ [apply-lowercase-to-node-builders](#apply-lowercase-to-node-builders); - ✅ [apply-name-to-is-identifier](#apply-name-to-is-identifier); - ✅ [apply-namespace-specifier](#apply-namespace-specifier); - ✅ [apply-parens](#apply-parens); - ✅ [apply-processors-destructuring](#apply-processors-destructuring); - ✅ [apply-remove](#apply-remove); - ✅ [apply-rename](#apply-rename); - ✅ [apply-report](#apply-report); - ✅ [apply-short-processors](#apply-short-processors); - ✅ [apply-string-to-property-key](#apply-string-to-property-key); - ✅ [apply-transform-with-options](#apply-transform-with-options); - ✅ [apply-traverser-to-ignore](#apply-traverser-to-ignore); - ✅ [apply-type-check](#apply-type-check); - ✅ [apply-vars](#apply-vars); - ✅ [check-declare](#check-declare); - ✅ [check-match](#check-match); - ✅ [check-replace-code](#check-replace-code); - ✅ [convert-add-argument-to-add-args](#convert-add-argument-to-add-test-args); - ✅ [convert-babel-types](#convert-babel-types); - ✅ [convert-destructuring-to-identifier](#convert-destructuring-to-identifier); - ✅ [convert-dirname-to-url](#convert-dirname-to-url); - ✅ [convert-find-to-traverse](#convert-find-to-traverse); - ✅ [convert-get-file-content-to-read-file-content](#convert-get-file-content-to-read-file-content); - ✅ [convert-get-rule-to-require](#convert-get-rule-to-require); - ✅ [convert-include-to-traverse](#convert-include-to-traverse); - ✅ [convert-match-to-function](#convert-match-to-function); - ✅ [convert-method-to-property](#convert-method-to-property); - ✅ [convert-node-to-path-in-get-template-values](#convert-node-to-path-in-get-template-values); - ✅ [convert-number-to-numeric](#convert-number-to-numeric); - ✅ [convert-plugins-element-to-tuple](#convert-plugins-element-to-tuple); - ✅ [convert-process-to-find](#convert-process-to-find); - ✅ [convert-progress-to-track-file](#convert-progress-to-track-file); - ✅ [convert-push-object-to-push-path](#convert-push-object-to-push-path); - ✅ [convert-putout-test-to-create-test](#convert-putout-test-to-create-test); - ✅ [convert-replace-to-function](#convert-replace-to-function); - ✅ [convert-replace-to-traverse](#convert-replace-to-traverse); - ✅ [convert-replace-with](#convert-replace-with); - ✅ [convert-replace-with-multiple](#convert-replace-with-multiple); - ✅ [convert-replacer-to-includer](#convert-replacer-to-includer); - ✅ [convert-report-to-function](#convert-report-to-function); - ✅ [convert-to-no-transform-code](#convert-to-no-transform-code); - ✅ [convert-traverse-to-include](#convert-traverse-to-include); - ✅ [convert-traverse-to-replace](#convert-traverse-to-replace); - ✅ [convert-traverse-to-scan](#convert-traverse-to-scan); - ✅ [convert-traverse-to-super-traverse](#convert-traverse-to-super-traverse); - ✅ [convert-url-to-dirname](#convert-url-to-dirname); - ✅ [create-test](#create-test); - ✅ [declare](#declare); - ✅ [declare-path-variable](#declare-path-variable); - ✅ [declare-template-variables](#declare-template-variables); - ✅ [includer](#includer); - ✅ [move-require-on-top-level](#move-require-on-top-level); - ✅ [remove-empty-array-from-process](#remove-empty-array-from-process); - ✅ [remove-empty-object-from-transform](#remove-empty-object-from-transform); - ✅ [remove-message-from-no-report-after-transform](#remove-message-from-no-report-after-transform); - ✅ [remove-unused-get-properties-argument](#remove-unused-get-properties-argument); - ✅ [remove-useless-match](#remove-useless-match); - ✅ [remove-useless-printer-option](#remove-useless-printer-option); - ✅ [remove-useless-source-argument](#remove-useless-source-argument); - ✅ [remove-useless-type-check-declaration](#remove-useless-type-check-declaration); - ✅ [rename-operate-to-operator](#rename-operate-to-operator); - ✅ [replace-operate-with-operator](#replace-operate-with-operator); - ✅ [replace-test-message](#replace-test-message); - ✅ [shorten-imports](#shorten-imports); - ✅ [shorten-path-get](#shorten-path-get); - ✅ [simplify-replace-template](#simplify-replace-template); ## File rules - ✅ [sort-readme-file](#sort-readme-file); ## Config ```json { "rules": { "putout/add-await-to-progress": "on", "putout/add-crawl-file": "on", "putout/add-path-arg-to-filter": "on", "putout/add-path-arg-to-fix": "on", "putout/add-path-arg-to-match": "on", "putout/add-path-arg-to-visitors": "on", "putout/add-places-to-compare-places": "on", "putout/add-push-arg": "on", "putout/add-test-args": "on", "putout/add-track-file": "on", "putout/add-traverse-args": "on", "putout/apply-async-formatter": "on", "putout/apply-create-nested-directory": "on", "putout/apply-create-test": "on", "putout/apply-declare": "on", "putout/apply-destructuring": "on", "putout/apply-destructuring-to-options": "on", "putout/apply-engine-node-version": "off", "putout/apply-exports": "off", "putout/apply-exports-to-add-args": "on", "putout/apply-exports-to-match-files": "on", "putout/apply-exports-to-rename-files": "on", "putout/apply-fixture-name-to-message": "on", "putout/apply-for-of-to-track-file": "on", "putout/apply-get-binding": "on", "putout/apply-insert-after": "on", "putout/apply-insert-before": "on", "putout/apply-lowercase-to-node-builders": "on", "putout/apply-name-to-is-identifier": "on", "putout/apply-namespace-specifier": "on", "putout/apply-parens": "on", "putout/apply-processors-destructuring": "on", "putout/apply-remove": "on", "putout/apply-rename": "on", "putout/apply-report": "on", "putout/apply-short-processors": "on", "putout/apply-string-to-property-key": "on", "putout/apply-transform-with-options": "on", "putout/apply-traverser-to-ignore": "on", "putout/apply-type-check": "on", "putout/apply-vars": "on", "putout/check-declare": "on", "putout/check-match": "on", "putout/check-replace-code": ["on", { "once": true }], "putout/convert-add-argument-to-add-args": "on", "putout/convert-babel-types": "on", "putout/convert-destructuring-to-identifier": "on", "putout/convert-dirname-to-url": "on", "putout/convert-get-file-content-to-read-file-content": "on", "putout/convert-get-rule-to-require": "on", "putout/convert-include-to-traverse": "on", "putout/convert-match-to-function": "on", "putout/convert-method-to-property": "on", "putout/convert-node-to-path-in-get-template-values": "on", "putout/convert-number-to-numeric": "on", "putout/convert-plugins-element-to-tuple": "on", "putout/convert-process-to-find": "on", "putout/convert-progress-to-track-file": "on", "putout/convert-push-object-to-push-path": "on", "putout/convert-putout-test-to-create-test": "on", "putout/convert-replace-to-function": "on", "putout/convert-replace-to-traverse": "on", "putout/convert-replace-with": "on", "putout/convert-replace-with-multiple": "on", "putout/convert-replacer-to-includer": "on", "putout/convert-report-to-function": "on", "putout/convert-to-no-transform-code": "on", "putout/convert-traverse-to-include": "on", "putout/convert-traverse-to-replace": "on", "putout/convert-traverse-to-scan": "on", "putout/convert-traverse-to-super-traverse": "on", "putout/convert-url-to-dirname": "on", "putout/create-test": "on", "putout/declare": "on", "putout/declare-path-variable": "on", "putout/declare-template-variables": "on", "putout/includer": "on", "putout/move-require-on-top-level": "on", "putout/remove-empty-array-from-process": "on", "putout/remove-empty-object-from-transform": "on", "putout/remove-message-from-no-report-after-transform": "on", "putout/remove-unused-get-properties-argument": "on", "putout/remove-useless-match": "on", "putout/remove-useless-printer-option": "on", "putout/remove-useless-source-argument": "on", "putout/remove-useless-type-check-declaration": "on", "putout/replace-test-message": "on", "putout/shorten-imports": "on", "putout/shorten-path-get": "on", "putout/simplify-replace-template": "on", "putout/sort-readme-file": "on" } } ``` ## add-await-to-progress Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/978d70945edfa369390ea059654ff04d/89225c04039b9c0e9057aad34852c9428264f119). ### ❌ Example of incorrect code ```js const {replaceWith} = require('putout').operator; module.exports.fix = (path) => { replaceWith(path, identifier('hello')); }; ``` ### ✅ Example of correct code ```js module.exports.fix = (path) => { path.replaceWithMultiple([ identifier('hello'), ]); }; ``` ## add-crawl-file Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/4faf27234e9c5616444d0cabd79f00be/aac768e7150635d96cd71507e4a6eb43d0899814). ### ❌ Example of incorrect code ```js const {replaceWithMultiple} = require('putout').operator; module.exports.fix = (path) => { replaceWithMultiple(path, [ identifier('hello'), ]); }; ``` ### ✅ Example of correct code ```js module.exports.replace = { 'let __a = __b': 'const __b = __a', }; ``` ## add-path-arg-to-filter Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/00a5e23e6a1a708937ef3fae2a792f86/c2fc350831f777bbb383fb65216b349edd4ec53d). ### ❌ Example of incorrect code ```js createTest(__dirname, { printer: 'putout', plugins: [ ['putout/create-test', plugin], ], }); ``` ### ✅ Example of correct code ```js const {isNumberLiteral} = types; isNumberLiteral(node); ``` ## add-path-arg-to-fix Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/3d3fb6b8f5e5376cdd1674c9b19e0e27/4872f77e680a2fc443618f4bf5fae3ffab11046a). ### ❌ Example of incorrect code ```js __putout_processor_json({ rules: { 'putout/create-test': ['on', { add: [ ['printer', 'putout'], ], }], }, }); ``` ### ✅ Example of correct code ```js createTest(__dirname, { 'putout/create-test': plugin, }); ``` ## add-path-arg-to-match Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/35189d0e47c6ad1ca369e5a9287a34c1/d5fa7513a44fecc86beabd1faa8542bee7bc3e5e). ### ❌ Example of incorrect code ```js const {isNumericLiteral} = types; isNumericLiteral(node); ``` ### ✅ Example of correct code ```js import putoutTest from '@putout/test'; const test = putoutTest(__dirname, { 'remove-unused-variables': rmVars, }); ``` ## add-path-arg-to-visitors Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e20eb16668b2ebbceca1a03cde859e93/fee08d6dbb6aa4d835adacc8e9de4d994fd34848). ### ❌ Example of incorrect code ```js import {createTest} from '@putout/test'; const test = createTest(__dirname, { 'remove-unused-variables': rmVars, }); ``` ### ✅ Example of correct code ```js t.transform('nested-not-block', [ ['convert-if-to-jmp', convertIfToJmp], convertDoWhileToJnz, ]); ``` ## add-push-arg Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/cae7b14fa6be0fe50b134839bea1e544/37f9d161146dbe4f0497f852ba54161a759f7cbd). ### ❌ Example of incorrect code ```js t.transform('nested-not-block', [ ['convert-if-to-jmp', convertIfToJmp], ['convert-do-while-to-jnz', convertDoWhileToJnz], ]); ``` ### ✅ Example of correct code ```js export const fix = ({path}) => { removeClassName(path, SELECTED); }; push({ path: child, }); ``` ## add-test-args ### ❌ Example of incorrect code ```js export const fix = (path) => { removeClassName(path, SELECTED); }; push(child); ``` ### ✅ Example of correct code ```js test('plugin-apply-destructuring: transform: array: destructuring', (t) => { const code = 'const {name} = array[0]'; t.transform(code, ''); t.end(); }); ``` ## add-track-file Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/faaba1ce41e6fd274bc82a8875a52bfa/b34a22fdf9080e6b2f06703760f629d83d69ff3d). ### ❌ Example of incorrect code ```js module.exports.replace = () => ({ 'let __a = __b': 'const __b = __a', }); ``` ### ✅ Example of correct code ```js export const fix = () => {}; export const replace = () => ({ [__json]: (path) => { const __aPath = path.get('arguments.0'); const {importsPath} = getProperties(__aPath, ['imports']); }, }); ``` ## add-traverse-args Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b453bd78b8e9380da8b2f33dfb38b4e2/53b14f89eb88aa10c8e00ba1f0251976592e14ee). Supported args: - `push`: ### ❌ Example of incorrect code ```js test('plugin-apply-destructuring: transform: array: destructuring', (t) => { const code = 'const {name} = array[0]'; t.noTransformCode(code); t.end(); }); ``` ### ✅ Example of correct code ```js module.exports.fix = (path) => { path.replaceWith(identifier('hello')); }; ``` ## apply-async-formatter ### ❌ Example of incorrect code ```js test('formatter: codeframea', (t) => { t.format(codeframe, 1); t.end(); }); ``` ### ✅ Example of correct code ```js test('formatter: codeframea', async ({format}) => { await format(codeframe, 1); }); ``` ## apply-create-nested-directory Checkout in [**Putout Editor**](https://putout.cloudcmd.io/#/gist/d97578b334963b2f573d1980a61034de/0b876a781268916344fa0ed4c19bdbc9fd7bbc3f). ### ❌ Example of incorrect code ```js const dirPath = createDirectory(path, '/hello/world'); const dirPath2 = createNestedDirectory(path, 'world'); ``` ### ✅ Example of correct code ```js const dirPath = createNestedDirectory(path, '/hello/world'); const dirPath2 = createDirectory(path, 'world'); ``` ## apply-create-test ### ❌ Example of incorrect code ```js const test = require('@putout/test')({ 'remove-debugger': plugin, }); ``` ### ✅ Example of correct code ```js const {createTest} = require('@putout/test'); const test = createTest({ 'remove-debugger': plugin, }); ``` ## apply-declare Better to use [`Declareator`](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#declarator) instead of `operator.declare()`. Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/cf35de5e80e8f7aad866358a50c5eded/0af6142fc9c9e71ac2a2aa96cb85613dd95c9fbf). ### ❌ Example of incorrect code ```js const {operator} = require('putout'); const {declare} = operator; module.exports = declare({ tryCatch: `import tryCatch from 'try-catch'`, tryToCatch: `import tryToCatch from 'try-to-catch'`, }); ``` ### ✅ Example of correct code ```js module.exports.declare = () => ({ tryCatch: `import tryCatch from 'try-catch'`, tryToCatch: `import tryToCatch from 'try-to-catch'`, }); ``` ## apply-destructuring Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/16fb7b414f23b9ed81bef4f5275d921e/e12e3a7c57868e623b2c11d19de1adbf1f5e3569). ### ❌ Example of incorrect code ```js const putout = require('putout'); ``` ### ✅ Example of correct code ```js const {putout} = require('putout'); ``` ## apply-destructuring-to-options Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/44f02be3d5b1fcef7dec27edf7bb0016/75e4443ff82350af1b85106af87e488dba1cf178). ### ❌ Example of incorrect code ```js export const filter = (path, options) => {}; ``` ### ✅ Example of correct code ```js export const filter = (path, {options}) => {}; ``` ## apply-engine-node-version Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/7ed4860732476de489ae149c7f09e2fe/d8b6e131596c0888ec8b99d4728cd999b17165c9). ```diff { "name": "@putout/plugin-variables", "peerDependencies": { "putout": ">=41" }, "license": "MIT", "engines": { - "node": ">=20" + "node": ">=22" } } ``` ## apply-exports Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/cf35de5e80e8f7aad866358a50c5eded/0af6142fc9c9e71ac2a2aa96cb85613dd95c9fbf). Possible configuration: ```json { "rules": { "putout/apply-exports": ["on", { "addArgs": [ "report", "fix", "scan" ] }] } } ``` ### ❌ Example of incorrect code ```js export default createRenameProperty([ ...v32, ...v29, ]); ``` ### ✅ Example of correct code ```js export const { report, fix, scan, } = createRenameProperty([ ...v32, ...v29, ]); ``` ## apply-exports-to-add-args Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/cf35de5e80e8f7aad866358a50c5eded/0af6142fc9c9e71ac2a2aa96cb85613dd95c9fbf). ### ❌ Example of incorrect code ```js export default addArgs(__args); ``` ### ✅ Example of correct code ```js export const { report, fix, traverse, } = addArgs(__args); ``` ## apply-exports-to-match-files Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d40ac85b974249c51f9874919468fd30/4194c9b21d065bd1359ffc7298aaeb1835fbbb48). ### ❌ Example of incorrect code ```js export default matchFiles({ '*.cjs': plugin, }); ``` ### ✅ Example of correct code ```js export const { report, fix, scan, } = matchFiles({ '*.cjs': plugin, }); ``` ## apply-exports-to-rename-files Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/999f7a582825fa88691ba87324365f3f/c679723b7ff2159d738ab7681f8c7c6460dd4326). ### ❌ Example of incorrect code ```js export default renameFiles({ type: 'module', mask: '*.mjs', rename(name) { return name.replace(/mjs$/, 'js'); }, }); ``` ### ✅ Example of correct code ```js export const { report, fix, scan, } = renameFiles({ type: 'module', mask: '*.mjs', rename(name) { return name.replace(/mjs$/, 'js'); }, }); ``` ## apply-for-of-to-track-file > The **Generator** object is returned by a `generator function` and it conforms to both the iterable protocol and the `iterator` protocol. > > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator) `trackFile` is generator function used to count progress that can be used in [**Scanner**](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#scanner). Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/5ec6c384aa6e4471aab17efb86e185f3/e749c7d649ef2da76410a5964e7c875d10538789) ### ❌ Example of incorrect code ```js module.exports.scan = (path, {push, trackFile}) => { trackFile(path, '*.swp').map(push); }; ``` ### ✅ Example of correct code ```js module.exports.scan = (path, {push, trackFile}) => { for (const file of trackFile(path, '*.swp')) { push(file); } }; ``` ## apply-get-binding Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/6c82eac69034a1bb10405aec9d0c9df1/acc0ced44417671f1af60b84f4d9707c735365f0). ### ❌ Example of incorrect code ```js path.scope.getBinding('require'); ``` ### ✅ Example of correct code ```js getBinding(path, 'require'); ``` ## apply-insert-after Better to use [`insertAfter(a, b)`](https://github.com/coderaiser/putout/tree/master/packages/operate#insert-after) method of `operator`. It helps to avoid duplication of comments. ### ❌ Example of incorrect code ```js export const fix = (path) => { path.insertAfter(path.get('init')); }; ``` ### ✅ Example of correct code ```js import {operator} from 'putout'; const {insertAfter} = operator; export const fix = (path) => { insertAfter(path, path.get('init')); }; ``` ## apply-insert-before Better to use [`insertBefore(a, b)`](https://github.com/coderaiser/putout/tree/master/packages/operate#insert-before) method of `operator`. ### ❌ Example of incorrect code ```js export const fix = (path) => { path.insertBefore(path.get('init')); }; ``` ### ✅ Example of correct code ```js import {operator} from 'putout'; const {insertBefore} = operator; export const fix = (path) => { insertBefore(path, path.get('init')); }; ``` ## apply-lowercase-to-node-builders Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/fe78f6e48998fb39fa7e53e4046f1fc0/e1e6f2387895ff2ab98b4a9bcd2e8d565f7c3f16). ### ❌ Example of incorrect code ```js path.node = Identifier('x'); ``` ### ✅ Example of correct code ```js path.node = identifier('x'); ``` ## apply-name-to-is-identifier Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9d416e21377a53ef13066007f7037bdf/e179718fe1908851c26f10ba84fab1bf7ebca3ce). ### ❌ Example of incorrect code ```js isIdentifier(path, 'hello'); ``` ### ✅ Example of correct code ```js isIdentifier(path, { name: 'hello', }); ``` ## apply-namespace-specifier Most likely what you need is [`esm/resolve-imported-file`](https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#resolve-imported-file). ### ❌ Example of incorrect code ```js import rmUnused from '@putout/plugin-remove-unused-variables'; ``` ### ✅ Example of correct code ```js import * as rmUnused from '@putout/plugin-remove-unused-variables'; ``` ## apply-parens Better use [`addParens(path)`](https://github.com/coderaiser/putout/tree/master/packages/operate#addparenspath-path) method of `operator` instead of using `path.node.extra` to have support of both printers: - ✅ `@putout/printer`; - ✅ `babel`; Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d325a84e26807d46b5ec14db179c38f4/8bcd22d6dbe880c0fd70992a1a36b9c609b53b22). ### ❌ Example of incorrect code ```js path.node.extra.parenthesized = false; path.node.extra.parenthesized = true; if (!path.node.extra?.parenthesized) return; ``` ### ✅ Example of correct code ```js removeParens(path); addParens(path); if (!hasParens(path)) return; ``` ## apply-processors-destructuring ### ❌ Example of incorrect code ```js test('', async (t) => { await t.process({}); }); ``` ### ✅ Example of correct code ```js test('', async ({process}) => { await process({}); }); ``` ## apply-processors-destructuring ### ❌ Example of incorrect code ```js test('', async (t) => { await t.process({}); }); ``` ### ✅ Example of correct code ```js test('', async ({process}) => { await process({}); }); ``` ## apply-remove Better to use [`remove(path)`](https://github.com/coderaiser/putout/tree/master/packages/operate#removepath) method of `operator`. It helps to preserve comments. ### ❌ Example of incorrect code ```js export const fix = (path) => { path.remove(); }; ``` ### ✅ Example of correct code ```js import {operator} from 'putout'; const {remove} = operator; export const fix = (path) => { remove(path); }; ``` ## apply-rename Better use [`rename(path, from, to)`](https://github.com/coderaiser/putout/tree/master/packages/operate#rename) method of `operator`. Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/22716f61af86351331fc92260b7ed8e6/1435f31954764c119813e03654caa36e6a2a666b). ### ❌ Example of incorrect code ```js export const fix = ({path, from, to}) => { path.scope.rename(from, to); }; ``` ### ✅ Example of correct code ```js import {operator} from 'putout'; const {rename} = operator; export const fix = ({path, from, to}) => { rename(path, from, to); }; ``` ## apply-report Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e9debc0b256556a632fb031be86afffc/afefbd44443f07dbb7d8f2972f2e40a9a82c214f). ### ❌ Example of incorrect code ```js t.noReport('rename-files-full', { from: ['/'], to: [], }); t.noReportWithOptions('rename-files-full'); t.noReport('a', 'Use b'); t.report('a'); ``` ### ✅ Example of correct code ```js t.noReportWithOptions('rename-files-full', { from: ['/'], to: [], }); t.noReport('rename-files-full'); t.report('a', 'Use b'); t.noReport('a'); ``` ## apply-short-processors Apply short names of processors, for example `__json` instead of `__putout_processor_json` . Checkout out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/908151edd3ee8d6a07d589df1e863883/1bd1eeadadea40915a2079f33a3845fa4fedda8e). ### ❌ Example of incorrect code ```js export const match = () => ({ '__putout_processor_ignore(__a)': ({__a}) => { const list = __a.elements.map(getValue); }, '__putout_processor_filesystem(__a)': ({__a}) => { const list = __a.elements.map(getValue); }, }); ``` ### ✅ Example of correct code ```js export const match = () => ({ [__ignore]: ({__array}) => { const list = __array.elements.map(getValue); }, [__filesystem]: ({__object}) => { const list = __object.elements.map(getValue); }, }); ``` ## apply-string-to-property-key Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/46e3930cbdf32d316c0c6cb21eb59f5a/aecd754638d0bac8252048a4f4b3131c15ef6c6f). ### ❌ Example of incorrect code ```js export const replace = { [`section('@select', select(__args))`]: ({__args}, path) => { __args.unshift(identifier('id')); return path; }, }; ``` ### ✅ Example of correct code ```js export const replace = { 'section("@select", select(__args))"': ({__args}, path) => { __args.unshift(identifier('id')); return path; }, }; ``` ## apply-transform-with-options Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/92d40d40c75481816a5b5507e01d8315/bb54e932b4fff4bc0b453d723c72c7a9ed796b98). ### ❌ Example of incorrect code ```js t.transform('submenu', { submenuIndex: 1, insideSubmenu: true, }); ``` ### ✅ Example of correct code ```js t.transformWithOptions('submenu', { submenuIndex: 1, insideSubmenu: true, }); ``` ## apply-traverser-to-ignore Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/ff74cf775696df17a5ba96c7ec309821/1cbdee25af883ccefd0a3614fe8424d8690fc58a). ### ❌ Example of incorrect code ```js export const { report, match, replace, } = ignore({ type: __json, name: '.nycrc.json', field: 'exclude', list: ['*.config.*'], }); ``` ### ✅ Example of correct code ```js export const { report, fix, traverse, } = ignore({ type: __json, name: '.nycrc.json', field: 'exclude', list: ['*.config.*'], }); ``` ## apply-type-check Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/3176ff5d9bfb388723c977735e49d599/00036b9cbd71b1a778c8423e2e7a707abd9f2f1f). ### ❌ Example of incorrect code ```js if (a.type === 'CallExpression') {} ``` ### ✅ Example of correct code ```js if (isCallExpression(a)) {} ``` ## apply-vars Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/6b1a4b5dc75f2591faf580774d23b38f/7278945371ceb76942494f7caf88375d2eaca869). ### ❌ Example of incorrect code ```js export const replace = () => ({ '__a(__args': ({}, path) => { return true; }, }); export const match = () => ({ '__a(__args': ({}, path) => { return ''; }, }); ``` ### ✅ Example of correct code ```js export const replace = () => ({ '__a(__args': (vars, path) => { return true; }, }); export const match = () => ({ '__a(__args': (vars, path) => { return ''; }, }); ``` ## check-declare Checks that [Declarator](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#declarator) transform is possible. Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9fccb187bb8933afff0dc0db57b3cea8/25cb812978fadb4efb5f0cb44058a61f70f8b78e): ### ❌ Example of incorrect code ```js export const match = () => ({ 'nemesis.getChar()': () => { return path.parentPath.isExpressionStatement(); }, 'getChar()': ({__a}) => { return path.parentPath.isExpressionStatement(); }, }); ``` ### ✅ Example of correct code ```js export const match = () => ({ 'nemesis.getChar()': (vars, path) => { return path.parentPath.isExpressionStatement(); }, 'getChar()': ({__a}, path) => { return path.parentPath.isExpressionStatement(); }, }); ``` ## check-match Checks that [Replacer](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#replacer) `match()` keys exists in `replace`. Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/c245bee6b129614b2f68c2e89fc3b101/d9f935ccd7f41ff166111cd62277f3244b1d526e). ### ❌ Example of incorrect code ```js export const scan = (root, {trackFile}) => { for (const file of trackFile(root, names)) { push(file); } }; ``` ### ✅ Example of correct code ```js export const scan = (root, {trackFile, push}) => { for (const file of trackFile(root, names)) { push(file); } }; ``` ## check-replace-code Checks that [Replacer](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#replacer) transform is possible. Pass `once=false` to always fail no matter how many `fixCounts` passed. ### ❌ Example of incorrect code ```js export const traverse = () => ({ TSUnionType() { console.log(path); }, }); ``` ### ✅ Example of correct code ```js export const traverse = () => ({ TSUnionType(path) { console.log(path); }, }); ``` ## convert-add-argument-to-add-args ### ❌ Example of incorrect code ```js test('', () => { comparePlaces(); }); ``` ### ✅ Example of correct code ```js test('', ({comparePlaces}) => { comparePlaces(); }); ``` ## convert-babel-types ### ❌ Example of incorrect code ```js module.exports.preProcess = () => {}; module.exports.postProcess = () => {}; ``` ### ✅ Example of correct code ```js module.exports.branch = (rawSource) => []; module.exports.merge = (processedSource, list) => ''; ``` ## convert-destructuring-to-identifier ### ❌ Example of incorrect code ```js module.exports.match = () => ({ 'module.exports.traverse = __a'({}, path) {}, }); ``` ### ✅ Example of correct code ```js module.exports.match = () => ({ 'module.exports.traverse = __a': ({}, path) => {}, }); ``` ## convert-dirname-to-url ### ❌ Example of incorrect code ```js module.exports.traverse = () => ({ '__a.replace(/__b/g, __c)': (path) => { push(path); }, }); ``` ### ✅ Example of correct code ```js module.exports.traverse = ({push}) => ({ '__a.replace(/__b/g, __c)': (path) => { push(path); }, }); ``` - [`store`](https://github.com/coderaiser/putout/blob/master/packages/engine-runner/README.md#store) ### ❌ Example of incorrect code ```js module.exports.traverse = () => ({ ImportDeclaration(path) { const {node} = path; const {name} = node.specifiers[0].local; store('name', name); }, }); ``` ### ✅ Example of correct code ```js module.exports.traverse = ({store}) => ({ ImportDeclaration(path) { const {node} = path; const {name} = node.specifiers[0].local; store('name', name); }, }); ``` - [`listStore``](https://github.com/coderaiser/putout/blob/master/packages/engine-runner/README.md#liststore) ### ❌ Example of incorrect code ```js export const traverse = () => ({ ImportDeclaration(path) { listStore(path); }, }); ``` ### ✅ Example of correct code ```js module.exports.traverse = ({listStore}) => ({ ImportDeclaration(path) { listStore(path); }, }); ``` - [`pathStore`](https://github.com/coderaiser/putout/blob/master/packages/engine-runner/README.md#pathstore) ### ❌ Example of incorrect code ```js export const traverse = () => ({ 'module.exports.match = __object': pathStore, }); ``` ### ✅ Example of correct code ```js export const traverse = ({pathStore}) => ({ 'module.exports.match = __object': pathStore, }); ``` ## convert-get-file-content-to-read-file-content To read file content use [`readFileContent`](https://github.com/coderaiser/putout/tree/master/packages/operator-filesystem#readfilecontentfilepath-filepath-string) and never confuse. Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/828da75f16a526652b138948d810ed9e/754bd02869a7e4e119e9fb442dab93df7785fb56). ### ❌ Example of incorrect code ```js const {operator} = require('putout'); const {addArgument} = operator; module.exports = addArgument({ t: ['t', 'test("__a", (__args) => __body)'], }); ``` ### ✅ Example of correct code ```js const {operator} = require('putout'); const {addArgs} = operator; module.exports = addArgs({ t: ['t', 'test("__a", (__args) => __body)'], }); ``` ## convert-get-rule-to-require - ✅ import [Nested plugins](https://github.com/coderaiser/putout/tree/master/packages/engine-loader#nested-plugin) in [**Deno** and **Browser**](https://github.com/putoutjs/bundle/); - ✅ easier bundle with rollup without [`dynamicRequireTargets`](https://github.com/rollup/plugins/tree/master/packages/commonjs/#dynamicrequiretargets); - ✅ easier to migrate to **ESM**; Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/38336fcc5b5ae6e441697e098067319c/dd98578c9554b7bd5dceee0499118f7d8216e1da). ### ❌ Example of incorrect code ```js export const scan = (root, {push, progress}) => { trackFile(); }; ``` ### ✅ Example of correct code ```js export const scan = (root, {push, progress, trackFile}) => { trackFile(); }; ``` ## convert-include-to-traverse Checkout in 🐊[**Putout Editor*](https://putout.cloudcmd.io/#/gist/a41b5c943a74b59a6c18f31fc6d31937/d79c6084f49b6444536840bc2fc1fba725ba83f8). ### ❌ Example of incorrect code ```js module.exports.replace = () => ({ 'if (__a = __b) __body': 'if (__a === "__b") __body', }); ``` ☝️ *There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false positives when running on code. This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.* ## convert-match-to-function ### ❌ Example of incorrect code ```js module.exports.traverse = ({push, options}) => ({ [__filesystem](path) { const {names} = options; for (const name of names) { const files = findFile(path, name); for (const file of files) { push({ name, path: file, }); } } }, }); ``` ### ✅ Example of correct code ```js module.exports.scan = (path, {push, options}) => { const {names} = options; for (const name of names) { const files = findFile(path, name); for (const file of files) { push(file, { name, }); } } }; ``` ## convert-method-to-property - property simpler to work with; - support of [`convert-destructuring-to-identifier`](#convert-destructuring-to-identifier) which is `Replacer`, while `convert-method-to-property` is `Includer` (searches for `ObjectMethod` node); ### ❌ Example of incorrect code ```js export const filter = () => { return path.isStringLiteral(); }; ``` ### ✅ Example of correct code ```js export const filter = (path) => { return path.isStringLiteral(); }; ``` ## convert-node-to-path-in-get-template-values ### ❌ Example of incorrect code ```js module.exports.declare = () => ({ isNumber: 'const isNumber = () => {}', isString: 'const isNumber = () => {}', }); ``` ☝️ *There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false positives when running on code. This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.* ## convert-number-to-numeric Prevent `Babel` warning: `The node type NumberLiteral has been renamed to NumericLiteral`. ### ❌ Example of incorrect code ```js const { ObjectExpression, SpreadElement, isObjectExpression, isIdentifier, } = require('@babel/types'); ``` ### ✅ Example of correct code ```js const { ObjectExpression, SpreadElement, isObjectExpression, isIdentifier, } = require('putout').types; ``` ## convert-plugins-element-to-tuple Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/abcc9f79469db69849b6d6efd3e85a8a/0536c9f780a0c9db2feed3be92299a22f06b9720). ### ❌ Example of incorrect code ```js const {__a, __b} = getTemplateValues(path.node, 'const __a = __b'); ``` ### ✅ Example of correct code ```js const {__a, __b} = getTemplateValues(path, 'const __a = __b'); ``` ## convert-process-to-find ### ❌ Example of incorrect code ```js export const fix = () => { path.remove(); }; ``` ### ✅ Example of correct code ```js export const fix = (path) => { path.remove(); }; ``` ## convert-push-object-to-push-path Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/fc54c923cb3cc4095c3c1d84d7ae7982/7de8eace54c8068be4ec5954ad4dde6d52ec6ca6). ### ❌ Example of incorrect code ```js const parseOptions = require('putout/lib/parse-options'); ``` ### ✅ Example of correct code ```js const parseOptions = require('putout/parse-options'); ``` ## convert-putout-test-to-create-test Fixes results of [@putout/convert-commonjs-to-esm](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-commonjs-to-esm#readme) work. ### ❌ Example of incorrect code ```js module.exports.replace = () => ({ 'const __a = __b': ({}) => {}, 'const __c = __d': ({}, path) => {}, }); ``` ### ✅ Example of correct code ```js module.exports.replace = () => ({ 'const __a = __b': (vars) => {}, 'const __c = __d': (vars, path) => {}, }); ``` ## add-places-to-compare-places" ### ❌ Example of incorrect code [`comparePlaces`](https://github.com/coderaiser/putout/tree/master/packages/test#compareplacesfilename-places-overrides) takes two or more arguments. Checkout in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/a83b1a6785bb01102451df4510333f42/a2439f7f44da56318d9a0e44b2602972811d9afb). ```js comparePlaces('hello'); ``` ### ✅ Example of correct code ```js comparePlaces('hello', []); ``` ## convert-replace-to-function ### ❌ Example of incorrect code ```js export const traverse = () => ({ [__markdown]: (path) => { traverse(); }, }); ``` ### ✅ Example of correct code ```js export const traverse = () => ({ [__markdown]: (path) => { superTraverse(path, { '__a(__b, __c)': (path) => {}, }); }, }); ``` ## convert-replace-to-traverse Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/a87ab50e500cd3aee3099063a48c0e3f/8dee3919638062563c9b39886d8bb8581f5722f2). ### ❌ Example of incorrect code ```js module.exports.traverse = () => ({ 'async (__a) => __b': 'async ({process}) => __b', }); ``` ### ✅ Example of correct code ```js module.exports.replace = () => ({ 'async (__a) => __b': 'async ({process}) => __b', }); ``` ## convert-replace-with ### ❌ Example of incorrect code ```js export const include = () => ({ ClassDeclaration(path) {}, }); ``` ### ✅ Example of correct code ```js export const traverse = () => ({ ClassDeclaration(path) {}, }); ``` ## convert-replace-with-multiple ### ❌ Example of incorrect code ```js module.exports.traverse = ({push}) => ({ TSTypeAssertion(path) { push(path); }, }); ``` ### ✅ Example of correct code ```js module.exports.include = () => [ 'TSTypeAssertion', ]; ``` ## convert-replacer-to-includer Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/4b5e172466fda5e8fb114e767639f7ee/d3af95da4418b8c0e761d8cd50c1fa38a412b55c). ### ❌ Example of incorrect code ```js export const replace = () => ({ 'const [__a, {__b}] = __c(__d, __e)': 'const [__a, {__b}] = __c(__d, __e)', 'const [__a, {__b = {}} = {}] = __c(__d, __e)': 'const [__a, {__b = {}} = {}] = __c(__d, __e)', }); ``` ### ✅ Example of correct code ```js export const fix = () => {}; export const include = () => [ 'const [__a, {__b}] = __c(__d, __e)', 'const [__a, {__b = {}} = {}] = __c(__d, __e)', ]; ``` ## convert-report-to-function ### ❌ Example of incorrect code ```js export const scan = (root, {push, progress}) => { crawlFile(); }; ``` ### ✅ Example of correct code ```js export const scan = (root, {push, progress, crawlFile}) => { crawlFile(); }; ``` ## convert-to-no-transform-code ### ❌ Example of incorrect code ```diff ## Rules -- ✅ [remove-illegal-strict-mode](#remove-useless-strict-mode); -- ✅ [add-node-prefix](#add-node-prefix); +- ✅ [add-node-prefix](#add-node-prefix); +- ✅ [remove-illegal-strict-mode](#remove-useless-strict-mode); ``` ## convert-traverse-to-include ### ❌ Example of incorrect code ```js export const traverse = ({push}) => ({ AssignmentExpression(path) { const {left} = path.node; if (!isIdentifier(left)) return; if (left.name === 'exports') return; push(path); }, }); ``` ### ✅ Example of correct code ```js export const include = () => [ 'AssignmentExpression', ]; export const filter = (path) => { const {left} = path.node; if (!isIdentifier(left)) return false; if (left.name === 'exports') return false; return true; }; ``` ### ❌ Example of incorrect code ```js module.exports.match = () => ({ '__a = __b': (vars, path) => {}, }); module.exports.replace = () => ({ '__a = __': '__a', }); ``` ☝️ *There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false positives when running on code. This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.* ## convert-traverse-to-replace ### ❌ Example of incorrect code ```js export const match = () => ({ '__a(__args': (vars, path) => { fn(x); return __args[__a]; }, }); ``` ### ✅ Example of correct code ```js export const match = () => ({ '__a(__args': ({__args, __a}, path) => { fn(x); return __args[__a]; }, }); ``` ## convert-traverse-to-scan Checkout in 🐊**Putout Editor**: - [`Traverser`](https://putout.cloudcmd.io/#/gist/afe988c8e53ae70e50bf26512672f3cd/a6677d53b996e85880a4af18250c00e849322bbe); - [`Replacer`](https://putout.cloudcmd.io/#/gist/2e89f498c88f3208beeb85dd01a9178e/ed975281c57f451fc1c3aaf187425a33499af71d); ### ❌ Example of incorrect code ```js export const match = () => ({ '__x __a __expr': ({__x}) => { if (path.isNextPunctuator(assign)) return false; return isOneOfKeywords(__x, ['const', 'let', 'var']); }, }); ``` ### ✅ Example of correct code ```js export const match = () => ({ '__x __a __expr': ({__x}) => { if (path.isNextPunctuator(assign)) return false; return isOneOfKeywords(__x, ['const', 'let', 'var']); }, }); ``` ## convert-traverse-to-super-traverse Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/131b7af8e25a454b293d592d2faa2cd8/f8ae176880de753eb50236d841a1a3bb8e494e2f). ### ❌ Example of incorrect code ```js compare(a, 'const __a = __b'); isIdentifier(a); ``` ### ✅ Example of correct code ```js import {operator, types} from 'putout'; const {compare} = operator; const {isIdentifier} = types; compare(a, 'const __a = __b'); isIdentifier(a); ``` ## convert-url-to-dirname ### ❌ Example of incorrect code ```js test('', ({progress}) => { progress(); }); ``` ### ✅ Example of correct code ```js test('', async ({progress}) => { await progress(); }); ``` ## create-test Add properties to `createTest` options, here is example of `.putout.json`: ```json ``` Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e2a9f02d352c064ac9a11688feadc923/2a525f0a8a2794c9d26c23914801c512f347abef). ### ❌ Example of incorrect code ```js module.exports.match = { 'let __a = __b': () => false, }; ``` ### ✅ Example of correct code ```js module.exports.match = () => ({ 'let __a = __b': () => false, }); ``` ## declare ### ❌ Example of incorrect code ```js import {createTest} from '@putout/test'; import plugin from '@putout/plugin-debugger'; import {createSimport} from 'simport'; const {__dirname} = createSimport(import.meta.url); const test = createTest(__dirname, { 'remove-debugger': plugin, }); ``` ### ✅ Example of correct code ```js import {createTest} from '@putout/test'; import plugin from '@putout/plugin-debugger'; const test = createTest(import.meta.url, { 'remove-debugger': plugin, }); ``` ## convert-progress-to-track Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/8736a0cf838a3660b0927e161e4fb06c/9f5c9f810babd4450898069d3d8dc28aceee1e2d). ### ❌ Example of incorrect code ```js module.exports.scan = (root, {push, progress}) => { const files = findFile(root, ['*']); const n = files.length; for (const [i, file] of files.entries()) { push(file); progress({ i, n, }); } }; ``` ### ✅ Example of correct code ```js module.exports.scan = (root, {push, trackFile}) => { for (const file of trackFile(root, ['*'])) { push(file); } }; ``` ## declare-path-variable Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b485bf55785ea836408d0d45c492c3e4/2a0b465076242ebf6a0d8015a90ccf7b0b660a42). ### ❌ Example of incorrect code ```js module.exports.report = `'report' should be a 'function'`; ``` ### ✅ Example of correct code ```js module.exports.report = () => `'report' should be a 'function'`; ``` ## declare-template-variables Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/71ae86cc372dca8adc79bf53c49e8d5f/c9c8517ee932c18abcfda10c0515253b907ee485). ### ❌ Example of incorrect code ```js const {createTest} = require('@putout/test'); const plugin = require('@putout/plugin-debugger'); const test = createTest(__dirname, { 'remove-debugger': plugin, }); ``` ### ✅ Example of correct code ```js const {createTest} = require('@putout/test'); const plugin = require('@putout/plugin-debugger'); const test = createTest(import.meta.url, { 'remove-debugger': plugin, }); ``` ## includer ### ❌ Example of incorrect code ```js module.exports.rules = getRule('remove-unused-variables'); ``` ### ✅ Example of correct code ```js const removeUnusedVariables = require('./remove-unused-variables'); module.exports.rules = { 'remove-unused-variables': removeUnusedVariables, }; ``` ## move-require-on-top-level ### ❌ Example of incorrect code ```js const content = getFileContent(file); ``` ### ✅ Example of correct code ```js const content = readFileContent(file); ``` ## remove-empty-array-from-process Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/fc32ff87e91fd28f26a03f55eba0663e/3423926ba0a80d30beafe2ac66c70c517df173e1). ### ❌ Example of incorrect code ```js module.exports.include = () => 'cons __a = __b'; module.exports.exclude = () => 'var __a = __b'; module.exports.include = 'cons __a = __b'; module.exports.exclude = 'var __a = __b'; module.exports.include = [ 'cons __a = __b', ]; module.exports.exclude = [ 'var __a = __b', ]; export const include = [ 'cons __a = __b', ]; export const exclude = [ 'var __a = __b', ]; ``` ### ✅ Example of correct code ```js module.exports.include = () => [ 'const __a = __b', ]; module.exports.exclude = () => [ 'var __a = __b', ]; export const include = () => [ 'cons __a = __b', ]; export const exclude = () => [ 'var __a = __b', ]; ``` ## remove-empty-object-from-transform Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f6e8710edf3501a8883f769c82a93048/8060cb8e1505324bb13de511a67d051217a2c39c). ### ❌ Example of incorrect code ```js test('plugin-putout: rename-operate-to-operator: transform: operator exist', (t) => { t.noTransform('operator'); t.end(); }); test('plugin-putout: rename-operate-to-operator: report: operator exist', (t) => { t.noReport('operator'); t.end(); }); ``` ### ✅ Example of correct code ```js test('plugin-putout: rename-operate-to-operator: no transform: operator exist', (t) => { t.noTransform('operator'); t.end(); }); test('plugin-putout: rename-operate-to-operator: no report: operator exist', (t) => { t.noReport('operator'); t.end(); }); ``` ## remove-message-from-no-report-after-transform Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b40b73049530d6c4e142a4d4b09e29e2/2167f30abebc5713e2db916a2a0152e13722e7b1). ### ❌ Example of incorrect code ```js test('hello', (t) => { t.transform('nested-labels', {}); }); ``` ### ✅ Example of correct code ```js test('hello', (t) => { t.transform('nested-labels'); }); ``` ## remove-unused-get-properties-argument Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/fc32ff87e91fd28f26a03f55eba0663e/3423926ba0a80d30beafe2ac66c70c517df173e1). ### ❌ Example of incorrect code ```js await process('input', []); ``` ### ✅ Example of correct code ```js await process('input'); ``` ## remove-useless-match Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/a813e8b3da2ccbe949a3156842c3112e/5e21a147247c2451f9f826ba384d62ab37c17a01). ### ❌ Example of incorrect code ```js export const match = () => ({ 'const [__a, {__b}] = __c(__d, __e)': () => true, 'const [__a, {__b = {}} = {}] = __c(__d, __e)': () => true, }); ``` ### ✅ Example of correct code ```js ``` ## remove-useless-printer-option Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f176313cf67fd6d7138470385511319f/5b26aa45db21f250016d228b7bbabbb3c10b582b). `putout` printer used by default, so there is no need to pass it. ### ❌ Example of incorrect code ```js const { overridesPath, parserPath, rulesPath, } = getProperties(__jsonPath, [ 'parser', 'rules', 'overrides', 'extends', ]); ``` ### ✅ Example of correct code ```js const { overridesPath, parserPath, rulesPath, } = getProperties(__jsonPath, ['parser', 'rules', 'extends']); ``` ## remove-useless-source-argument Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9b5f94d6a60f3337f925fcc338370d83/7e944de0dfdd64b3c74d490aae21b04015b8262f). ### ❌ Example of incorrect code ```js test('github: set-message-of-commit-fixes: no report after transform', (t) => { t.noReportAfterTransform('set-message-of-commit-fixes', `Set 'message' of 'Commit fixes'`); t.end(); }); ``` ### ✅ Example of correct code ```js test('github: set-message-of-commit-fixes: no report after transform', (t) => { t.noReportAfterTransform('set-message-of-commit-fixes'); t.end(); }); ``` ## remove-useless-type-check-declaration Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/443f742c8cda2b50e1722cdf2577d5c3/1f269a3d5ae0dcfa8661ca283b329c53c2450b39). ### ❌ Example of incorrect code ```js const isStringLiteral = (arg) => arg.type === 'StringLiteral'; ``` ### ✅ Example of correct code ```js ``` ## apply-fixture-name-to-message" Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/66eb493ee966c2465a9fc783cd3ca362/f42ec60e393181b6d6aaf6df81640e93fabe8783). ```js test('flatlint: convert-comma-to-semicolon: no report: xxx', (t) => { t.noReport('array'); t.end(); }); ``` ### ✅ Example of correct code ```js test('flatlint: convert-comma-to-semicolon: no report: array', (t) => { t.noReport('array'); t.end(); }); ``` ## replace-test-message Checks that `test message` and used `operator` are synchronized. Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d9c6972ea848ba8e7e745d2479727b65/199c30b986ce7d544397c344ebfc5031c4b53181). ### ❌ Example of incorrect code ```js const test = require('@putout/test')(__dirname, { 'remove-debugger': require('..'), }); test('remove debugger: report', (t) => { t.transform('debugger', { 'remove-debugger': require('..'), }); t.end(); }); ``` ### ✅ Example of correct code ```js const removeDebugger = require('..'); const test = require('@putout/test')(__dirname, { 'remove-debugger': removeDebugger, }); test('remove debugger: report', (t) => { t.transform('debugger', { 'remove-debugger': removeDebugger, }); t.end(); }); ``` ## shorten-imports ### ❌ Example of incorrect code ```js const test = createTest(__dirname, { printer: 'putout', plugins: [ ['remove-unchanged-zero-declarations', plugin], ], }); ``` ### ✅ Example of correct code ```js const test = createTest(__dirname, { plugins: [ ['remove-unchanged-zero-declarations', plugin], ], }); ``` ## shorten-path-get Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/afc8a421eee129910153939eae2eb79e/04304530529a53f5894a289bcd83d3ac2460c9ab). ### ❌ Example of incorrect code ```js const elements = path.get('arguments')[0].get('elements'); ``` ### ✅ Example of correct code ```js const elements = path.get('arguments.0.elements'); ``` ## simplify-replace-template Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/a012fc12f4d38038da022f7c8f379fe2/c65bf97c42650aa31c5481849bc934323df892a6). ### ❌ Example of incorrect code ```js module.exports.replace = () => ({ 'if (__a) {__b} else {__c}': () => 'if (__a) __b; else __c', }); ``` ### ✅ Example of correct code ```js module.exports.replace = () => ({ 'if (__a) {__b} else {__c}': 'if (__a) __b; else __c', }); ``` ## sort-readme-file Checkout in 🐊**Putout Editor**: - ✅ [`add-missing-semicolon`](https://putout.cloudcmd.io/#/gist/7c7ab5cbedef8d6021ce2a77b5caa4f0/aee514d0cc4ef0ea26f4fdcf4def03a078eb1bd0); - ✅ [`sort-contents`](https://putout.cloudcmd.io/#/gist/647bcc98ba9eeaa619dfa90d129ee0ec/a19ba868e8c2f97292e763675de65cc1ec98ff66); - ✅ [`sort-headings`](https://putout.cloudcmd.io/#/gist/a5a23310a84cb209e7e5537bab294ab2/0ecd88ffa6e37ac2553cabe5333d307aed2c4a7d); - ✅ [`sort-config`](https://putout.cloudcmd.io/#/gist/41c9975090803fdee30c445868e5b93f/18f78a72eb4f4cf33f5137fca11de9314c12763c); - ✅ [`sort-readme-file`](https://putout.cloudcmd.io/#/gist/41c9975090803fdee30c445868e5b93f/a5edcb99b4769c05d6482a051f918442bdcc86e9); ## License MIT