A CLI tool that automatically generates .pre-commit-config.yaml files based on detected project types.
- 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
cargo install --path .# Initialize in current directory
init-pre-commit
# Initialize in a specific directory
init-pre-commit /path/to/repoThe tool will:
- Verify the target is a git repository
- Detect project types based on file patterns
- Generate
.pre-commit-config.yamlwith appropriate hooks - Install pre-commit hooks (if pre-commit is available)
All generated configs include:
check-yaml- Validate YAML syntaxend-of-file-fixer- Ensure files end with newlinetrailing-whitespace- Remove trailing whitespacecheck-merge-conflict- Detect merge conflict markerscheck-added-large-files- Prevent large files from being committedgitleaks- Scan for secrets
black- Code formatterruff- Fast linter with auto-fix
go-fmt- Format Go codego-vet- Report suspicious constructsgo-imports- Manage imports
fmt- Format Rust codeclippy- Lint Rust code
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: eslintMIT