← 返回
未分类 中文

Phy Pre Commit Gen

Generates a tailored .pre-commit-config.yaml by analyzing your project's language stack, existing linting tools, and CI setup. Detects Python/JS/TS/Go/Rust/T...
通过分析项目的语言栈、已有的 lint 工具和 CI 配置,自动生成定制化的 .pre-commit-config.yaml,支持 Python/JS/TS/Go/Rust 等语言。
phy041 phy041 来源
未分类 clawhub v1.0.3 1 版本 100000 Key: 无需
★ 0
Stars
📥 114
下载
💾 0
安装
1
版本
#latest

概述

phy-pre-commit-gen — Pre-commit Config Generator

Analyzes your project and generates a .pre-commit-config.yaml with the right hooks for your specific stack. No generic templates — actual configuration based on what your project uses.

Quick Start

# Generate config for the current directory
python3 ~/.claude/skills/phy-pre-commit-gen/scripts/pre_commit_gen.py .

# Preview without writing
python3 ~/.claude/skills/phy-pre-commit-gen/scripts/pre_commit_gen.py . --dry-run

# Audit an existing .pre-commit-config.yaml
python3 ~/.claude/skills/phy-pre-commit-gen/scripts/pre_commit_gen.py . --audit

# Overwrite an existing config
python3 ~/.claude/skills/phy-pre-commit-gen/scripts/pre_commit_gen.py . --overwrite

# Write to a specific path
python3 ~/.claude/skills/phy-pre-commit-gen/scripts/pre_commit_gen.py . --output .pre-commit-config.yaml

Then activate:

pip install pre-commit
pre-commit install          # activate for this repo
pre-commit autoupdate       # update all hook revs to latest
pre-commit run --all-files  # run on existing code

What It Detects

DetectionSignal Files
------------------------
Python*.py, pyproject.toml, requirements.txt, setup.py
JavaScript/TypeScriptpackage.json, TypeScript in deps
Gogo.mod
RustCargo.toml
Terraform*.tf files
DockerDockerfile, .dockerfile
Shell.sh, .bash
SQL*.sql, migrations/ directory
YAML/CI.github/workflows/, .gitlab-ci.yml
Ruffruff.toml, .ruff.toml, [tool.ruff] in pyproject.toml
Black[tool.black] in pyproject.toml
ESLinteslint in package.json deps
Prettierprettier in package.json deps
Commitizencommitizen or @commitlint/cli in package.json
Existing pre-commitReads existing hooks to avoid duplicates

Hook Selection Logic

Python:

  • Has Ruff config → use ruff + ruff-format (replaces black+isort+flake8)
  • Has Black config → use black + isort (if isort configured) + flake8 (if configured)
  • Neither → add Ruff as recommended default

JS/TypeScript:

  • Has ESLint → use eslint mirror hook
  • Has Prettier → use prettier mirror hook
  • Neither → add Prettier as baseline

Always included:

  • pre-commit-hooks — trailing whitespace, EOF fixer, YAML/JSON/TOML check, large files, merge conflict detection, no-commit-to-branch (main/master)
  • detect-secrets — secret baseline scanning
  • markdownlint-cli — Markdown quality

Conditionally included:

  • Go → go-fmt, go-vet, go-unit-tests
  • Rust → rustfmt (local), clippy (local)
  • Terraform → terraform_fmt, terraform_validate, terraform_tflint
  • Docker → hadolint (Dockerfile security)
  • Shell → shellcheck
  • SQL → sqlfluff
  • YAML CI present → yamllint
  • Commitizen/commitlint detected → commitizen (commit-msg stage)

Audit Mode

Checks an existing .pre-commit-config.yaml for:

  • Unpinned revs (latest, main, HEAD) — can break unexpectedly
  • No secret detection hook (detect-secrets or gitleaks)
  • Missing trailing-whitespace hook
  • Local hooks that may not work cross-platform
python3 ~/.claude/skills/phy-pre-commit-gen/scripts/pre_commit_gen.py . --audit

Output:

📋  Auditing: .pre-commit-config.yaml

  🔴 Unpinned rev 'main' — pre-commit hooks should be pinned to a specific tag
  🟠 No secret detection hook — add detect-secrets or gitleaks
  ✅ trailing-whitespace present

