Quick Setup with Lefthook

Lefthook is a fast, cross-platform Git hooks manager. Recommended for team projects.

1. Install Lefthook
npm install --save-dev lefthook
2. Download configuration
curl https://nomoji.dev/examples/lefthook.yml -o lefthook.yml
3. Add to package.json
{ "scripts": { "prepare": "lefthook install" } }
4. Install hooks
npm run prepare

Manual Setup (Alternative)

For projects without Node.js or for simple setup:

curl -s https://nomoji.dev/examples/scripts/setup-hooks.sh | bash

This installs hooks directly to .git/hooks/

What Gets Checked

Pre-commit Hook

Runs before each commit:

  • Validates staged files are emoji-free
  • Checks code, documentation, and comments
  • Runs linting and type checking

Commit-msg Hook

Validates commit messages:

  • Checks message for emojis
  • Enforces conventional commit format
  • Ensures professional standards

Usage

Hooks run automatically during normal Git workflow:

git add . git commit -m "feat: add new feature" # Lefthook automatically runs pre-commit hooks git push # Lefthook automatically runs pre-push hooks

Bypassing Hooks

In exceptional circumstances, you can bypass hooks:

# Skip pre-commit and commit-msg hooks git commit --no-verify -m "emergency fix" # Skip pre-push hooks git push --no-verify

Not recommended - only for emergencies

Comparison: Lefthook vs Manual Hooks

Lefthook (Recommended)

Pros:

  • Version controlled via lefthook.yml
  • Automatic installation via npm
  • Cross-platform compatibility
  • Parallel execution
  • Easy to share and update
  • Team-friendly

Cons:

  • Requires npm package
  • Small learning curve

Manual Hooks

Pros:

  • No additional dependencies
  • Direct control
  • Simple for single developer

Cons:

  • Not version controlled
  • Must be installed manually by each developer
  • Hard to update and share
  • Platform-specific scripts

Troubleshooting

Hooks Not Running?

  1. Verify installation:
    npx lefthook version && ls -la .git/hooks/
  2. Reinstall hooks:
    npx lefthook install

API Request Failures?

If emoji check fails due to network issues:

curl https://nomoji.dev/api/health

Performance Issues?

Skip expensive checks in development:

LEFTHOOK_EXCLUDE=type-check git commit

Team Setup

To ensure all team members use the same hooks:

  1. Commit lefthook.yml to version control
  2. Add prepare script to package.json
  3. Document in README:
    ## Development Setup After cloning the repository: ```bash npm install # Automatically installs git hooks ```