How to use the putout.types 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 / 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 / plugin-putout / lib / convert-to-no-transform-code / index.js View on Github external
'use strict';

const {
    isIdentifier,
    Identifier,
} = require('putout').types;

module.exports.report = () => {
    return `"noTransformCode" should be called instead of using same arguments twice in "transformCode"`;
};

module.exports.traverse = ({push}) => {
    return {
        CallExpression(path) {
            const calleePath = path.get('callee');
            
            if (!calleePath.isMemberExpression())
                return;
            
            const {object, property} = calleePath.node;
            
            if (object.name !== 't' || property.name !== 'transformCode')
github coderaiser / putout / packages / plugin-convert-esm-to-commonjs / lib / fix / index.js View on Github external
'use strict';

const {
    isExportNamedDeclaration,
    isExportDefaultDeclaration,
    isImportDeclaration,
} = require('putout').types;

const {
    convertNamedExport,
    convertDefaultExport,
} = require('./export');

const {convertImport} = require('./import');

module.exports = (path) => {
    const {node} = path;
    
    if (isExportNamedDeclaration(node))
        return convertNamedExport(path);
    
    if (isExportDefaultDeclaration(node))
        return convertDefaultExport(path);
github coderaiser / putout / packages / plugin-remove-unused-variables / lib / get-vars / get-vars.js View on Github external
'use strict';

const {
    isAssignmentPattern,
    isClassDeclaration,
    isIdentifier,
    isSpreadElement,
    isObjectPattern,
    isObjectExpression,
    isFunctionDeclaration,
    isArrayExpression,
    isVariableDeclaration,
} = require('putout').types;

const {
    traverseObjectExpression,
    processObjectPattern,
    traverseArrayExpression,
    traverseAssignmentExpression,
    traverseTemplateLiteral,
} = require('./traverse');

const {assign} = Object;

const jsx = require('./jsx');
const flow = require('./flow');
const typescript = require('./typescript');

module.exports = ({use, declare, addParams}) => {
github coderaiser / putout / packages / plugin-remove-unused-variables / lib / get-vars / traverse.js View on Github external
'use strict';

const {
    isIdentifier,
    isObjectExpression,
    isObjectPattern,
    isTemplateLiteral,
    isAssignmentPattern,
} = require('putout').types;

const traverseObjectPattern = ({use, declare}) => {
    const traverseAssign = traverseAssignmentPattern({
        use,
    });
    
    return (propertiesPaths) => {
        for (const path of propertiesPaths) {
            const {key} = path.node;
            const valuePath = path.get('value');
            
            if (isIdentifier(key))
                declare(path, key.name);
            
            if (valuePath.isAssignmentPattern())
                traverseAssign(valuePath);
github coderaiser / putout / packages / plugin-madrun / lib / rename-series-to-run / index.js View on Github external
'use strict';

const {isIdentifier} = require('putout').types;

module.exports.report = () => `"run" should be called instead of "series"`;

module.exports.traverse = ({push}) => {
    return {
        CallExpression(path) {
            if (!isIdentifier(path.node.callee, {name: 'series'}))
                return;
            
            push(path);
        },
    };
};

module.exports.fix = (path) => {
    path.node.callee.name = 'run';
github coderaiser / putout / packages / plugin-react-hooks / lib / convert-state-to-hooks / index.js View on Github external
'use strict';

const {
    isIdentifier,
    isMemberExpression,
    isThisExpression,
    isObjectExpression,
    isAssignmentExpression,
} = require('putout').types;

const {traverseClass} = require('../common');
const stateToHooks = require('./state-to-hooks');
const setStateToHooks = require('./set-state-to-hooks');

module.exports.report = (path) => {
    if (isAssignmentExpression(path))
        return 'hooks should be used instead of this.state';
    
    if (isVarFromState(path))
        return 'hooks should be used instead of this.state';
    
    if (isThisSetState(path))
        return 'hooks should be used instead of this.setState';
};
github coderaiser / putout / packages / codemod-convert-path-to-chunk / lib / convert-path-get / index.js View on Github external
'use strict';

const {
    isMemberExpression,
    Identifier,
} = require('putout').types;

module.exports.report = () => {
    return `"path.property should be used instead of "path.get('property')"`;
};

module.exports.find = (ast, {push, traverse}) => {
    traverse(ast, {
        CallExpression(chunk) {
            if (!isMemberExpression(chunk.callee))
                return;
            
            const {property} = chunk.callee;
            
            if (property.name !== 'get')
                return;
github coderaiser / putout / packages / plugin-strict-mode / lib / add / index.js View on Github external
'use strict';

const {
    isExpressionStatement,
    StringLiteral,
    ExpressionStatement,
} = require('putout').types;

const store = require('fullstore');

module.exports.report = () => '"use strict" directive should be on top of commonjs file';

module.exports.fix = ({node}) => {
    node.body.unshift(ExpressionStatement(StringLiteral('use strict')));
};

module.exports.traverse = ({push}) => {
    const isModule = store();
    let added = false;
    
    return {
        'ImportDeclaration|ExportNamedDeclaration|ExportDefaultDeclaration|TypeAlias'() {
            isModule(true);