Skip to content

Instantly share code, notes, and snippets.

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 glaucocustodio/a82a35500cd77c6f4b00aee813fe0212 to your computer and use it in GitHub Desktop.
Save glaucocustodio/a82a35500cd77c6f4b00aee813fe0212 to your computer and use it in GitHub Desktop.
Auto formatting changed Ruby files with Standard

Prerequisites

Create a git pre commit hook and give it permission to execute:

touch .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit

Add the following bash script to the hook:

#!/bin/sh

standardrb --fix --format progress $(git diff --name-only --diff-filter=ACMRTUXB master | grep -E "(.rb$)")

Useful links

@benmosher
Copy link

Very helpful, thanks! but heads up -- I had to update to | grep -E "(\.rb$)" to get just "*.rb" without *.erb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment