pre-commit

Inspiration

Because of issues installing on Windwos and line endings getting messed up, I installed pre-commit to fix bugs as they arised.

Future features have been added if a need has been presented.

This is installed in the Dockerfile for you, but you can choose to install this on it’s own if you wish to do so without a container. It is especially nice to avoid any platform specific bugs (see Quickstart), although your IDE can normally do enough to get you by. GitHub actions will also fix errors for you when possible.

.pre-commit-config.yml

Inspired by https://gdevops.gitlab.io/tuto_git/tools/pre-commit/repos_hooks/repo_pre_commit_hooks/mixed-line-ending/mixed-line-ending.html:

---
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.3.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-json
      - id: forbid-new-submodules
      - id: mixed-line-ending
        args: ["--fix=lf"]
        description: Forces to replace line ending by the UNIX 'lf' character.
      - id: check-added-large-files
        args: ["--maxkb=500"]
      - id: no-commit-to-branch
        args: [--branch, staging]
  - repo: https://github.com/adrienverge/yamllint
    rev: v1.35.1
    hooks:
      - id: yamllint
  - repo: https://github.com/AleksaC/hadolint-py
    rev: v2.12.1b3
    hooks:
      - id: hadolint

Usage

Install the hooks:

pre-commit install --install-hooks

Then to run manually without needing a git commit:

pre-commit run --all-files

Otherwise pre-commit checks happen upon each invokation of git commit.