Git Hooks for Automated Code Quality
Git hooks run scripts automatically before or after Git events. Set up pre-commit hooks for linting, formatting, and testing to catch issues before they reach your repository.
Hash Generator
Generate SHA-1, SHA-256, SHA-384, SHA-512 hashes from text
Why Git Hooks?
Git hooks provide automatic quality gates in your development workflow. A pre-commit hook can run linters, formatters, and type checkers on staged files, catching issues before they're committed. A pre-push hook can run the full test suite before code leaves your machine.
Essential Pre-Commit Hooks
Lint staged files (not the entire project) for speed. Format code automatically — if the formatter changes a file, stage the changes and allow the commit. Check for debug statements, TODO comments, and hardcoded secrets. Validate file sizes to prevent accidental binary commits. Run type checking on changed files.
Setting Up with pre-commit Framework
The pre-commit framework (pre-commit.com) manages hook installation and execution. Define hooks in .pre-commit-config.yaml, and the framework handles virtual environments, caching, and updates. Hooks run only on staged files, keeping execution fast even in large repositories.
Commit Message Hooks
The commit-msg hook validates commit message format. Enforce conventional commit prefixes (feat:, fix:, docs:), minimum length, and ticket reference patterns. This enables automatic changelog generation and semantic versioning.
Team Adoption
Install hooks automatically when developers clone the repository. Add a setup script that runs pre-commit install or configure your package manager to include this step. Document which hooks are active and how to bypass them in emergencies (git commit --no-verify for rare exceptions).
Performance Considerations
Keep pre-commit hooks under 5 seconds for developer experience. Run expensive checks (full test suite, integration tests) in pre-push hooks or CI/CD instead. Cache results where possible — don't re-lint unchanged files.
関連ツール
関連フォーマット
関連ガイド
JSON vs YAML vs TOML: Choosing a Configuration Format
Configuration files are the backbone of modern applications. JSON, YAML, and TOML each offer different trade-offs between readability, complexity, and tooling support that affect your development workflow.
How to Format and Validate JSON Data
Malformed JSON causes silent failures in APIs and configuration files. Learn how to format, validate, and debug JSON documents to prevent integration errors and improve readability.
Base64 Encoding: How It Works and When to Use It
Base64 converts binary data into ASCII text, making it safe for transmission through text-based systems. Learn when Base64 is the right choice and when alternatives like hex encoding or URL encoding are more appropriate.
Best Practices for Working with Unix Timestamps
Unix timestamps provide a language-agnostic way to represent points in time, but they come with pitfalls around time zones, precision, and the 2038 problem. This guide covers best practices for storing and converting timestamps.
Troubleshooting JWT Token Issues
JSON Web Tokens are widely used for authentication but can be frustrating to debug. This guide covers common JWT problems including expiration errors, signature mismatches, and payload decoding issues.