Difference between revisions of "Git/pre-commit"

From Ever changing code
< Git
Jump to navigation Jump to search
Line 6: Line 6:
= Sample <code>.pre-commit-config.yaml</code> =
= Sample <code>.pre-commit-config.yaml</code> =
<syntaxhighlightjs lang=yaml>
<syntaxhighlightjs lang=yaml>
# verified with pre-commit v2.16.0
repos:
repos:
   - repo: git://github.com/pre-commit/pre-commit-hooks
   - repo: git://github.com/pre-commit/pre-commit-hooks
Line 19: Line 20:
       - id: mixed-line-ending
       - id: mixed-line-ending
       - id: trailing-whitespace
       - id: trailing-whitespace
   - repo: git://github.com/antonbabenko/pre-commit-terraform.git
   - repo: local
    rev: v1.62.3
     hooks:
     hooks:
       - id: terraform_fmt
       - id: terraform-docs
      - id: terraform_docs
        name: terraform-docs
        language: docker_image
        entry: quay.io/terraform-docs/terraform-docs:0.16.0
        args: ["--config", ".terraform-docs.yml", "markdown", "."]
        pass_filenames: false
   - repo: https://github.com/gruntwork-io/pre-commit
   - repo: https://github.com/gruntwork-io/pre-commit
     rev: v0.1.17
     rev: v0.1.17
Line 39: Line 43:
     hooks:
     hooks:
       - id: gitleaks
       - id: gitleaks
</syntaxhighlightjs>
</syntaxhighlightjs>



Revision as of 13:26, 23 December 2021

Install

pip install pre-commit

Sample .pre-commit-config.yaml

<syntaxhighlightjs lang=yaml>

  1. verified with pre-commit v2.16.0

repos:

 - repo: git://github.com/pre-commit/pre-commit-hooks
   rev: v4.0.1
   hooks:
     - id: fix-byte-order-marker
     - id: check-case-conflict
     - id: check-merge-conflict
     - id: detect-aws-credentials
       args: ['--allow-missing-credentials']
     - id: detect-private-key
     - id: end-of-file-fixer
     - id: mixed-line-ending
     - id: trailing-whitespace
 - repo: local
   hooks:
     - id: terraform-docs
       name: terraform-docs
       language: docker_image
       entry: quay.io/terraform-docs/terraform-docs:0.16.0
       args: ["--config", ".terraform-docs.yml", "markdown", "."]
       pass_filenames: false
 - repo: https://github.com/gruntwork-io/pre-commit
   rev: v0.1.17
   hooks:
     - id: shellcheck
 - repo: https://github.com/dnephin/pre-commit-golang.git
   rev: v0.4.0
   hooks:
     - id: go-fmt
     - id: go-imports
     - id: go-lint
     - id: go-mod-tidy
 - repo: https://github.com/zricethezav/gitleaks
   rev: v8.2.4
   hooks:
     - id: gitleaks

</syntaxhighlightjs>

Operations

pre-commit install         # install all hooks
pre-commit run --all-files # run all hooks/checks
pre-commit autoupdate      # update all hooks to their latest versions, next time you `run` they will get downloaded

Hooks