πPutout plugin helps with plugins development
npm install @putout/plugin-putout[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 plugin helps with plugins development.
```
npm i @putout/plugin-putout -D
- β
add-await-to-progress;
- β
add-places-to-compare-places;
- β
add-path-arg-to-fix;
- β
add-path-arg-to-visitors;
- β
add-push-arg;
- β
add-test-args;
- β
add-traverse-args;
- β
add-crawl-file;
- β
add-track-file;
- β
apply-async-formatter;
- β
apply-create-test;
- β
apply-create-nested-directory;
- β
apply-declare;
- β
apply-destructuring;
- β
apply-engine-node-version;
- β
apply-exports;
- β
apply-exports-to-add-args;
- β
apply-exports-to-match-files;
- β
apply-exports-to-rename-files;
- β
apply-for-of-to-track-file;
- β
apply-fixture-name-to-message;
- β
apply-insert-after;
- β
apply-insert-before;
- β
apply-vars;
- β
apply-lowercase-to-node-builders;
- β
apply-namespace-specifier;
- β
apply-report;
- β
apply-processors-destructuring;
- β
apply-remove;
- β
apply-rename;
- β
apply-parens;
- β
apply-short-processors;
- β
apply-transform-with-options;
- β
check-match;
- β
check-declare;
- β
check-replace-code;
- β
convert-add-argument-to-add-args;
- β
convert-babel-types;
- β
convert-destructuring-to-identifier;
- β
convert-dirname-to-url;
- β
convert-find-to-traverse;
- β
convert-get-rule-to-require;
- β
convert-get-file-content-to-read-file-content;
- β
convert-match-to-function;
- β
convert-method-to-property;
- β
convert-node-to-path-in-get-template-values;
- β
convert-number-to-numeric;
- β
convert-process-to-find;
- β
convert-progress-to-track-file;
- β
convert-putout-test-to-create-test;
- β
convert-plugins-element-to-tuple;
- β
convert-push-object-to-push-path;
- β
convert-replace-to-function;
- β
convert-replace-to-traverse;
- β
convert-replace-with;
- β
convert-replace-with-multiple;
- β
convert-report-to-function;
- β
convert-to-no-transform-code;
- β
convert-include-to-traverse;
- β
convert-traverse-to-include;
- β
convert-traverse-to-replace;
- β
convert-traverse-to-scan;
- β
convert-url-to-dirname;
- β
create-test;
- β
declare;
- β
declare-template-variables;
- β
declare-path-variable;
- β
includer;
- β
move-require-on-top-level;
- β
remove-empty-array-from-process;
- β
remove-empty-object-from-transform;
- β
remove-unused-get-properties-argument;
- β
remove-useless-printer-option;
- β
remove-message-from-no-report-after-transform;
- β
rename-operate-to-operator;
- β
replace-operate-with-operator;
- β
replace-test-message;
- β
shorten-imports;
- β
simplify-replace-template;
`json`
{
"rules": {
"putout/add-places-to-compare-places": "on",
"putout/add-path-arg-to-fix": "on",
"putout/add-path-arg-to-visitors": "on",
"putout/add-push-arg": "on",
"putout/add-test-args": "on",
"putout/add-traverse-args": "on",
"putout/add-crawl-file": "on",
"putout/add-track-file": "on",
"putout/add-await-to-progress": "on",
"putout/apply-create-test": "on",
"putout/apply-create-nested-directory": "on",
"putout/apply-async-formatter": "on",
"putout/apply-declare": "on",
"putout/apply-destructuring": "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-report": "on",
"putout/apply-processors-destructuring": "on",
"putout/apply-rename": "on",
"putout/apply-parens": "on",
"putout/apply-remove": "on",
"putout/apply-transform-with-options": "on",
"putout/apply-insert-before": "on",
"putout/apply-insert-after": "on",
"putout/apply-vars": "on",
"putout/apply-short-processors": "on",
"putout/apply-lowercase-to-node-builders": "on",
"putout/apply-namespace-specifier": "on",
"putout/apply-for-of-to-track-file": "on",
"putout/apply-fixture-name-to-message": "on",
"putout/check-match": "on",
"putout/check-declare": "on",
"putout/check-replace-code": ["on", {
"once": true
}],
"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-replace-to-traverse": "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-include-to-traverse": "on",
"putout/convert-traverse-to-include": "on",
"putout/convert-traverse-to-replace": "on",
"putout/convert-traverse-to-scan": "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/convert-get-rule-to-require": "on",
"putout/convert-get-file-content-to-read-file-content": "on",
"putout/convert-progress-to-track-file": "on",
"putout/convert-plugins-element-to-tuple": "on",
"putout/convert-push-object-to-push-path": "on",
"putout/create-test": "on",
"putout/shorten-imports": "on",
"putout/declare": "on",
"putout/declare-template-variables": "on",
"putout/declare-path-variable": "on",
"putout/includer": "on",
"putout/move-require-on-top-level": "on",
"putout/replace-test-message": "on",
"putout/remove-unused-get-properties-argument": "on",
"putout/remove-empty-array-from-process": "on",
"putout/remove-empty-object-from-transform": "on",
"putout/remove-useless-printer-option": "on",
"putout/remove-message-from-no-report-after-transform": "on",
"putout/simplify-replace-template": "on"
}
}
Checkout in πPutout Editor.
`js`
path.node = Identifier('x');
`js`
path.node = identifier('x');
Checkout in πPutout Editor.
`js
t.noReport('rename-files-full', {
from: ['/'],
to: [],
});
t.noReportWithOptions('rename-files-full');
t.noReport('a', 'Use b');
t.report('a');
`
`js
t.noReportWithOptions('rename-files-full', {
from: ['/'],
to: [],
});
t.noReport('rename-files-full');
t.report('a', 'Use b');
t.noReport('a');
`
Checkout in πPutout Editor.
`js`
t.transform('submenu', {
submenuIndex: 1,
insideSubmenu: true,
});
`js`
t.transformWithOptions('submenu', {
submenuIndex: 1,
insideSubmenu: true,
});
`js`
test('', async (t) => {
await t.process({});
});
`js`
test('', async ({process}) => {
await process({});
});
`js`
test('', async (t) => {
await t.process({});
});
`js`
test('', async ({process}) => {
await process({});
});
Apply short names of processors, for example __json instead of __putout_processor_json . Checkout out in πPutout Editor.
`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);
},
});
`js`
export const match = () => ({
[__ignore]: ({__array}) => {
const list = __array.elements.map(getValue);
},
[__filesystem]: ({__object}) => {
const list = __object.elements.map(getValue);
},
});
Better use rename(path, from, to) method of operator.
Check out in πPutout Editor.
`js`
export const fix = ({path, from, to}) => {
path.scope.rename(from, to);
};
`js
import {operator} from 'putout';
const {rename} = operator;
export const fix = ({path, from, to}) => {
rename(path, from, to);
};
`
Better use addParens(path) method of operator instead of using path.node.extra to have support of both printers:
- β
@putout/printer;babel
- β
;
Check out in πPutout Editor.
`js
path.node.extra.parenthesized = false;
path.node.extra.parenthesized = true;
if (!path.node.extra?.parenthesized)
return;
`
`js
removeParens(path);
addParens(path);
if (!hasParens(path))
return;
`
Better to use remove(path) method of operator.
It helps to preserve comments.
`js`
export const fix = (path) => {
path.remove();
};
`js
import {operator} from 'putout';
const {remove} = operator;
export const fix = (path) => {
remove(path);
};
`
Better to use insertBefore(a, b) method of operator.
`js`
export const fix = (path) => {
path.insertBefore(path.get('init'));
};
`js
import {operator} from 'putout';
const {insertBefore} = operator;
export const fix = (path) => {
insertBefore(path, path.get('init'));
};
`
Better to use insertAfter(a, b) method of operator.
It helps to avoid duplication of comments.
`js`
export const fix = (path) => {
path.insertAfter(path.get('init'));
};
`js
import {operator} from 'putout';
const {insertAfter} = operator;
export const fix = (path) => {
insertAfter(path, path.get('init'));
};
`
Checkout in πPutout Editor.
`js
export const replace = () => ({
'__a(__args': ({}, path) => {
return true;
},
});
export const match = () => ({
'__a(__args': ({}, path) => {
return '';
},
});
`
`js
export const replace = () => ({
'__a(__args': (vars, path) => {
return true;
},
});
export const match = () => ({
'__a(__args': (vars, path) => {
return '';
},
});
`
Better to use Declareator instead of operator.declare().
Check out in πPutout Editor.
`js
const {operator} = require('putout');
const {declare} = operator;
module.exports = declare({
tryCatch: import tryCatch from 'try-catch',import tryToCatch from 'try-to-catch'
tryToCatch: ,`
});
`jsimport tryCatch from 'try-catch'
module.exports.declare = () => ({
tryCatch: ,import tryToCatch from 'try-to-catch'
tryToCatch: ,`
});
Check out in πPutout Editor.
`js`
const putout = require('putout');
`js`
const {putout} = require('putout');
Check out in πPutout Editor.
`diff`
{
"name": "@putout/plugin-variables",
"peerDependencies": {
"putout": ">=41"
},
"license": "MIT",
"engines": {
- "node": ">=20"
+ "node": ">=22"
}
}
Check out in πPutout Editor.
Possible configuration:
`json`
{
"rules": {
"putout/apply-exports": ["on", {
"addArgs": [
"report",
"fix",
"scan"
]
}]
}
}
`js`
export default createRenameProperty([
...v32,
...v29,
]);
`js`
export const {
report,
fix,
scan,
} = createRenameProperty([
...v32,
...v29,
]);
Check out in πPutout Editor.
`js`
export default addArgs(__args);
`js`
export const {
report,
fix,
traverse,
} = addArgs(__args);
Check out in πPutout Editor.
`js`
export default matchFiles({
'*.cjs': plugin,
});
`js`
export const {
report,
fix,
scan,
} = matchFiles({
'*.cjs': plugin,
});
Check out in πPutout Editor.
`js`
export default renameFiles({
type: 'module',
mask: '*.mjs',
rename(name) {
return name.replace(/mjs$/, 'js');
},
});
`js`
export const {
report,
fix,
scan,
} = renameFiles({
type: 'module',
mask: '*.mjs',
rename(name) {
return name.replace(/mjs$/, 'js');
},
});
`js`
test('formatter: codeframea', (t) => {
t.format(codeframe, 1);
t.end();
});
`js`
test('formatter: codeframea', async ({format}) => {
await format(codeframe, 1);
});
`js`
const test = require('@putout/test')({
'remove-debugger': plugin,
});
`js
const {createTest} = require('@putout/test');
const test = createTest({
'remove-debugger': plugin,
});
`
Checkout in Putout Editor.
`js`
const dirPath = createDirectory(path, '/hello/world');
const dirPath2 = createNestedDirectory(path, 'world');
`js`
const dirPath = createNestedDirectory(path, '/hello/world');
const dirPath2 = createDirectory(path, 'world');
Most likely what you need is esm/resolve-imported-file.
`js`
import rmUnused from '@putout/plugin-remove-unused-variables';
`js`
import * as rmUnused from '@putout/plugin-remove-unused-variables';
> The Generator object is returned by a generator function and it conforms to both the iterable protocol and the iterator protocol.
>
> (c) MDN
trackFile is generator function used to count progress that can be used in Scanner.
Checkout in πPutout Editor
`js`
module.exports.scan = (path, {push, trackFile}) => {
trackFile(path, '*.swp').map(push);
};
`js`
module.exports.scan = (path, {push, trackFile}) => {
for (const file of trackFile(path, '*.swp')) {
push(file);
}
};
Add properties to createTest options, here is example of .putout.json:
`json`
{
"rules": {
"putout/create-test": ["on", {
"add": [
["printer", "putout"]
]
}]
}
}
Check it out in πPutout Editor.
`js`
createTest(__dirname, {
'putout/create-test': plugin,
});
`js`
createTest(__dirname, {
printer: 'putout',
plugins: [
['putout/create-test', plugin],
],
});
Prevent Babel warning: The node type NumberLiteral has been renamed to NumericLiteral.
`js`
const {isNumberLiteral} = types;
isNumberLiteral(node);
`js`
const {isNumericLiteral} = types;
isNumericLiteral(node);
Fixes results of @putout/convert-commonjs-to-esm work.
`js
import putoutTest from '@putout/test';
const test = putoutTest(__dirname, {
'remove-unused-variables': rmVars,
});
`
`js
import {createTest} from '@putout/test';
const test = createTest(__dirname, {
'remove-unused-variables': rmVars,
});
`
Checkout in πPutout Editor.
`js`
t.transform('nested-not-block', [
['convert-if-to-jmp', convertIfToJmp],
convertDoWhileToJnz,
]);
`js`
t.transform('nested-not-block', [
['convert-if-to-jmp', convertIfToJmp],
['convert-do-while-to-jnz', convertDoWhileToJnz],
]);
Checkout in πPutout Editor.
`js
export const fix = ({path}) => {
removeClassName(path, SELECTED);
};
push({
path: child,
});
`
`js
export const fix = (path) => {
removeClassName(path, SELECTED);
};
push(child);
`
`js`
test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
const code = 'const {name} = array[0]';
t.transform(code, '');
t.end();
});
`js`
test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
const code = 'const {name} = array[0]';
t.noTransformCode(code);
t.end();
});
`js`
module.exports.fix = (path) => {
path.replaceWith(identifier('hello'));
};
`js
const {replaceWith} = require('putout').operator;
module.exports.fix = (path) => {
replaceWith(path, identifier('hello'));
};
`
`js`
module.exports.fix = (path) => {
path.replaceWithMultiple([
identifier('hello'),
]);
};
`js
const {replaceWithMultiple} = require('putout').operator;
module.exports.fix = (path) => {
replaceWithMultiple(path, [
identifier('hello'),
]);
};
`
`js`
module.exports.replace = {
'let __a = __b': 'const __b = __a',
};
`js`
module.exports.replace = () => ({
'let __a = __b': 'const __b = __a',
});
Checkout in πPutout Editor.
`js`
export const fix = () => {};
export const replace = () => ({
[__json]: (path) => {
const __aPath = path.get('arguments.0');
const {importsPath} = getProperties(__aPath, ['imports']);
},
});
`js`
export const fix = () => {};
export const traverse = () => ({
[__json]: (path) => {
const __aPath = path.get('arguments.0');
const {importsPath} = getProperties(__aPath, ['imports']);
},
});
`js`
module.exports.match = {
'let __a = __b': () => false,
};
`js`
module.exports.match = () => ({
'let __a = __b': () => false,
});
`js`
const {
ObjectExpression,
SpreadElement,
isObjectExpression,
isIdentifier,
} = require('@babel/types');
`js`
const {
ObjectExpression,
SpreadElement,
isObjectExpression,
isIdentifier,
} = require('putout').types;
`js`
module.exports.replace = () => ({
'const __a = __b': ({}) => {},
'const __c = __d': ({}, path) => {},
});
`js`
module.exports.replace = () => ({
'const __a = __b': (vars) => {},
'const __c = __d': (vars, path) => {},
});
`js`
const {__a, __b} = getTemplateValues(path.node, 'const __a = __b');
`js`
const {__a, __b} = getTemplateValues(path, 'const __a = __b');
`js`
const parseOptions = require('putout/lib/parse-options');
`js`
const parseOptions = require('putout/parse-options');
Checkout in π*Putout Editor.
`js`
export const include = () => ({
ClassDeclaration(path) {},
});
`js`
export const traverse = () => ({
ClassDeclaration(path) {},
});
`js`
module.exports.traverse = ({push}) => ({
TSTypeAssertion(path) {
push(path);
},
});
`js`
module.exports.include = () => [
'TSTypeAssertion',
];
`js`
module.exports.traverse = () => ({
'async (__a) => __b': 'async ({process}) => __b',
});
`js`
module.exports.replace = () => ({
'async (__a) => __b': 'async ({process}) => __b',
});
Checkout in πPutout Editor:
`js`
module.exports.traverse = ({push, options}) => ({
__filesystem {
const {names} = options;
for (const name of names) {
const files = findFile(path, name);
for (const file of files) {
push({
name,
path: file,
});
}
}
},
});
`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,
});
}
}
};
`js`
module.exports.preProcess = () => {};
module.exports.postProcess = () => {};
`js`
module.exports.branch = (rawSource) => [];
module.exports.merge = (processedSource, list) => '';
- property simpler to work with;
- support of convert-destructuring-to-identifier which is Replacer, while convert-method-to-property is Includer (searches for ObjectMethod node);
`js`
module.exports.match = () => ({
'module.exports.traverse = __a'({}, path) {},
});
`js`
module.exports.match = () => ({
'module.exports.traverse = __a': ({}, path) => {},
});
Checks that Declarator transform is possible.
Checkout in πPutout Editor:
`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.rule
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 and make transforms more stable.*
Checks that Replacer transform is possible.
Pass once=false to always fail no matter how many fixCounts passed.
`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.rule
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 and make transforms more stable.*
Checks that Replacer match() keys exists in replace.
Checkout in πPutout Editor.
`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.rule
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 and make transforms more stable.*
Depends on @putout/convert-esm-to-commonjs and
@putout/declare.
`js`
compare(a, 'const __a = __b');
isIdentifier(a);
`js
const {operator, types} = require('putout');
const {compare} = operator;
const {isIdentifier} = types;
compare(a, 'const __a = __b');
isIdentifier(a);
`
Checkout in πPutout Editor.
`js`
export const match = () => ({
'__a(__args': (vars, path) => {
fn(x);
return __args[__a];
},
});
`js`
export const match = () => ({
'__a(__args': ({__args, __a}, path) => {
fn(x);
return __args[__a];
},
});
Checkout in πPutout Editor.
`js`
export const match = () => ({
'__x __a __expr': ({__x}) => {
if (path.isNextPunctuator(assign))
return false;
return isOneOfKeywords(__x, ['const', 'let', 'var']);
},
});
`js`
export const match = () => ({
'__x __a __expr': ({__x}) => {
if (path.isNextPunctuator(assign))
return false;
return isOneOfKeywords(__x, ['const', 'let', 'var']);
},
});
comparePlaces takes two or more arguments.
Checkout in πPutout Editor.
`js`
comparePlaces('hello');
`js`
comparePlaces('hello', []);
Checkout in πPutout Editor.
`js`
export const fix = () => {
path.remove();
};
`js`
export const fix = (path) => {
path.remove();
};
Checkout in πPutout Editor.
`js`
export const traverse = () => ({
TSUnionType() {
console.log(path);
},
});
`js`
export const traverse = () => ({
TSUnionType(path) {
console.log(path);
},
});
Checkout in πPutout Editor.
`js`
export const scan = (root, {trackFile}) => {
for (const file of trackFile(root, names)) {
push(file);
}
};
`js`
export const scan = (root, {trackFile, push}) => {
for (const file of trackFile(root, names)) {
push(file);
}
};
`js`
test('', () => {
comparePlaces();
});
`js`
test('', ({comparePlaces}) => {
comparePlaces();
});
Checkout in πPutout Editor.
Supported args:
- push:
`js`
module.exports.traverse = () => ({
'__a.replace(/__b/g, __c)': (path) => {
push(path);
},
});
`js`
module.exports.traverse = ({push}) => ({
'__a.replace(/__b/g, __c)': (path) => {
push(path);
},
});
- store
`js`
module.exports.traverse = () => ({
ImportDeclaration(path) {
const {node} = path;
const {name} = node.specifiers[0].local;
store('name', name);
},
});
`js`
module.exports.traverse = ({store}) => ({
ImportDeclaration(path) {
const {node} = path;
const {name} = node.specifiers[0].local;
store('name', name);
},
});
`js`
export const traverse = () => ({
ImportDeclaration(path) {
listStore(path);
},
});
`js`
module.exports.traverse = ({listStore}) => ({
ImportDeclaration(path) {
listStore(path);
},
});
`js`
export const traverse = () => ({
'module.exports.match = __object': pathStore,
});
`js`
export const traverse = ({pathStore}) => ({
'module.exports.match = __object': pathStore,
});
Checkout in πPutout Editor.
`js`
test('', ({progress}) => {
progress();
});
`js`
test('', async ({progress}) => {
await progress();
});
Checkout in πPutout Editor.
`js`
export const scan = (root, {push, progress}) => {
crawlFile();
};
`js`
export const scan = (root, {push, progress, crawlFile}) => {
crawlFile();
};
Checkout in πPutout Editor.
`js`
export const scan = (root, {push, progress}) => {
trackFile();
};
`js`
export const scan = (root, {push, progress, trackFile}) => {
trackFile();
};
`js
const {operator} = require('putout');
const {addArgument} = operator;
module.exports = addArgument({
t: ['t', 'test("__a", (__args) => __body)'],
});
`
`js
const {operator} = require('putout');
const {addArgs} = operator;
module.exports = addArgs({
t: ['t', 'test("__a", (__args) => __body)'],
});
`
`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,
});
`
`js
import {createTest} from '@putout/test';
import plugin from '@putout/plugin-debugger';
const test = createTest(import.meta.url, {
'remove-debugger': plugin,
});
`
`js
const {createTest} = require('@putout/test');
const plugin = require('@putout/plugin-debugger');
const test = createTest(__dirname, {
'remove-debugger': plugin,
});
`
`js
const {createTest} = require('@putout/test');
const plugin = require('@putout/plugin-debugger');
const test = createTest(import.meta.url, {
'remove-debugger': plugin,
});
`
`js'report' should be a 'function'
module.exports.report = ;`
`js'report' should be a 'function'
module.exports.report = () => ;`
Checkout in πPutout Editor.
`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,
});
}
};
`js`
module.exports.scan = (root, {push, trackFile}) => {
for (const file of trackFile(root, ['*'])) {
push(file);
}
};
- β
import Nested plugins in Deno and Browser;
- β
easier bundle with rollup without dynamicRequireTargets;
- β
easier to migrate to ESM;
Checkout in πPutout Editor.
`js`
module.exports.rules = getRule('remove-unused-variables');
`js
const removeUnusedVariables = require('./remove-unused-variables');
module.exports.rules = {
'remove-unused-variables': removeUnusedVariables,
};
`
To read file content use readFileContent and never confuse.
Checkout in πPutout Editor.
`js`
const content = getFileContent(file);
`js`
const content = readFileContent(file);
`js
const test = require('@putout/test')(__dirname, {
'remove-debugger': require('..'),
});
test('remove debugger: report', (t) => {
t.transform('debugger', {
'remove-debugger': require('..'),
});
t.end();
});
`
`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();
});
`
`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',
];
`
`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',
];
`
Checks that test message and used operator are synchronized.
Check it out in πPutout Editor.
`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();
});
`
`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();
});
`
Check it out in πPutout Editor.
`js`
await process('input', []);
`js`
await process('input');
Check it out in πPutout Editor.
`js`
test('hello', (t) => {
t.transform('nested-labels', {});
});
`js`
test('hello', (t) => {
t.transform('nested-labels');
});
Check it out in πPutout Editor.
`js`
const {
overridesPath,
parserPath,
rulesPath,
} = getProperties(__jsonPath, [
'parser',
'rules',
'overrides',
'extends',
]);
`js`
const {
overridesPath,
parserPath,
rulesPath,
} = getProperties(__jsonPath, ['parser', 'rules', 'extends']);
Check it out in πPutout Editor.
`jsSet 'message' of 'Commit fixes'
test('github: set-message-of-commit-fixes: no report after transform', (t) => {
t.noReportAfterTransform('set-message-of-commit-fixes', );`
t.end();
});
`js`
test('github: set-message-of-commit-fixes: no report after transform', (t) => {
t.noReportAfterTransform('set-message-of-commit-fixes');
t.end();
});
Check it out in πPutout Editor.
putout printer used by default, so there is no need to pass it.
`js`
const test = createTest(__dirname, {
printer: 'putout',
plugins: [
['remove-unchanged-zero-declarations', plugin],
],
});
`js`
const test = createTest(__dirname, {
plugins: [
['remove-unchanged-zero-declarations', plugin],
],
});
Checkout in πPutout Editor.
`js`
module.exports.replace = () => ({
'if (__a) {__b} else {__c}': () => 'if (__a) __b; else __c',
});
`js`
module.exports.replace = () => ({
'if (__a) {__b} else {__c}': 'if (__a) __b; else __c',
});
Checkout in πPutout Editor.
`js`
test('flatlint: convert-comma-to-semicolon: no report: xxx', (t) => {
t.noReport('array');
t.end();
});
`js``
test('flatlint: convert-comma-to-semicolon: no report: array', (t) => {
t.noReport('array');
t.end();
});
MIT