🐊Putout plugin helps with plugins development.
npm i @putout/plugin-putout -D
{
"rules": {
"putout/apply-create-test": "on",
"putout/apply-processors-destructuring": "on",
"putout/apply-async-formatter": "on",
"putout/apply-remove": "on",
"putout/apply-declare": "on",
"putout/add-args": "on",
"putout/add-push": "on",
"putout/convert-putout-test-to-create-test": "on",
"putout/convert-to-no-transform-code": "on",
"putout/convert-number-to-numeric": "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/convert-report-to-function": "on",
"putout/create-test": "on",
"putout/shorten-imports": "on",
"putout/check-replace-code": "on",
"putout/declare": "on",
"putout/includer": "on",
"putout/move-require-on-top-level": "on",
"putout/replace-test-message": "on"
}
}
test('', async (t) => {
await t.process({});
});
test('', async ({process}) => {
await process({});
});
Better to use remove(path)
method of operator
.
It helps to preserve comments.
export const fix = (path) => {
path.remove();
};
import {operator} from 'putout';
const {remove} = operator;
export const fix = (path) => {
remove(path);
};
Better to use Declareator
instead of operator.declare()
.
Check out in 🐊Putout Editor.
const {operator} = require('putout');
const {declare} = operator;
module.exports = declare({
tryCatch: `import tryCatch from 'try-catch'`,
tryToCatch: `import tryToCatch from 'try-to-catch'`,
});
module.exports.declare = () => ({
tryCatch: `import tryCatch from 'try-catch'`,
tryToCatch: `import tryToCatch from 'try-to-catch'`,
});
test('formatter: codeframea', (t) => {
t.format(codeframe, 1);
t.end();
});
test('formatter: codeframea', async ({format}) => {
await format(codeframe, 1);
});
const test = require('@putout/test')({
'remove-debugger': plugin,
});
const {createTest} = require('@putout/test');
const test = createTest({
'remove-debugger': plugin,
});
Add properties to createTest
options, here is exmample of .putout.json
:
{
"rules": {
"putout/create-test": ["on", {
"add": [
["printer", "putout"]
]
}]
}
}
Check it out in 🐊Putout Editor.
createTest(__dirname, {
'putout/create-test': plugin,
});
createTest(__dirname, {
printer: 'putout',
plugins: [
['putout/create-test', plugin],
],
});
Prevent Babel
warning: The node type NumberLiteral has been renamed to NumericLiteral
.
const {isNumberLiteral} = types;
isNumberLiteral(node);
const {isNumericLiteral} = types;
isNumericLiteral(node);
Fixes results of @putout/convert-commonjs-to-esm work.
import putoutTest from '@putout/test';
const test = putoutTest(__dirname, {
'remove-unused-variables': rmVars,
});
import {createTest} from '@putout/test';
const test = createTest(__dirname, {
'remove-unused-variables': rmVars,
});
test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
const code = 'const {name} = array[0]';
t.transform(code, '');
t.end();
});
test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
const code = 'const {name} = array[0]';
t.noTransformCode(code);
t.end();
});
module.exports.fix = (path) => {
path.replaceWith(Identifier('hello'));
};
const {replaceWith} = require('putout').operator;
module.exports.fix = (path) => {
replaceWith(path, Identifier('hello'));
};
module.exports.fix = (path) => {
path.replaceWithMultiple([Identifier('hello')]);
};
const {replaceWithMultiple} = require('putout').operator;
module.exports.fix = (path) => {
replaceWithMultiple(path, [Identifier('hello')]);
};
module.exports.replace = {
'let __a = __b': 'const __b = __a',
};
module.exports.replace = () => ({
'let __a = __b': 'const __b = __a',
});
module.exports.match = {
'let __a = __b': () => false,
};
module.exports.match = () => ({
'let __a = __b': () => false,
});
const {
ObjectExpression,
SpreadElement,
isObjectExpression,
isIdentifier,
} = require('@babel/types');
const {
ObjectExpression,
SpreadElement,
isObjectExpression,
isIdentifier,
} = require('putout').types;
module.exports.replace = () => ({
'const __a = __b': ({}) => {},
'const __c = __d': ({}, path) => {},
});
module.exports.replace = () => ({
'const __a = __b': (vars) => {},
'const __c = __d': (vars, path) => {},
});
const {__a, __b} = getTemplateValues(path.node, 'const __a = __b');
const {__a, __b} = getTemplateValues(path, 'const __a = __b');
const parseOptions = require('putout/lib/parse-options');
const parseOptions = require('putout/parse-options');
module.exports.traverse = ({push}) => ({
TSTypeAssertion(path) {
push(path);
},
});
module.exports.include = () => [
'TSTypeAssertion',
];
module.exports.traverse = () => ({
'async (__a) => __b': 'async ({process}) => __b',
});
module.exports.replace = () => ({
'async (__a) => __b': 'async ({process}) => __b',
});
module.exports.preProcess = () => {};
module.exports.postProcess = () => {};
module.exports.branch = (rawSource) => [];
module.exports.merge = (processedSource, list) => '';
- property simpler to work with;
- support of
convert-destructuring-to-identifier
which isReplacer
, whileconvert-method-to-property
isIncluder
(searches forObjectMethod
node);
module.exports.match = () => ({
'module.exports.traverse = __a'({}, path) {},
});
module.exports.match = () => ({
'module.exports.traverse = __a': ({}, path) => {},
});
Checks that Replacer transform is possible.
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.
Depends on @putout/convert-esm-to-commonjs and @putout/declare.
compare(a, 'const __a = __b');
isIdentifier(a);
const {
operator,
types,
} = require('putout');
const {compare} = operator;
const {isIdentifier} = types;
compare(a, 'const __a = __b');
isIdentifier(a);
test('', () => {
comparePlaces();
});
test('', ({comparePlaces}) => {
comparePlaces();
});
module.exports.traverse = () => ({
'__a.replace(/__b/g, __c)': (path) => {
push(path);
},
});
module.exports.traverse = ({push}) => ({
'__a.replace(/__b/g, __c)': (path) => {
push(path);
},
});
const {operator} = require('putout');
const {addArgument} = operator;
module.exports = addArgument({
t: ['t', 'test("__a", (__args) => __body)'],
});
const {operator} = require('putout');
const {addArgs} = operator;
module.exports = addArgs({
t: ['t', 'test("__a", (__args) => __body)'],
});
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,
});
import {createTest} from '@putout/test';
import plugin from '@putout/plugin-debugger';
const test = createTest(import.meta.url, {
'remove-debugger': plugin,
});
const {createTest} = require('@putout/test');
const plugin = require('@putout/plugin-debugger');
const test = createTest(__dirname, {
'remove-debugger': plugin,
});
const {createTest} = require('@putout/test');
const plugin = require('@putout/plugin-debugger');
const test = createTest(import.meta.url, {
'remove-debugger': plugin,
});
module.exports.report = `'report' should be a 'function'`;
module.exports.report = () => `'report' should be a 'function'`;
const test = require('@putout/test')(__dirname, {
'remove-debugger': require('..'),
});
test('remove debugger: report', (t) => {
t.transform('debugger', {
'remove-debugger': require('..'),
});
t.end();
});
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();
});
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',
];
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',
];
Checks that test message
and used operator
are synchronized.
Check it out in 🐊Putout Editor.
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();
});
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();
});
MIT