Skip to content

Latest commit

 

History

History
110 lines (75 loc) · 2.48 KB

File metadata and controls

110 lines (75 loc) · 2.48 KB

Pre-commit Hooks Setup

This repository uses pre-commit hooks to ensure code quality and consistency. The hooks run automatically before each commit to catch issues early.

Installation

Option 1: Using Just (Recommended)

just setup-precommit

Option 2: Manual Installation

# Install pre-commit using uv
uv tool install pre-commit

# Install the git hooks
pre-commit install

Option 3: Using npm

# Install dependencies
npm install

# Setup hooks (runs automatically via package.json prepare script)
npm run prepare

What the hooks do

The pre-commit configuration includes the following checks:

File Quality Checks

  • Trailing whitespace: Removes trailing whitespace (except in .md files)
  • End of file fixer: Ensures files end with a newline
  • Large files: Prevents committing files larger than 1MB
  • Private keys: Detects accidentally committed private keys
  • Merge conflicts: Checks for unresolved merge conflict markers

Code Formatting

  • Prettier: Formats JavaScript, CSS, JSON, YAML, and Markdown files
  • Markdown linting: Ensures consistent markdown formatting
  • YAML linting: Validates YAML syntax and style

Security

  • Secret detection: Scans for accidentally committed secrets and credentials

Hugo-specific Checks

  • Hugo build check: Ensures the site builds successfully
  • Tailwind CSS check: Validates Tailwind CSS compilation
  • TODO/FIXME detection: Warns about uncommitted TODO/FIXME comments

Content Quality

  • Spell checking: Uses typos to catch spelling errors in content

Running hooks manually

# Run all hooks on all files
just check
# or
pre-commit run --all-files

# Run hooks on staged files only
pre-commit run

# Run a specific hook
pre-commit run prettier
pre-commit run markdownlint

Updating hooks

# Update hook versions to latest
just update-hooks
# or
pre-commit autoupdate

Configuration Files

  • .pre-commit-config.yaml - Main pre-commit configuration
  • .prettierrc - Prettier formatting rules
  • .markdownlint.json - Markdown linting rules
  • .yamllint - YAML linting rules
  • _typos.toml - Spell checker configuration

Skipping hooks (emergency use only)

If you need to skip hooks in an emergency:

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

# Skip specific hooks
SKIP=hugo-build-check git commit -m "Skip build check"

Note: Use --no-verify sparingly and fix issues in follow-up commits.