cf. https://codimd.nomadic-labs.com/p/YcXmjg1qv#/4
pre-commit is a tool that helps to configure git pre-commit hooks, with an abundance of already configured scripts
pre-commit install and configuration
- Install in system
(apt-get / brew ) install pre-commit
- install in repo
pre-commit install
- then (configure) edit .pre-commit-config.yaml
.pre-commit-config.yaml example (from https://gitlab.com/tezos/tezos/-/blob/master/.pre-commit-config.yaml?ref_type=heads )
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.9.0
hooks:
- id: shellcheck
args: [ "--external-sources" ]
- repo: https://github.com/cisagov/pre-commit-shfmt
rev: v0.0.2
hooks:
- id: shfmt
# These settings must mirror the ones set in `scripts/lint.sh`.
args: [ "-i", "2", "-sr", "-d" ]
- repo: https://github.com/arenadotio/pre-commit-ocamlformat
rev: 0439858
hooks:
- id: ocamlformat
args: [ "-i" ]
- repo: https://github.com/hadolint/hadolint
rev: v2.9.3
hooks:
- id: hadolint-docker
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.0
hooks:
- id: check-gitlab-ci
args: ["--verbose"]
files: '(\.gitlab-ci\.yml|\.gitlab/ci/.*\.yml)'
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.9.0
hooks:
- id: shellcheck
args: [ "--external-sources" ]
- repo: https://github.com/cisagov/pre-commit-shfmt
rev: v0.0.2
hooks:
- id: shfmt
# These settings must mirror the ones set in `scripts/lint.sh`.
args: [ "-i", "2", "-sr", "-d" ]
- repo: https://github.com/arenadotio/pre-commit-ocamlformat
rev: 0439858
hooks:
- id: ocamlformat
args: [ "-i" ]
- repo: https://github.com/hadolint/hadolint
rev: v2.9.3
hooks:
- id: hadolint-docker
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.0
hooks:
- id: check-gitlab-ci
args: ["--verbose"]
files: '(\.gitlab-ci\.yml|\.gitlab/ci/.*\.yml)'
General Notes about pre-commits
- runs only against staged files
- to run manually :
pre-commit run --all-files
- to run 1 check specifically (example : run only 1 plugin (shfmt) )
pre-commit run shfmt
Aucun commentaire:
Enregistrer un commentaire