How to use the putout.operate function in putout

To help you get started, we’ve selected a few putout examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github coderaiser / putout / packages / plugin-remove-nested-blocks / lib / remove-nested-blocks.js View on Github external
'use strict';

const {replaceWithMultiple} = require('putout').operate;

module.exports.report = () => 'Nested blocks should not be used';

module.exports.fix = (path) => {
    replaceWithMultiple(path, path.node.body);
};

module.exports.traverse = ({push}) => {
    return {
        BlockStatement(path) {
            if (!path.parentPath.isBlockStatement())
                return;
            
            push(path);
        },
    };
github coderaiser / putout / packages / plugin-remove-useless-variables / lib / for-of / index.js View on Github external
'use strict';

const {replaceWith} = require('putout').operate;

module.exports.report = () => `Destructuring should be used in the head of for-of`;

module.exports.fix = ({path, varPath}) => {
    replaceWith(varPath, path.node.id);
    path.remove();
};

module.exports.traverse = ({push}) => {
    return {
        'for (const __ of __) __'(path) {
            const leftPath = path.get('left');
            const varPath = leftPath.get('declarations.0.id');
            
            if (!varPath.isIdentifier())
                return;
github coderaiser / putout / packages / plugin-react-hooks / lib / remove-this / index.js View on Github external
'use strict';

const {replaceWith} = require('putout').operate;

const {traverseClass} = require('../common');

module.exports.report = ({name}) => `should be used "${name}" instead of "this.${name}"`;

module.exports.fix = ({path}) => {
    replaceWith(path, path.get('property'));
};

module.exports.find = (ast, {push, traverse}) => {
    traverseClass(traverse, ast, {
        ThisExpression(path) {
            const {parentPath} = path;
            const propertyPath = parentPath.get('property');
            
            const {name} = propertyPath.node;
github coderaiser / putout / packages / plugin-react-hooks / lib / convert-state-to-hooks / set-state-to-hooks.js View on Github external
'use strict';

const {replaceWithMultiple} = require('putout').operate;

const {template} = require('putout');

const buildHooks = template(`
    SETTER(VALUE);
`);

module.exports = (path) => {
    const {properties} = path.node.arguments[0];
    const nodes = [];
    
    for (const {key, value} of properties) {
        const {name} = key;
        const SETTER = getSetter(name);
        const VALUE = String(value.value);
github coderaiser / putout / packages / _plugin-remove-useless-spread / lib / remove-useless-spread.js View on Github external
'use strict';

const {replaceWith} = require('putout').operate;

module.exports.report = () => `Useless spread should be avoided`;

module.exports.fix = (path) => {
    const [element] = path.node.elements;
    replaceWith(path, element.argument);
};

module.exports.include = () => [
    '[...__]',
];

module.exports.exclude= () => [
    '[...__].__()',
    'return [...__]',
];