Skip to content

Instantly share code, notes, and snippets.

@pseudomuto
Created January 3, 2017 13:57
Show Gist options
  • Save pseudomuto/6a094bb10d6ab576e92c9167181dbd79 to your computer and use it in GitHub Desktop.
Save pseudomuto/6a094bb10d6ab576e92c9167181dbd79 to your computer and use it in GitHub Desktop.
Linting Pre-Push Hooks
#!/bin/bash
set -euo pipefail
######################################################################
# Auto-formats code with RustFmt
# https://github.com/rust-lang-nursery/rustfmt
#
# After running, there will either be changes, or no changes.
#
# Possible outcomes:
# * No changes: push is executed
# * Changes: code has been formatted, user must accept the changes
######################################################################
cargo fmt -- --write-mode=overwrite
# return 0 if nothing's changed or staged
git diff --exit-code && git diff-index --quiet --cached HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment