How to use putout - 10 common examples

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-unused-variables / lib / get-vars / get-vars.js View on Github external
continue;
                }
                
                if (isAssignmentPattern(node)) {
                    traverseAssign(paramPath);
                    continue;
                }
                
                if (isObjectPattern(node)) {
                    processObj(paramPath.get('properties'));
                    continue;
                }
            }
            
            // ArrowFunction only
            if (isIdentifier(body))
                use(path, body.name);
            
            addParams({
                path,
                params,
            });
        },
        ...jsx(use),
github coderaiser / putout / packages / plugin-remove-unused-variables / lib / get-vars / get-vars.js View on Github external
}
            
            for (const paramPath of paramsPaths) {
                const {node} = paramPath;
                
                if (isIdentifier(node)) {
                    declare(paramPath, node.name);
                    continue;
                }
                
                if (isAssignmentPattern(node)) {
                    traverseAssign(paramPath);
                    continue;
                }
                
                if (isObjectPattern(node)) {
                    processObj(paramPath.get('properties'));
                    continue;
                }
            }
            
            // ArrowFunction only
            if (isIdentifier(body))
                use(path, body.name);
            
            addParams({
                path,
                params,
            });
        },
        ...jsx(use),
github coderaiser / putout / packages / plugin-remove-unused-variables / lib / get-vars / get-vars.js View on Github external
if (id) {
                declare(path, node.id.name);
                
                if (!parentPath.isBlock() && !parentPath.isProgram())
                    use(path, node.id.name);
            }
            
            for (const paramPath of paramsPaths) {
                const {node} = paramPath;
                
                if (isIdentifier(node)) {
                    declare(paramPath, node.name);
                    continue;
                }
                
                if (isAssignmentPattern(node)) {
                    traverseAssign(paramPath);
                    continue;
                }
                
                if (isObjectPattern(node)) {
                    processObj(paramPath.get('properties'));
                    continue;
                }
            }
            
            // ArrowFunction only
            if (isIdentifier(body))
                use(path, body.name);
            
            addParams({
                path,
github coderaiser / putout / packages / compare / lib / log.spec.js View on Github external
'use strict';

const test = require('supertape');
const mockRequire = require('mock-require');
const {Identifier} = require('putout').types;

const {reRequire} = mockRequire;
const stub = require('@cloudcmd/stub');

const {assign} = Object;

test('putout: run-plugins: template: log', (t) => {
    const namespace = stub();
    
    assign(namespace, {
        enabled: true,
    });
    
    const debug = stub().returns(namespace);
    
    mockRequire('debug', debug);
github coderaiser / putout / packages / plugin-madrun / lib / call-run / index.js View on Github external
'use strict';

const {
    isStringLiteral,
    stringLiteral,
    identifier,
    callExpression,
    arrayExpression,
} = require('putout').types;

module.exports.report = ({name}) => {
    return `"run" should be called in script: "${name}"`;
};

module.exports.traverse = ({push}) => {
    return {
        ArrowFunctionExpression(path) {
            const {body} = path.node;
            
            if (!isStringLiteral(body))
                return;
            
            const {value} = body;
            
            if (!/^(redrun|npm run)/.test(value))
github coderaiser / putout / packages / compare / lib / log.spec.js View on Github external
test('putout: run-plugins: template: log: object', (t) => {
    const namespace = stub();
    
    assign(namespace, {
        enabled: true,
    });
    
    const debug = stub().returns(namespace);
    
    mockRequire('debug', debug);
    
    const log = reRequire('./log');
    
    log(Identifier('hello'), Identifier('world'));
    const expected = `Identifier: "hello" = Identifier: "world"`;
    
    t.ok(namespace.calledWith(expected));
    t.end();
});
github coderaiser / putout / packages / plugin-madrun / lib / call-run / index.js View on Github external
module.exports.fix = ({path, value}) => {
    const [line, arg] = value.split(' -- ');
    const scripts = getScripts(line);
    
    const strs = [];
    for (const script of scripts) {
        strs.push(stringLiteral(script));
    }
    
    const runArgs = getRunArgs(strs, arg);
    
    path.node.body = callExpression(identifier('run'), runArgs);
};
github coderaiser / putout / packages / plugin-madrun / lib / call-run / index.js View on Github external
module.exports.fix = ({path, value}) => {
    const [line, arg] = value.split(' -- ');
    const scripts = getScripts(line);
    
    const strs = [];
    for (const script of scripts) {
        strs.push(stringLiteral(script));
    }
    
    const runArgs = getRunArgs(strs, arg);
    
    path.node.body = callExpression(identifier('run'), runArgs);
};
github coderaiser / putout / packages / plugin-remove-unused-variables / lib / get-vars / get-vars.js View on Github external
UnaryExpression(path) {
            const {argument} = path.node;
            
            if (isIdentifier(argument))
                use(path, argument.name);
        },
github coderaiser / putout / packages / plugin-remove-unused-variables / lib / get-vars / get-vars.js View on Github external
SwitchStatement(path) {
            const {node} = path;
            
            if (isIdentifier(node.discriminant))
                use(path, node.discriminant.name);
            
            for (const {test} of node.cases) {
                if (isIdentifier(test))
                    use(path, test.name);
            }
        },