pre-commit-standards

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Pre-commit Standards

Pre-commit 标准

Version: 2025.1

版本:2025.1

Standard pre-commit configuration for repository compliance.
用于仓库合规的标准pre-commit配置。

Standard Versions (2025.1)

标准版本(2025.1)

HookVersionPurpose
pre-commit-hooksv5.0.0Core hooks (trailing-whitespace, check-yaml, etc.)
conventional-pre-commitv4.3.0Conventional commit message validation
biomev0.4.0Code formatting and linting (JS, TS, JSON)
gruntwork pre-commitv0.1.29helmlint, tflint (infrastructure only)
actionlintv1.7.7GitHub Actions validation (infrastructure only)
helm-docsv1.14.2Helm documentation (infrastructure only)
gitleaksv8.22.1Secret scanning (recommended)
钩子版本用途
pre-commit-hooksv5.0.0核心钩子(移除尾随空格、检查YAML格式等)
conventional-pre-commitv4.3.0约定式提交信息校验
biomev0.4.0代码格式化与lint检查(JS、TS、JSON)
gruntwork pre-commitv0.1.29helmlint、tflint(仅基础设施类项目)
actionlintv1.7.7GitHub Actions配置校验(仅基础设施类项目)
helm-docsv1.14.2Helm文档生成(仅基础设施类项目)
gitleaksv8.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: gitleaks

Python 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: gitleaks
Python项目所需的必填钩子:
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: gitleaks

Compliance Checking

合规性检查

Required Base Hooks (All Projects)

基础必填钩子(所有项目)

Every repository MUST have these hooks:
  1. pre-commit-hooks (v5.0.0+)
    • trailing-whitespace
    • end-of-file-fixer
    • check-yaml
    • check-json
    • check-merge-conflict
    • check-added-large-files
  2. conventional-pre-commit (v4.3.0+)
    • conventional-pre-commit
      in
      commit-msg
      stage
每个仓库必须包含以下钩子:
  1. pre-commit-hooks(v5.0.0及以上版本)
    • trailing-whitespace
    • end-of-file-fixer
    • check-yaml
    • check-json
    • check-merge-conflict
    • check-added-large-files
  2. conventional-pre-commit(v4.3.0及以上版本)
    • 运行在
      commit-msg
      阶段的
      conventional-pre-commit
      钩子

Status Levels

状态等级

StatusMeaning
PASSHook present with compliant version
WARNHook present but version outdated
FAILRequired hook missing
SKIPHook 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.yaml
:
bash
pre-commit install
pre-commit install --hook-type commit-msg
Or simply:
bash
pre-commit install --install-hooks
配置好
.pre-commit-config.yaml
后执行:
bash
pre-commit install
pre-commit install --hook-type commit-msg
或者直接执行:
bash
pre-commit install --install-hooks

Updating

更新

To update all hooks to latest versions:
bash
pre-commit autoupdate
Then verify versions match project standards.
将所有钩子更新到最新版本:
bash
pre-commit autoupdate
然后验证版本是否符合项目标准。