Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'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);
'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))
'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')
'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);
'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}) => {
'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);
'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';
'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';
};
'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;
'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);