Skip to content

Instantly share code, notes, and snippets.

@killtheliterate
Last active August 29, 2015 14:02
Show Gist options
  • Save killtheliterate/62ff5163f3633b694a64 to your computer and use it in GitHub Desktop.
Save killtheliterate/62ff5163f3633b694a64 to your computer and use it in GitHub Desktop.
git hook recommendations

Git hooks to validate code style

This recommendation is motivated by the fact that a common code style will reduce extraneous git diffs caused by formatting differences. The git log will be more parseable.

A pre-commit hook is the appropriate hook to use for validating code changes before committing. We can use a precommit hook to:

  • Validate JavaScript with jshint: example
  • Validate white space usage: example
  • Run staged files through js-beautify, in verify-only mode

The pre-commit hook should be used to run the CLI version of programs, not necessarily invoking them with Grunt. This should allow us more flexibility in controlling what constitues a "pass" or "fail" when verifying.

One other another thing

Git hooks can't be shared in the repo itself (imagine a hook that runs rm -rf /), so we'll need to have a simple way for sharing hooks. I'd recommend a repo on Github. Additionally, it might be wise to have some common Git settings tracked in a per repo gitconfig, such as how EOF is handled.

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