pre-commit-standards
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePre-commit Standards
Pre-commit 标准
Version: 2025.1
版本:2025.1
Standard pre-commit configuration for repository compliance.
用于仓库合规的标准pre-commit配置。
Standard Versions (2025.1)
标准版本(2025.1)
| Hook | Version | Purpose |
|---|---|---|
| pre-commit-hooks | v5.0.0 | Core hooks (trailing-whitespace, check-yaml, etc.) |
| conventional-pre-commit | v4.3.0 | Conventional commit message validation |
| biome | v0.4.0 | Code formatting and linting (JS, TS, JSON) |
| gruntwork pre-commit | v0.1.29 | helmlint, tflint (infrastructure only) |
| actionlint | v1.7.7 | GitHub Actions validation (infrastructure only) |
| helm-docs | v1.14.2 | Helm documentation (infrastructure only) |
| gitleaks | v8.22.1 | Secret scanning (recommended) |
| 钩子 | 版本 | 用途 |
|---|---|---|
| pre-commit-hooks | v5.0.0 | 核心钩子(移除尾随空格、检查YAML格式等) |
| conventional-pre-commit | v4.3.0 | 约定式提交信息校验 |
| biome | v0.4.0 | 代码格式化与lint检查(JS、TS、JSON) |
| gruntwork pre-commit | v0.1.29 | helmlint、tflint(仅基础设施类项目) |
| actionlint | v1.7.7 | GitHub Actions配置校验(仅基础设施类项目) |
| helm-docs | v1.14.2 | Helm文档生成(仅基础设施类项目) |
| gitleaks | v8.22.1 | 敏感信息扫描(推荐启用) |
Project Type Configurations
项目类型配置
Frontend App (Vue/React)
前端应用(Vue/React)
Required hooks for frontend applications:
yaml
default_install_hook_types:
- pre-commit
- commit-msg
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
exclude: ^(helm/templates/|skaffold/|k8s/).*\.ya?ml$
- id: check-json
exclude: tsconfig\.json$
- id: check-added-large-files
args: ['--maxkb=1000']
- id: check-merge-conflict
- id: detect-private-key
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.3.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
- repo: https://github.com/biomejs/pre-commit
rev: v0.4.0
hooks:
- id: biome-check
additional_dependencies: ["@biomejs/biome@1.9.4"]
# Optional: If project has Helm charts
- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.29
hooks:
- id: helmlint
files: ^helm/前端应用所需的必填钩子:
yaml
default_install_hook_types:
- pre-commit
- commit-msg
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
exclude: ^(helm/templates/|skaffold/|k8s/).*\.ya?ml$
- id: check-json
exclude: tsconfig\.json$
- id: check-added-large-files
args: ['--maxkb=1000']
- id: check-merge-conflict
- id: detect-private-key
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.3.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
- repo: https://github.com/biomejs/pre-commit
rev: v0.4.0
hooks:
- id: biome-check
additional_dependencies: ["@biomejs/biome@1.9.4"]
# 可选:如果项目包含Helm charts
- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.29
hooks:
- id: helmlint
files: ^helm/Infrastructure Repository
基础设施仓库
Required hooks for infrastructure (Terraform, Helm, ArgoCD):
yaml
default_install_hook_types:
- pre-commit
- commit-msg
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
args: [--allow-multiple-documents]
exclude: argocd/.*templates/|helm/[^/]+/templates/
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-added-large-files
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.3.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.29
hooks:
- id: tflint
- id: helmlint
- repo: https://github.com/rhysd/actionlint
rev: v1.7.7
hooks:
- id: actionlint
- repo: https://github.com/norwoodj/helm-docs
rev: v1.14.2
hooks:
- id: helm-docs
args:
- --chart-search-root=helm
- repo: https://github.com/gitleaks/gitleaks
rev: v8.22.1
hooks:
- id: gitleaks基础设施类项目(Terraform、Helm、ArgoCD)所需的必填钩子:
yaml
default_install_hook_types:
- pre-commit
- commit-msg
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
args: [--allow-multiple-documents]
exclude: argocd/.*templates/|helm/[^/]+/templates/
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-added-large-files
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.3.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.29
hooks:
- id: tflint
- id: helmlint
- repo: https://github.com/rhysd/actionlint
rev: v1.7.7
hooks:
- id: actionlint
- repo: https://github.com/norwoodj/helm-docs
rev: v1.14.2
hooks:
- id: helm-docs
args:
- --chart-search-root=helm
- repo: https://github.com/gitleaks/gitleaks
rev: v8.22.1
hooks:
- id: gitleaksPython Service
Python服务
Required hooks for Python projects:
yaml
default_install_hook_types:
- pre-commit
- commit-msg
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-added-large-files
- id: check-merge-conflict
- id: detect-private-key
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.3.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/gitleaks/gitleaks
rev: v8.22.1
hooks:
- id: gitleaksPython项目所需的必填钩子:
yaml
default_install_hook_types:
- pre-commit
- commit-msg
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-added-large-files
- id: check-merge-conflict
- id: detect-private-key
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.3.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/gitleaks/gitleaks
rev: v8.22.1
hooks:
- id: gitleaksCompliance Checking
合规性检查
Required Base Hooks (All Projects)
基础必填钩子(所有项目)
Every repository MUST have these hooks:
-
pre-commit-hooks (v5.0.0+)
trailing-whitespaceend-of-file-fixercheck-yamlcheck-jsoncheck-merge-conflictcheck-added-large-files
-
conventional-pre-commit (v4.3.0+)
- in
conventional-pre-commitstagecommit-msg
每个仓库必须包含以下钩子:
-
pre-commit-hooks(v5.0.0及以上版本)
trailing-whitespaceend-of-file-fixercheck-yamlcheck-jsoncheck-merge-conflictcheck-added-large-files
-
conventional-pre-commit(v4.3.0及以上版本)
- 运行在阶段的
commit-msg钩子conventional-pre-commit
- 运行在
Status Levels
状态等级
| Status | Meaning |
|---|---|
| PASS | Hook present with compliant version |
| WARN | Hook present but version outdated |
| FAIL | Required hook missing |
| SKIP | Hook not applicable for project type |
| 状态 | 含义 |
|---|---|
| PASS | 钩子已存在且版本符合要求 |
| WARN | 钩子已存在但版本过时 |
| FAIL | 缺少必填钩子 |
| SKIP | 钩子不适用于当前项目类型 |
Version Comparison
版本比较规则
When checking versions:
- Exact match or newer: PASS
- Older by patch version: WARN (functional but should update)
- Missing entirely: FAIL (must add)
检查版本时:
- 完全匹配或版本更新:PASS
- 补丁版本号更低:WARN(功能可用但建议更新)
- 完全缺失:FAIL(必须添加)
Exclusion Patterns
排除规则
Frontend Apps
前端应用
Exclude Kubernetes/Helm templates from YAML/prettier checks:
yaml
exclude: ^(helm/templates/|skaffold/|k8s/).*\.ya?ml$YAML/prettier检查需要排除Kubernetes/Helm模板文件:
yaml
exclude: ^(helm/templates/|skaffold/|k8s/).*\.ya?ml$Infrastructure
基础设施类项目
Exclude ArgoCD and Helm templates:
yaml
exclude: argocd/.*templates/|helm/[^/]+/templates/排除ArgoCD和Helm模板文件:
yaml
exclude: argocd/.*templates/|helm/[^/]+/templates/Python
Python
No special exclusions needed for standard Python projects.
标准Python项目无需特殊排除规则。
Installation
安装
After configuring :
.pre-commit-config.yamlbash
pre-commit install
pre-commit install --hook-type commit-msgOr simply:
bash
pre-commit install --install-hooks配置好后执行:
.pre-commit-config.yamlbash
pre-commit install
pre-commit install --hook-type commit-msg或者直接执行:
bash
pre-commit install --install-hooksUpdating
更新
To update all hooks to latest versions:
bash
pre-commit autoupdateThen verify versions match project standards.
将所有钩子更新到最新版本:
bash
pre-commit autoupdate然后验证版本是否符合项目标准。