mcpField
P
pre-commit-standards

pre-commit-standards

github.com/laurigates测试与质量5968 次安装1 天前更新
代码仓库

关于 pre-commit-standards

提供仓库 pre-commit 合规检查所需的标准钩子、版本和约定,适合审核现有配置或为其他技能引用规则;不负责交互式安装或修复。

主要功能

  1. 01列出标准钩子及固定版本
  2. 02定义不同项目类型的配置
  3. 03检查必需钩子及版本状态
  4. 04提供项目类型对应的排除规则
  5. 05说明安装与更新命令

适用场景

  1. 01核对 .pre-commit-config.yaml
  2. 02检查钩子是否缺失或过期
  3. 03为其他技能引用规范版本
  4. 04按项目类型配置排除项

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/laurigates/claude-plugins --skill pre-commit-standards

安装后在 Claude Code 中输入/pre-commit-standards确认已加载。

详细介绍

Pre-commit 标准

何时使用此技能

在以下情况下使用此技能……在以下情况下改用 configure-pre-commit……
需要权威的钩子列表、固定版本和 Conventional Commits 约定想通过交互式工作流,端到端地审查或安装项目的 pre-commit 钩子
正在检查 .pre-commit-config.yaml 是否符合文档中的标准希望在选择钩子集之前,动态检测项目类型(前端、基础设施、Python)
其他技能需要引用标准钩子版本或规则集用户要求实际创建或修复 pre-commit 配置

版本:2025.1

用于确保仓库符合规范的标准 pre-commit 配置。

标准版本(2025.1)

钩子版本用途
pre-commit-hooksv6.0.0核心钩子(trailing-whitespace、check-yaml 等)
conventional-pre-commitv4.4.0Conventional Commits 提交消息校验
biomev2.4.16代码格式化和 lint(JS、TS、JSON)
gruntwork pre-commitv0.1.30helmlint、tflint(仅限基础设施)
actionlintv1.7.12GitHub Actions 校验(仅限基础设施)
helm-docsv1.14.2Helm 文档(仅限基础设施)
gitleaksv8.30.1密钥扫描(推荐)

项目类型配置

前端应用(Vue/React)

前端应用必需的钩子:

default_install_hook_types:
  - pre-commit
  - commit-msg

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v6.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.4.0
    hooks:
      - id: conventional-pre-commit
        stages: [commit-msg]

  - repo: https://github.com/biomejs/pre-commit
    rev: v2.4.16
    hooks:
      - id: biome-check
        additional_dependencies: ["@biomejs/[email protected]"]

  # Optional: If project has Helm charts
  - repo: https://github.com/gruntwork-io/pre-commit
    rev: v0.1.30
    hooks:
      - id: helmlint
        files: ^helm/
基础设施仓库

基础设施(Terraform、Helm、ArgoCD)必需的钩子:

default_install_hook_types:
  - pre-commit
  - commit-msg

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v6.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.4.0
    hooks:
      - id: conventional-pre-commit
        stages: [commit-msg]

  - repo: https://github.com/gruntwork-io/pre-commit
    rev: v0.1.30
    hooks:
      - id: tflint
      - id: helmlint

  - repo: https://github.com/rhysd/actionlint
    rev: v1.7.12
    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.30.1
    hooks:
      - id: gitleaks
Python 服务

Python 项目必需的钩子:

default_install_hook_types:
  - pre-commit
  - commit-msg

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v6.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.4.0
    hooks:
      - id: conventional-pre-commit
        stages: [commit-msg]

  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.15.15
    hooks:
      - id: ruff
        args: [--fix]
      - id: ruff-format

  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.30.1
    hooks:
      - id: gitleaks

合规性检查

必需的基础钩子(所有项目)

每个仓库都必须包含以下钩子:

  1. pre-commit-hooks(v6.0.0+)

    • trailing-whitespace
    • end-of-file-fixer
    • check-yaml
    • check-json
    • check-merge-conflict
    • check-added-large-files
  2. conventional-pre-commit(v4.4.0+)

    • 在 commit-msg 阶段使用 conventional-pre-commit
状态级别
状态含义
PASS钩子存在且版本符合要求
WARN钩子存在,但版本过旧
FAIL缺少必需的钩子
SKIP此钩子不适用于该项目类型
版本比较

检查版本时:

  • 版本完全匹配或更新:PASS
  • 仅补丁版本较旧:WARN(功能正常,但应更新)
  • 完全缺失:FAIL(必须添加)

排除模式

前端应用

从 YAML/prettier 检查中排除 Kubernetes/Helm 模板:

exclude: ^(helm/templates/|skaffold/|k8s/).*\.ya?ml$
基础设施

排除 ArgoCD 和 Helm 模板:

exclude: argocd/.*templates/|helm/[^/]+/templates/
Python

标准 Python 项目无需特殊排除项。

安装

配置 .pre-commit-config.yaml 后:

pre-commit install
pre-commit install --hook-type commit-msg

或者直接运行:

pre-commit install --install-hooks

更新

将所有钩子更新到最新版本:

pre-commit autoupdate

然后验证版本是否符合项目标准。

评论

支持 Markdown