import {types, operator} from 'putout'; const { isForStatement, variableDeclaration, } = types; const { replaceWithMultiple, isKeyword, } = operator; export const report = () => 'Variables should be declared separately'; export const fix = (path) => { const {node} = path; const varNodes = getVarNodes(node); replaceWithMultiple(path, varNodes); }; export const include = () => [ 'VariableDeclaration', ]; export const filter = (path) => { const { node, parent, parentPath, } = path; const {declarations} = node; if (parentPath.isExportDeclaration()) return false; if (declarations.length === 1) return false; for (const declaration of declarations) { const {name} = declaration.id; if (isKeyword(name)) return false; } const init = node; return !isForStatement(parent, { init, }); }; function getVarNodes({kind, declarations}) { const result = []; for (const declaration of declarations) { const declarations = [declaration]; result.push(variableDeclaration( kind, declarations, )); } return result; }