AgentSkillsCN

precommit-check

在提交 Git 代码前,先用 Prettier 格式化改动文件,随后运行类型检查与构建流程。适用于在基于 Git 的 JS/TS 仓库中,借助 npm 脚本准备提交时使用。

SKILL.md
--- frontmatter
name: precommit-check
description: "Run pre-commit checks by formatting changed files with Prettier, then running typecheck and build. Use when preparing to commit in git-based JS/TS repos with npm scripts."

Precommit Check

Overview

Format changed files, then run typecheck and build. Treat warnings as non-blocking unless a command exits nonzero.

Workflow

  1. Confirm you are in the repo root and git is available.

  2. Format changed files with Prettier:

    bash
    affected=$(git diff --name-only --diff-filter=ACM)
    if [ -n "$affected" ]; then
      git diff --name-only --diff-filter=ACM -z | xargs -0 npx prettier --write --ignore-unknown --log-level warn --
    fi
    
  3. Run typecheck: npm run typecheck.

  4. Run build: npm run build.

  5. Report results:

    • Fail on any nonzero exit code.
    • Ignore warnings that do not affect logic, but mention them if they appear in output.