UNPKG

@putout/plugin-madrun

Version:

🐊Putout plugin adds ability to transform madrun scripts

48 lines (34 loc) 1.24 kB
import {types} from 'putout'; const {isStringLiteral} = types; const replace = (a) => a .replace('eslint', 'putout') .replace(/\s--ignore.*/, ''); export const report = () => `Use "putout" instead of "eslint"`; export const fix = ({node}) => { const {type, value} = node; switch(type) { case 'StringLiteral': node.value = replace(value); break; case 'TemplateElement': node.value.raw = replace(value.raw); break; } }; export const traverse = ({push}) => ({ 'module.exports = __object'(path) { const properties = path.get('right.properties'); for (const prop of properties) { const {key} = prop.node; if (!isStringLiteral(key)) continue; if (key.value !== 'lint') continue; const body = prop.get('value.body'); if (body.isStringLiteral() && body.node.value.startsWith('eslint')) return push(body); if (body.isTemplateLiteral() && body.node.quasis[0].value.raw.startsWith('eslint')) return push(body.get('quasis.0')); } }, });