README
@putout/plugin-putout
🐊Putout
plugin helps with plugins development.
Install
npm i @putout/plugin-putout -D
Rules
{
"rules": {
"putout/apply-create-test": "on",
"putout/apply-processors-destructuring": "on",
"putout/apply-async-formatter": "on",
"putout/add-args": "on",
"putout/convert-putout-test-to-create-test": "on",
"putout/convert-to-no-transform-code": "on",
"putout/convert-replace-with": "on",
"putout/convert-replace-with-multiple": "on",
"putout/convert-replace-to-function": "on",
"putout/convert-match-to-function": "on",
"putout/convert-babel-types": "on",
"putout/convert-destructuring-to-identifier": "on",
"putout/convert-node-to-path-in-get-template-values": "on",
"putout/convert-traverse-to-include": "on",
"putout/convert-traverse-to-replace": "on",
"putout/convert-process-to-find": "on",
"putout/convert-method-to-property": "on",
"putout/convert-add-argument-to-add-args": "on",
"putout/convert-dirname-to-url": "on",
"putout/convert-url-to-dirname": "on",
"putout/shorten-imports": "on",
"putout/check-replace-code": "on",
"putout/declare": "on",
"putout/includer": "on",
"putout/move-require-on-top-level": "on"
}
}
apply-processors-destructuring
❌ Incorrect code example
test('', async (t) => {
await t.process({});
});
✅ Correct code Example
test('', async ({process}) => {
await process({});
});
apply-async-formatter
❌ Incorrect code example
test('formatter: codeframea', (t) => {
t.format(codeframe, 1);
t.end();
});
✅ Correct code example
test('formatter: codeframea', async ({format}) => {
await format(codeframe, 1);
});
apply-create-test
❌ Incorrect code example
const test = require('@putout/test')({
'remove-debugger': plugin,
});
✅ Correct code example
const {createTest} = require('@putout/test');
const test = createTest({
'remove-debugger': plugin,
});
convert-putout-test-to-create-test"
Fixes results of @putout/convert-commonjs-to-esm work.
❌ Incorrect code example
import putoutTest from '@putout/test';
const test = putoutTest(__dirname, {
'remove-unused-variables': rmVars,
});
✅ Correct code Example
import createTest from '@putout/test';
const test = createTest(__dirname, {
'remove-unused-variables': rmVars,
});
convert-to-no-transform-code
❌ Incorrect code example
test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
const code = 'const {name} = array[0]';
t.transform(code, '');
t.end();
});
✅ Correct code Example
test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
const code = 'const {name} = array[0]';
t.noTransformCode(code);
t.end();
});
convert-replace-with
❌ Incorrect code example
module.exports.fix = (path) => {
path.replaceWith(Identifier('hello'));
};
✅ Correct code Example
const {replaceWith} = require('putout').operator;
module.exports.fix = (path) => {
replaceWith(path, Identifier('hello'));
};
convert-replace-with-multiple
❌ Incorrect code example
module.exports.fix = (path) => {
path.replaceWithMultiple([Identifier('hello')]);
};
✅ Correct code Example
const {replaceWithMultiple} = require('putout').operator;
module.exports.fix = (path) => {
replaceWithMultiple(path, [Identifier('hello')]);
};
convert-replace-to-function
❌ Incorrect code example
module.exports.replace = {
'let __a = __b': 'const __b = __a',
};
✅ Correct code Example
module.exports.replace = () => ({
'let __a = __b': 'const __b = __a',
});
convert-match-to-function
❌ Incorrect code example
module.exports.match = {
'let __a = __b': () => false,
};
✅ Correct code Example
module.exports.match = () => ({
'let __a = __b': () => false,
});
convert-babel-types
❌ Incorrect code example
const {
ObjectExpression,
SpreadElement,
isObjectExpression,
isIdentifier,
} = require('@babel/types');
✅ Correct code Example
const {
ObjectExpression,
SpreadElement,
isObjectExpression,
isIdentifier,
} = require('putout').types;
convert-to-no-transform-code
❌ Incorrect code example
module.exports.replace = () => ({
'const __a = __b': ({}) => {
},
'const __c = __d': ({}, path) => {
},
});
✅ Correct code Example
module.exports.replace = () => ({
'const __a = __b': (vars) => {
},
'const __c = __d': (vars, path) => {
},
});
convert-node-to-path-in-get-template-values
❌ Incorrect code example
const {__a, __b} = getTemplateValues(path.node, 'const __a = __b');
✅ Correct code Example
const {__a, __b} = getTemplateValues(path, 'const __a = __b');
shorten-imports
❌ Incorrect code example
const parseOptions = require('putout/lib/parse-options');
✅ Correct code Example
const parseOptions = require('putout/parse-options');
convert-traverse-to-include
❌ Incorrect code example
module.exports.traverse = ({push}) => ({
TSTypeAssertion(path) {
push(path);
},
});
✅ Correct code Example
module.exports.include = () => [
'TSTypeAssertion',
];
convert-traverse-to-replace
❌ Incorrect code example
module.exports.traverse = () => ({
'async (__a) => __b': 'async ({process}) => __b',
});
✅ Correct code Example
module.exports.replace = () => ({
'async (__a) => __b': 'async ({process}) => __b',
});
convert-process-to-find
❌ Incorrect code example
module.exports.preProcess = () => {};
module.exports.postProcess = () => {};
✅ Correct code Example
module.exports.branch = (rawSource) => [];
module.exports.merge = (processedSource, list) => '';
convert-method-to-property
- property simpler to work with;
- support of
convert-destructuring-to-identifier
which isReplacer
, whileconvert-method-to-property
isIncluder
(searches forObjectMethod
node);
❌ Incorrect code example
module.exports.match = () => ({
'module.exports.traverse = __a'({}, path) {
},
});
✅ Correct code Example
module.exports.match = () => ({
'module.exports.traverse = __a': ({}, path) => {
},
});
check-replace-code
Checks that Replacer transform is possible.
❌ Incorrect code example
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 possitives 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.
declare
Depend on @putout/convert-esm-to-commonjs and @putout/declare-undefined-variables
❌ Incorrect code example
compare(a, 'const __a = __b');
isIdentifier(a);
✅ Correct code Example
const {operator, types} = require('putout');
const {compare} = operator;
const {isIdentifier} = types;
compare(a, 'const __a = __b');
isIdentifier(a);
add-args
❌ Incorrect code example
test('', () => {
comparePlaces();
});
✅ Correct code Example
test('', ({comparePlaces}) => {
comparePlaces();
});
convert-add-argument-to-add-args
const {operator} = require('putout');
const {addArgument} = operator;
module.exports = addArgument({
t: ['t', 'test("__a", (__args) => __body)'],
});
✅ Correct code Example
const {operator} = require('putout');
const {addArgs} = operator;
module.exports = addArgs({
t: ['t', 'test("__a", (__args) => __body)'],
});
convert-dirname-to-url
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,
});
✅ Correct code Example
import {createTest} from '@putout/test';
import plugin from '@putout/plugin-debugger';
const test = createTest(import.meta.url, {
'remove-debugger': plugin,
});
convert-url-to-dirname-
const {createTest} = require('@putout/test');
const plugin = require('@putout/plugin-debugger');
const test = createTest(import.meta.url, {
'remove-debugger': plugin,
});
✅ Correct code Example
const {createTest} = require('@putout/test');
const plugin = require('@putout/plugin-debugger');
const test = createTest(import.meta.url, {
'remove-debugger': plugin,
});
move-require-on-top-level
❌ Incorrect code example
const test = require('@putout/test')(__dirname, {
'remove-debugger': require('..'),
});
test('remove debugger: report', (t) => {
t.transform('debugger', {
'remove-debugger': require('..'),
});
t.end();
});
✅ Correct code Example
const removeDebugger = require('..');
const test = require('@putout/test')(__dirname, {
'remove-debugger': removeDebugger,
});
test('remove debugger: report', (t) => {
const test = require('@putout/test')(__dirname, {
'remove-debugger': removeDebugger,
});
t.end();
});
includer
❌ Incorrect code example
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'];
✅ Correct code Example
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'];
License
MIT