Skip to content

How do you format your ruby code across developers and projects?

I confess, I’m in love with standardrb. I’ve used other formatting tools like the hound and rubocop, but standardrb is great because it takes all the choice away from me. I’ll be honest, I didn’t even look at the ruleset; the fact that some great ruby consultancies use it is enough for me. I just install the tool using bundle, add it to a pre commit hook, and all the ruby code I check in is formatted beautifully. And if there are any other flaws in my code that standardrb can catch (like an unused variable), they are noted before my code even commits.

Here’s my precommit hook.

if git rev-parse --verify HEAD >/dev/null 2>&1
then
        against=HEAD
else
        # Initial commit: diff against an empty tree object
        against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

# Redirect output to stderr.
exec 1>&2

standardrb --fix app test config

The one issue I have is that when changes are made by standardrb, the commit fails, but I have to remember to re-add the modified files. Nothing a little –amend can’t fix, but slightly annoying.

Sometimes taking choice away gives you more freedom. Try standardrb today.

Cultivate

Join the Culture Foundry Community

Even if you’re not ready to make the leap yet, you’ll find our community to be a helpful source of key insights and advice to help you learn more about how to thrive in digital. All are welcome.

Join the Community