Skip to content

Instantly share code, notes, and snippets.

@dagingaa
Created January 26, 2016 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dagingaa/8b8d6e9eb264e69aec64 to your computer and use it in GitHub Desktop.
Save dagingaa/8b8d6e9eb264e69aec64 to your computer and use it in GitHub Desktop.
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