Files
open-claw-team/.openclaw/workspace/skills/code-quality-gate/SKILL.md
T

87 lines
2.3 KiB
Markdown

---
name: code-quality-gate
description: Pre-commit and pre-merge code quality enforcement — lint, type-check, test, security scan, coverage threshold. Use when setting up CI gates, pre-commit hooks, or quality checks.
---
# Code Quality Gate
Combines patterns from ECC plankton-code-quality + AGENTS.md review standards.
## Gate Structure
### Level 1: Pre-Commit (Fast)
- Lint (ESLint, ruff, golangci-lint)
- Format check (Prettier, black, gofmt)
- Type check (tsc, mypy)
- No console.log / print statements
### Level 2: Pre-Test (Medium)
- Unit tests
- Static analysis / code quality scan
- Dependency security audit
- Build succeeds
### Level 3: Pre-Merge (Comprehensive)
- All tests pass (unit + integration + E2E)
- Code coverage meets threshold (> 80%)
- Security scan passes (no Critical/High CVEs)
- 3-tier review completed (self → peer → leader)
- No merge conflicts
- Documentation updated
## Implementation
### Pre-commit Hook (using pre-commit framework)
```yaml
# .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/mirrors-eslint
hooks: [id: eslint]
- repo: https://github.com/charliermarsh/ruff-pre-commit
hooks: [id: ruff]
- repo: https://github.com/golangci/golangci-lint
hooks: [id: golangci-lint]
```
### CI Gate Script
```bash
#!/bin/bash
set -e
echo "=== Quality Gate ==="
echo "1. Lint..."
npm run lint || { echo "FAIL: Lint"; exit 1; }
echo "2. Type check..."
npm run typecheck || { echo "FAIL: Type check"; exit 1; }
echo "3. Unit tests..."
npm test -- --coverage --coverageThreshold='{"global":{"lines":80}}' || { echo "FAIL: Tests"; exit 1; }
echo "4. Security audit..."
npm audit --audit-level=high || { echo "WARN: Security audit"; }
echo "5. Build..."
npm run build || { echo "FAIL: Build"; exit 1; }
echo "=== All gates passed ==="
```
## Quality Metrics to Track
| Metric | Target | Fail if |
|--------|--------|---------|
| Test coverage (lines) | > 80% | < 70% |
| Test coverage (branches) | > 70% | < 50% |
| Critical paths coverage | 100% | Any missing |
| Lint errors | 0 | > 0 |
| Type errors | 0 | > 0 |
| Security vulns (Critical/High) | 0 | > 0 |
| Build time | < 5 min | > 10 min |
## Review Integration
Quality gate must pass BEFORE review can start.
- Self-review: Gate passes + manual checklist
- Peer review: Self-review confirmed + peer reads diff
- Leader review: Both reviews pass + leader approves