# Pre-commit [[Git]] [pre-commit](https://pre-commit.com/) [pre-commit/pre-commit-hooks: Some out-of-the-box hooks for pre-commit](https://github.com/pre-commit/pre-commit-hooks) ## [[Husky]] ## Add pre-commit to project - create a file named `.pre-commit-config.yaml` to the root of your project ```yaml repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v2.3.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/psf/black rev: 22.10.0 hooks: - id: black ``` - pre-commit install - `git add .pre-commit-config.yaml` and commit to your repo and it should work. it's usually a good idea to run the hooks against all of the files when adding new hooks (usually `pre-commit` will only run on the changed files during git hooks) `pre-commit run --all-files` ## CI [pre-commit.ci](https://pre-commit.ci/) ### Add this to `.pre-commit-config.yaml` ``` ci: autofix_commit_msg: | [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci autofix_prs: true autoupdate_branch: '' autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate' autoupdate_schedule: weekly skip: [] submodules: false ``` ## Hooks & Repos to use for more checks - https://pre-commit.com/hooks.html - [ansible/ansible-lint: ansible-lint checks playbooks for practices and behavior that could potentially be improved](https://github.com/ansible/ansible-lint) - [detailyang/pre-commit-shell: :beers: pre commit wrapper shellcheck](https://github.com/detailyang/pre-commit-shell) - [antonbabenko/pre-commit-terraform: pre-commit git hooks to take care of Terraform configurations 🇺🇦](https://github.com/antonbabenko/pre-commit-terraform) - [Yelp/detect-secrets: An enterprise friendly way of detecting and preventing secrets in code.](https://github.com/Yelp/detect-secrets) - [markdownlint/markdownlint: Markdown lint tool](https://github.com/markdownlint/markdownlint) - [aquasecurity/tfsec: Security scanner for your Terraform code](https://github.com/aquasecurity/tfsec) - [google/yamlfmt: An extensible command line tool or library to format yaml files.](https://github.com/google/yamlfmt) - [ashwin153/pre-commit-vagrant: A collection of pre-commit hooks.](https://github.com/ashwin153/pre-commit-vagrant) - [norwoodj/helm-docs: A tool for automatically generating markdown documentation for helm charts](https://github.com/norwoodj/helm-docs)# Pre-commit