Example Outputs

Python + Ruff project

# Generated by phy-pre-commit-gen
# Run: pre-commit install && pre-commit autoupdate

repos:

  # Universal quality checks
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.6.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-json
      - id: check-toml
      - id: check-merge-conflict
      - id: check-added-large-files
        args: [--maxkb=1000]
      - id: mixed-line-ending
      - id: no-commit-to-branch
        args: [--branch, main, --branch, master]

  # Secret detection
  - repo: https://github.com/Yelp/detect-secrets
    rev: v1.5.0
    hooks:
      - id: detect-secrets
        args: [--baseline, .secrets.baseline]

  # Python — Ruff (linter + formatter)
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.4.7
    hooks:
      - id: ruff
        args: [--fix]
      - id: ruff-format

  # Markdown
  - repo: https://github.com/igorshubovych/markdownlint-cli
    rev: v0.41.0
    hooks:
      - id: markdownlint

Full-stack polyglot (JS + Python + Terraform + Docker)

# Generated by phy-pre-commit-gen

repos:

  # Universal
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.6.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      ... (+ 6 more)

  # Secret detection
  - repo: https://github.com/Yelp/detect-secrets
    rev: v1.5.0
    hooks:
      - id: detect-secrets

  # Python — Ruff
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.4.7
    hooks:
      - id: ruff
        args: [--fix]
      - id: ruff-format

  # JS/TS — ESLint
  - repo: https://github.com/pre-commit/mirrors-eslint
    rev: v9.7.0
    hooks:
      - id: eslint

  # JS/TS — Prettier
  - repo: https://github.com/pre-commit/mirrors-prettier
    rev: v3.3.2
    hooks:
      - id: prettier

  # Terraform
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.92.1
    hooks:
      - id: terraform_fmt
      - id: terraform_validate
      - id: terraform_tflint

  # Dockerfile security
  - repo: https://github.com/hadolint/hadolint
    rev: v2.13.0-beta
    hooks:
      - id: hadolint-docker

  # Shell
  - repo: https://github.com/shellcheck-py/shellcheck-py
    rev: v0.10.0.1
    hooks:
      - id: shellcheck

  # YAML
  - repo: https://github.com/adrienverge/yamllint
    rev: v1.35.1
    hooks:
      - id: yamllint
        args: [-d, relaxed]

  # Markdown
  - repo: https://github.com/igorshubovych/markdownlint-cli
    rev: v0.41.0
    hooks:
      - id: markdownlint

Hook Revisions

All revisions are pinned to stable releases as of early 2026. Always run pre-commit autoupdate after generating to get the latest pinned versions:

pre-commit autoupdate
git add .pre-commit-config.yaml
git commit -m "chore: update pre-commit hook revisions"

Integration with CI

# GitHub Actions — run pre-commit on all files
- uses: pre-commit/action@v3.0.1
  with:
    extra_args: --all-files

# Or manual:
- name: pre-commit
  run: |
    pip install pre-commit
    pre-commit run --all-files

Technical Notes

  • Zero external dependencies — pure Python 3.7+ stdlib
  • Duplicate detection — reads existing .pre-commit-config.yaml to avoid adding already-present hooks
  • Idempotent — running on a project with existing config uses --overwrite flag; safe default is to not overwrite
  • YAML output — valid YAML, human-readable comments, standard pre-commit format

Companion Skills

SkillRelationship
--------------------
phy-dep-upgradeKeeps dependencies up-to-date (pre-commit hooks check quality)
phy-dockerfile-auditHadolint is included as a pre-commit hook when Dockerfiles detected
phy-lock-file-auditorDetects lock file issues (complementary to pre-commit integrity checks)
phy-env-doctorDiscovers .env refs — pairs with detect-secrets hook

Author

Canlah AI — Run performance marketing without breaking your brand.

版本历史

共 1 个版本

  • v1.0.3 当前
    2026-05-29 14:21 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

knowledge-management

Phy Lenny Mentor

phy041
由300+期Lenny播客驱动的AI产品导师。提炼Brian Chesky、Shreyas Doshi、April Dunford等世界级领袖的智慧。T...
★ 1 📥 671
dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 198 📥 68,231
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 686 📥 331,077