Note: This guide assumes you are using rubocop for linting and RSpec for testing
Git hook scripts are useful for identifying simple issues before submission to code review. We run our hooks on every commit to automatically point out issues in code such as missing semicolons, trailing whitespace, and debug statements. By pointing these issues out before code review, this allows a code reviewer to focus on the architecture of a change while not wasting time with trivial style nitpicks.
brew install pre-commit
create a file named
.pre-commit-config.yaml in your project root.
repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.3.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - repo: https://github.com/mattlqx/pre-commit-ruby rev: v1.3.5 hooks: - id: rubocop - id: rspec
Updated configuration & discussion thread is maintained on GitHub.
now pre-commit will run automatically on git commit
Pre-Commit will only run on changed files during git commit.
In case you would like to run it on all the files:
pre-commit run --all-files
Feel free to config pre-commit according to your requirements.