--- name: code-quality-check description: Pre-commit quality checklist — linting, formatting, type checking, dead code detection. Language-agnostic gate before git commit or push. license: MIT --- ## What I do Run comprehensive quality checks before committing code. Ensure linting passes, types are correct, formatting is consistent, and tests pass. ## Quality Check Workflow ### Phase 1: Pre-Check Setup ```bash git branch # Ensure on feature branch (not main) git status # Check what files changed git diff --name-only git fetch origin # Get latest from main ``` ### Phase 2: Run Quality Checks #### 1. Format Check ```bash cargo fmt # Rust zig fmt # Zig gofmt -w . # Go clang-format -i . # C/C++ ``` #### 2. Lint Check ```bash cargo clippy # Rust zig fmt --check # Zig clang-tidy . # C/C++ ``` #### 3. Type Check ```bash cargo check # Rust zig build # Zig go build ./... # Go javac File.java # Java gcc -Wall -Wextra -Werror file.c # C ``` #### 4. Security Check ```bash cargo audit # Rust dependency audit go vet ./... # Go gitleaks detect --source . # Secrets check ``` ### Phase 3: Run Tests ```bash cargo test # Rust zig build test # Zig go test ./... # Go ``` ### Phase 4: Pre-Commit Hooks ```bash lefthook run pre-commit # If configured ``` --- ## Checklist - [ ] `git status` shows only intended changes - [ ] Format check passes - [ ] Lint check passes - [ ] Type check passes - [ ] Tests pass - [ ] No debug code left (print statements, logging) - [ ] No commented-out code - [ ] No TODO/FIXME without issue number --- ## Preventing Bugs ### The Mindset - **Bugs are choices**: We write them, we can choose not to - **Re-read frequently**: After writing 3-6 lines, re-read them - **The brain fills gaps**: Your brain knows what it meant to write ### Practical Techniques - Pretend it's someone else's code: Removes familiarity bias --- ## TigerStyle (TigerBeetle Philosophy) Safety, performance, developer experience—in that order. ### Safety Rules - **No recursion**: Ensure bounded executions - **Put limits on everything**: Prevent infinite loops, fail-fast - **Use explicitly-sized types**: `u32` not `usize` - **Static memory only**: No malloc/free after init - **Minimal scope**: Declare variables at smallest possible scope - **70 lines max per function**: Easier to reason about - **Handle all errors**: 92% of catastrophic failures from mishandled errors ### Assertions - **2 assertions per function minimum** - **Pair assertions**: assert before AND after I/O - Split compound assertions: `assert(a); assert(b);` over `assert(a && b)` ### Performance - Think about performance **upfront**, not after profiling - Back-of-envelope sketches with 4 resources (network, disk, memory, CPU) - Optimize slowest resources first ### Developer Experience **Naming**: - Use `snake_case` for functions, variables, files - **No abbreviations** unless primitive integer in sort/matrix code - Put units/qualifiers **last**: `latency_ms_max`, not `max_latency_ms` - Callbacks go **last** in parameter list **Code Organization**: - **100 columns max** - 4 spaces indentation - Top-down order: main first **Comments**: - **Always say why** — code alone is not documentation --- ## Code Design Traps - Mirroring reality: Categories are in our heads, not the world - Forcing hierarchies: Patterns aren't always tree-shaped - Over-generalizing: Don't replace problem with harder one --- Run these checks before every commit for consistently high-quality code.