Skip to content

A CLI tool that automatically generates `.pre-commit-config.yaml` files based on detected project types.

Notifications You must be signed in to change notification settings

blackopsrepl/init-pre-commit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

init-pre-commit

A CLI tool that automatically generates .pre-commit-config.yaml files based on detected project types.

Features

  • Detects project languages (Python, Go, Rust) from file patterns
  • Generates a pre-commit config with appropriate hooks for each language
  • Includes common hooks by default (yaml check, trailing whitespace, gitleaks, etc.)
  • Optionally installs pre-commit hooks automatically

Installation

cargo install --path .

Usage

# Initialize in current directory
init-pre-commit

# Initialize in a specific directory
init-pre-commit /path/to/repo

The tool will:

  1. Verify the target is a git repository
  2. Detect project types based on file patterns
  3. Generate .pre-commit-config.yaml with appropriate hooks
  4. Install pre-commit hooks (if pre-commit is available)

Default Hooks

All generated configs include:

  • check-yaml - Validate YAML syntax
  • end-of-file-fixer - Ensure files end with newline
  • trailing-whitespace - Remove trailing whitespace
  • check-merge-conflict - Detect merge conflict markers
  • check-added-large-files - Prevent large files from being committed
  • gitleaks - Scan for secrets

Language-Specific Hooks

Python

  • black - Code formatter
  • ruff - Fast linter with auto-fix

Go

  • go-fmt - Format Go code
  • go-vet - Report suspicious constructs
  • go-imports - Manage imports

Rust

  • fmt - Format Rust code
  • clippy - Lint Rust code

Adding New Languages

Edit rules.yaml to add detection patterns and hooks for new languages:

- name: javascript
  detect_patterns:
    - "**/*.js"
    - "**/package.json"
  message: Detected JavaScript project
  hooks: |
    -   repo: https://github.com/pre-commit/mirrors-eslint
        rev: v8.56.0
        hooks:
        -   id: eslint

License

MIT

About

A CLI tool that automatically generates `.pre-commit-config.yaml` files based on detected project types.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published