UNPKG

@putout/plugin-madrun

Version:

🐊Putout plugin adds ability to transform madrun scripts

38 lines (28 loc) 872 B
import {template, operator} from 'putout'; const {replaceWith, getProperty} = operator; export const report = () => 'test: "-d" can be removed, duplicates checked by default'; export const fix = ({path, line}) => { const c8 = line.replace('tape -d', 'tape'); replaceWith(path, template.ast(c8)); }; export const traverse = ({push}) => ({ 'export default __object'(path) { const declarationPath = path.get('declaration'); const testPath = getProperty(declarationPath, 'test'); add(testPath, { push, }); }, }); function add(currentPath, {push}) { if (!currentPath) return; const bodyPath = currentPath.get('value.body'); const line = bodyPath.toString(); if (!line.includes('tape -d')) return; push({ path: bodyPath, line, }); }