This repository uses pre-commit to automatically run checks before commits.
Pre-commit is already installed in the devcontainer. To enable the hooks:
pre-commit install
pre-commit install --hook-type commit-msg- Trailing whitespace
- End of file fixes
- Large files detection
- Merge conflict markers
- Private key detection
- ShellCheck linting
- Shebang validation
- Execute permissions
- Format checking (
terraform fmt) - Validation (
terraform validate) - Documentation generation
- Security scanning (checkov)
- Linting (tflint)
- Ansible-lint for playbooks
- YAML syntax validation
- Code formatting (black)
- Style checking (flake8)
- Import sorting
- Dockerfile linting (hadolint)
- Markdown linting
- YAML linting
- Secret detection
- Private key scanning
- Conventional commit message format
After installation, hooks run automatically on git commit:
git add .
git commit -m "feat: add new feature"
# Pre-commit hooks run automaticallyRun checks on all files:
pre-commit run --all-filesRun specific hook:
pre-commit run terraform-fmt --all-files
pre-commit run shellcheck --all-filesUpdate to latest versions:
pre-commit autoupdateNot recommended, but if needed:
git commit --no-verify -m "emergency fix"Hooks are configured in .pre-commit-config.yaml. To modify:
- Edit
.pre-commit-config.yaml - Update hook versions or add new hooks
- Run
pre-commit installagain - Test with
pre-commit run --all-files
# Reinstall hooks
pre-commit uninstall
pre-commit installpre-commit clean
pre-commit run --all-filesAdd to .pre-commit-config.yaml:
exclude: |
(?x)^(
path/to/exclude/|
specific-file.txt
)CI does not run pre-commit itself - it runs the linters that matter for this
repository directly, in the lint job of
.github/workflows/build.yml: bash -n and
shellcheck over every shell script, a JSON parse over every JSON file, and
hadolint over the Dockerfile.
Dockerfile lint rules live in .hadolint.yaml and are
shared, so the hadolint-docker hook here and the CI job agree by construction.
Ensure Terraform is initialized:
cd terraform/
terraform initCheck .ansible-lint configuration or update playbook syntax.
Fix Dockerfile issues or add ignore rules:
args: ['--ignore', 'DL3008', '--ignore', 'DL3009']Full list of enabled hooks:
| Hook | Purpose | Auto-fix |
|---|---|---|
| trailing-whitespace | Remove trailing spaces | ✓ |
| end-of-file-fixer | Ensure newline at EOF | ✓ |
| check-yaml | Validate YAML syntax | ✗ |
| check-json | Validate JSON syntax | ✗ |
| shellcheck | Lint shell scripts | ✗ |
| terraform-fmt | Format Terraform | ✓ |
| terraform-validate | Validate Terraform | ✗ |
| checkov | Security scanning | ✗ |
| ansible-lint | Lint Ansible | ✗ |
| black | Format Python | ✓ |
| flake8 | Lint Python | ✗ |
| hadolint | Lint Dockerfile | ✗ |
| markdownlint | Lint Markdown | ✓ |
| detect-secrets | Find secrets | ✗ |
| conventional-pre-commit | Validate commit msg | ✗ |
When adding new file types or tools, update .pre-commit-config.yaml with appropriate hooks.