Pre-commit Setup

•
91
•

Automates the configuration and installation of Git pre-commit hooks for multi-language code quality enforcement.

The precommit-setup skill streamlines the process of implementing Git hooks to ensure code quality before every commit. It provides standardized configurations for Python (Ruff, Mypy), Rust (Clippy, Rustfmt), and TypeScript (ESLint, Prettier), helping developers catch errors early. By automating the creation of .pre-commit-config.yaml and integrating with CI/CD pipelines, this skill ensures consistent linting, formatting, and security standards across the entire development team.

주요 기능

01Seamless integration with the uv package manager and environment
02Standardized .pre-commit-config.yaml template generation
03Pre-configured security scanning and compilation check hooks
04GitHub Actions CI/CD integration templates for automated verification
0591 GitHub stars
06Automated multi-language hook configuration for Python, Rust, and TypeScript

사용 사례

01Setting up automated code quality gates for a new software repository
02Ensuring consistent commit standards across polyglot development teams
03Retrofitting an existing codebase with standardized linting and formatting
name description model tools
precommit-setup
Configure pre-commit hooks for code formatting, linting, and security checks
claude-sonnet-4
Read
Write
Bash

Pre-commit Setup Skill

Configure pre-commit hooks to enforce code quality before commits.

Use When

  • Setting up new project with code quality enforcement
  • Adding pre-commit hooks to existing project
  • Updating pre-commit hook versions

Standard Hooks

Python Hooks

  1. pre-commit-hooks - Basic checks (trailing whitespace, EOF, YAML syntax)
  2. ruff - Fast linting and formatting
  3. mypy - Type checking
  4. bandit - Security scanning (optional)

Rust Hooks

  1. rustfmt - Code formatting
  2. clippy - Linting
  3. cargo-check - Compilation check

TypeScript Hooks

  1. eslint - Linting
  2. prettier - Code formatting
  3. tsc - Type checking

Workflow

1. Create Configuration

# Render .pre-commit-config.yaml from template
python3 plugins/attune/scripts/attune_init.py \
  --lang python \
  --name my-project \
  --path .

This creates .pre-commit-config.yaml:

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

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

2. Install Hooks

# Install pre-commit tool
uv sync --extra dev

# Install git hooks
uv run pre-commit install

# Output:
# pre-commit installed at .git/hooks/pre-commit

3. Test Hooks

# Run on all files
uv run pre-commit run --all-files

# Test on staged files
git add .
uv run pre-commit run

4. Update Hook Versions

# Update to latest versions
uv run pre-commit autoupdate

# Example output:
# Updating https://github.com/astral-sh/ruff-pre-commit ... updating v0.14.0 -> v0.14.2

Hook Configuration

Skip Specific Hooks

# Skip specific hook for one commit
SKIP=mypy git commit -m "Work in progress"

# Skip all hooks for one commit
git commit --no-verify -m "Emergency fix"

Custom Hooks

Add project-specific hooks in .pre-commit-config.yaml:

  - repo: local
    hooks:
      - id: pytest-check
        name: pytest-check
        entry: uv run pytest --collect-only -q
        language: system
        pass_filenames: false
        always_run: true

CI Integration

Ensure CI runs the same checks:

# .github/workflows/pre-commit.yml
name: Pre-commit

on: [push, pull_request]

jobs:
  pre-commit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
      - name: Run pre-commit
        run: |
          pip install pre-commit
          pre-commit run --all-files

Troubleshooting

Hooks Too Slow

# Run only on changed files (default)
# vs
# Run on all files (slower)
uv run pre-commit run --all-files

Cache Issues

# Clear pre-commit cache
uv run pre-commit clean

Hook Failures

# See detailed output
uv run pre-commit run --verbose --all-files

Related Skills

  • Skill(attune:project-init) - Full project initialization
  • Skill(attune:workflow-setup) - GitHub Actions setup