Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
isImportNamespaceSpecifier,
} = types;
const getName = ({source}) => source.raw;
const convert = template(`
const DECLARATION = require(NAME);
`);
const convertDestructureRename = template(`
const {
IMPORTED: LOCAL,
} = require(NAME);
`);
const convertDestructure = template(`
const {
IMPORTED,
} = require(NAME);
`);
const convertEmpty = template(`
require(%%name%%);
`);
module.exports.convertImport = (path) => {
const {node} = path;
const {specifiers} = node;
const name = getName(node);
const vars = [];
'use strict';
const {operate, template} = require('putout');
const {replaceWith} = operate;
const buildArrayFrom = template(`
Array.from(%%argument%%);
`);
module.exports.report = () => `Array.from should be used instead of array spread`;
module.exports.fix = (path) => {
const [element] = path.node.elements;
const {argument} = element;
const ast = buildArrayFrom({
argument,
});
replaceWith(path, ast);
};
'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);
nodes.push(buildHooks({
SETTER,
VALUE,
}));
module.exports.convertDefaultExport = (path) => {
const {declaration} = path.node;
const convert = template(`
module.exports = DECLARATION;
`);
const DECLARATION = getDeclaration(declaration);
replaceWith(path, convert({
DECLARATION,
}));
};
'use strict';
const {template, operate} = require('putout');
const {replaceWithMultiple} = operate;
const buildHooks = template(`
const [NAME, SETTER] = useState(VALUE);
`);
module.exports = (path) => {
const {right} = path.node;
const nodes = [];
for (const {key, value} of right.properties) {
const {name} = key;
const NAME = name;
const SETTER = getSetter(name);
const VALUE = String(value.value);
nodes.push(buildHooks({
NAME,
SETTER,
replaceWithMultiple,
} = operate;
const {
isImportSpecifier,
isImportDefaultSpecifier,
isImportNamespaceSpecifier,
} = types;
const getName = ({source}) => source.raw;
const convert = template(`
const DECLARATION = require(NAME);
`);
const convertDestructureRename = template(`
const {
IMPORTED: LOCAL,
} = require(NAME);
`);
const convertDestructure = template(`
const {
IMPORTED,
} = require(NAME);
`);
const convertEmpty = template(`
require(%%name%%);
`);
module.exports.convertImport = (path) => {
const DECLARATION = require(NAME);
`);
const convertDestructureRename = template(`
const {
IMPORTED: LOCAL,
} = require(NAME);
`);
const convertDestructure = template(`
const {
IMPORTED,
} = require(NAME);
`);
const convertEmpty = template(`
require(%%name%%);
`);
module.exports.convertImport = (path) => {
const {node} = path;
const {specifiers} = node;
const name = getName(node);
const vars = [];
if (!specifiers.length)
return replaceWith(path, convertEmpty({name}));
for (const spec of specifiers) {
if (isImportDefaultSpecifier(spec)) {
vars.push(getImportDefaultVar(name, spec));
'use strict';
const {
template,
operate,
types,
} = require('putout');
const {
replaceWith,
replaceWithMultiple,
} = operate;
const forOfTemplate = template(`
for (const %%item%% of %%items%%)
%%body%%
`);
const {ContinueStatement} = types;
const {keys} = Object;
const isRoot = (path) => path.isFunction() || path.isProgram();
module.exports.report = () => `for-of should be used instead of forEach`;
module.exports.fix = (path) => {
const {params, body} = path.node.arguments[0];
const item = getItem(params);
delete item.typeAnnotation;
'use strict';
const {
template,
generate,
types,
operate,
} = require('putout');
const {replaceWith} = operate;
const {isIdentifier} = types;
module.exports.report = () => `Object properties should be extracted into variables`;
const buildAst = template(`
const {PROPERTY} = OBJECT;
`);
module.exports.fix = ({items}) => {
const names = [];
for (const item of items) {
const {object, property} = item.node;
if (isIdentifier(property) && !names.includes(property.name)) {
names.push(property.name);
const {
body = item.scope.block.body,
} = item.scope.block.body;
body.unshift(buildAst({
} = require('putout');
const {
replaceWith,
replaceWithMultiple,
} = operate;
const {
isImportSpecifier,
isImportDefaultSpecifier,
isImportNamespaceSpecifier,
} = types;
const getName = ({source}) => source.raw;
const convert = template(`
const DECLARATION = require(NAME);
`);
const convertDestructureRename = template(`
const {
IMPORTED: LOCAL,
} = require(NAME);
`);
const convertDestructure = template(`
const {
IMPORTED,
} = require(NAME);
`);
const convertEmpty = template(`