Skip to content

Instantly share code, notes, and snippets.

@wguto
Last active October 13, 2021 10:34
Show Gist options
  • Save wguto/15ae2be2decf73672b56c734a03f9021 to your computer and use it in GitHub Desktop.
Save wguto/15ae2be2decf73672b56c734a03f9021 to your computer and use it in GitHub Desktop.
pre-commit-hooks

Pre-commit

It's strong recommended to use pre-commit framework to help maintain a good code.

You can see more details directly in the site of the framework but a simple way to install is using homebrew.

brew install pre-commit

The specilized hooks used by terraform needs some packages too. Again the easiest way is using homebrew.

brew install pre-commit terraform-docs

If everything works correctly, before commiting, pre-commit will check all staged files, as in the example below.

$ git commit -am ""
Check for merge conflicts................................................Passed
Trim Trailing Whitespace.................................................Passed
Check JSON...........................................(no files to check)Skipped
Detect AWS Credentials...................................................Passed
Terraform fmt........................................(no files to check)Skipped
Terraform docs.......................................(no files to check)Skipped
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
# Docs https://pre-commit.com/hooks.html
hooks:
# Git style
- id: check-added-large-files
- id: check-merge-conflict
- id: no-commit-to-branch
# Common errors
- id: end-of-file-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: check-yaml
- id: check-json
- id: check-merge-conflict
- id: check-executables-have-shebangs
# Cross platform
- id: check-case-conflict
# Security
- id: detect-aws-credentials
args: ['--allow-missing-credentials']
- id: detect-private-key
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.52.0
# Docs https://github.com/antonbabenko/pre-commit-terraform#available-hooks
hooks:
- id: terraform_fmt
- id: terraform_docs
- id: terragrunt_validate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment