eslint-plugin-putout
Version:
ESLint plugin for 🐊Putout
53 lines (35 loc) • 994 B
JavaScript
;
const regExp = /^\n( +)?\n +$/;
module.exports.report = () => `Add newline before 'return'`;
module.exports.filter = ({text, node, getCommentsBefore, getSpacesBeforeNode}) => {
if (getCommentsBefore(node).length)
return false;
const {parent} = node;
const {body} = parent;
if (!body)
return false;
const n = body.length;
if (body[0] === node)
return false;
if (n < 3)
return false;
const spaces = getSpacesBeforeNode(node, text);
if (regExp.test(spaces))
return false;
let i = n - 1;
let count = 0;
while (--i) {
const prevA = body[i];
const spaces = getSpacesBeforeNode(prevA);
if (regExp.test(spaces))
break;
++count;
}
return !(count < 1);
};
module.exports.fix = ({text}) => {
return `\n${text}`;
};
module.exports.include = () => [
'ReturnStatement',
];