eslint-plugin-putout
Version:
ESLint plugin for 🐊Putout
26 lines (19 loc) • 694 B
JavaScript
;
module.exports.category = 'destructuring';
module.exports.report = () => 'Keep all properties in one line when using destructuring in for-of';
module.exports.include = ({options}) => {
const {maxProperties = 8} = options[0] || {};
return [`VariableDeclarator[id.type="ObjectPattern"][id.properties.length<${maxProperties}]`];
};
module.exports.filter = ({node, text}) => {
if (node.parent.parent.type !== 'ForOfStatement')
return false;
return text.includes('\n');
};
module.exports.fix = ({text}) => {
return text
.replace(/\n/g, '')
.replace(/,/g, ', ')
.replace(/{\s*/g, '{')
.replace(/\s*}/g, '}');
};