Skip to content

tenthirtyam/pre-commit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

pre-commit hooks

License  

This repository contains a comprehensive set of Git pre-commit hooks that are specifically designed to work seamlessly with the pre-commit framework. These hooks aim to automate critical tasks such as code formatting, validation, linting, and other quality assurance checks, ensuring that your code adheres to best practices and project standards before it is committed to the repository.

By integrating these hooks into your workflow, you can catch and address common issues early in the development process, reducing the likelihood of bugs and inconsistencies making their way into your codebase. The pre-commit framework makes it straightforward to configure and enforce these checks across your team, promoting consistency and improving overall code quality.

The hooks included in this repository cover a wide range of use cases and technologies, supporting multiple file types and tools. Whether you are working with Terraform, Golang, Python, Markdown, or Bash scripts, you will find hooks tailored to your needs. From formatting and linting to validating configurations, these hooks help streamline your development process and enforce coding standards.

Hooks

The currently supported hooks are listed below, categorized by technology and file type, to make it easier to identify the tools most relevant to your project requirements.

Go

  • gofmt: Runs gofmt on all Go (*.go files).
  • golangci-lint: Runs golangci-lint on all Go (*.go) files.
  • goimports: Runs goimports on all Go (*.go) files.
  • go build: Verify that go build runs successfully for all your Go project.
  • go mod tidy: Runs go mod tidy to ensure go.mod and go.sum are up-to-date.

Python

  • yapf: Runs yapf on all Python (*.py) files.

Terraform / OpenTofu

  • terraform-fmt: Runs terraform fmt on all Terraform (*.tf) files.
  • terraform-validate: Runs terraform validate on all Terraform (*.tf) files.
  • terragrunt-hclfmt: Runs terragrunt hclfmt on all Terragrunt files.
  • tofu-fmt: Runs tofu fmt on all OpenTofu (*.tf, *.terraform) files.
  • tofu-validate: Runs tofu validate on all OpenTofu (*.tf, *.terraform) files.

Packer

  • packer-fmt:
  • packer-validate: Runs packer validate on all Packer (*.pkr.*)files.

Markdown

  • markdown-link-check: Runs markdown-link-check on markdown (*.md) files.

Bash/Shell

Getting Started

In each of your repos, add a file called .pre-commit-config.yaml with the following contents:

repos:
  - repo: https://github.com/tenthirtyam/pre-commit
    rev: x.y.z # Example only; get the latest from: https://github.com/tenthirtyam/pre-commit/releases
    hooks:
      - id: terraform-fmt
      - id: terraform-validate
      - id: shellcheck
      - id: gofmt
      - id: golint

Next:

  1. Install pre-commit on your system:

    brew install pre-commit
  2. In your repository, run the following command:

    pre-commit install

Each time you make a commit, the hooks defined in the hooks: configuration will run.

Tips

Tip

Formatting All Files

If you'd like to format all of your code at once (rather than one file at a time), you can run:

pre-commit run terraform-fmt --all-files

Tip

Formatting All Files in a CI

To ensure all hooks are enforced, configure your CI build to fail if the code does not pass the checks by adding the following to your build scripts:

pip install pre-commit
pre-commit install
pre-commit run --all-files

If all hooks succeed, the final command will exit with an exit code 0.

However, if any hooks make changes (e.g., due to unformatted files), this will result in a failure and exit with an exit code 1.

Sponsor

Sponsor   Buy me a Coffee

License

Copyright © Ryan Johnson

Licensed under the MIT License.

About

Pre-Commit Hooks.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Languages