The Sourcery Pre-Commit Hook

With the Sourcery pre-commit hook, you can:

  • set up automated code quality checks for every commit
  • review your code before you send it to a human reviewer
  • set up the same quality gates as in your CI system

screenshot Sourcery pre-commit hook failed

The recommended setup for a pre-commit hook:

repos:
  - repo: https://github.com/sourcery-ai/sourcery
    rev: v1.0.1
    hooks:
      - id: sourcery
        # The best way to use Sourcery in a pre-commit hook:
        # * review only changed lines:
        # * omit the summary
        args: [--diff=git diff HEAD, --no-summary]

For more details and configuration options, check out the Getting Started with pre-commit guide.