Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fixes the arrow parens thing in eslint, but is slightly broken
module.exports = (file, api, options) => {
const j = api.jscodeshift;
const root = j(file.source);
const getBodyStatement = fn => {
if (
fn.body.type == 'BlockStatement' &&
fn.body.body.length == 1
) {
const inner = fn.body.body[0];
if (
inner.type == 'ExpressionStatement'
) {
return inner.expression;
} else if (inner.type == 'ReturnStatement') {
return inner.argument;
}
}
return fn.body;
};
const createArrowFunctionExpression = fn => {
return j.arrowFunctionExpression(
fn.params,
getBodyStatement(fn),
false);
};
root
.find(j.ArrowFunctionExpression)
.forEach(path => {
return j(path).replaceWith(
createArrowFunctionExpression(path.value)
)
});
return root.toSource();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.