ln-742-precommit-setup
L3 Worker - Configures Git hooks for code quality enforcement
Main Workflow
stateDiagram-v2
[*] --> CheckExisting: Start Hook Setup
state CheckExisting {
[*] --> ScanHooks
ScanHooks --> Evaluate
Evaluate --> [*]
}
CheckExisting --> Decision: Hooks Evaluated
state Decision {
[*] --> NoHooks
[*] --> PartialHooks
[*] --> CompleteHooks
NoHooks --> Install: Create new
PartialHooks --> AskUser: Complete or replace?
CompleteHooks --> Skip: Inform user
}
Decision --> InstallManager: Action Determined
state InstallManager {
[*] --> DetectStack
DetectStack --> Husky: Node.js
DetectStack --> PreCommit: Python
Husky --> [*]
PreCommit --> [*]
}
InstallManager --> ConfigureLinting: Manager Installed
ConfigureLinting --> ConfigureCommitMsg: Linting Configured
ConfigureCommitMsg --> TestHooks: Validation Configured
TestHooks --> [*]: Hooks Working
Git Commit Flow with Hooks
sequenceDiagram
participant Dev as Developer
participant Git as Git
participant PreCommit as pre-commit hook
participant LintStaged as lint-staged
participant CommitMsg as commit-msg hook
participant Commitlint as commitlint
Dev->>Git: git commit -m "feat: add feature"
Git->>PreCommit: Trigger pre-commit
rect rgb(230, 245, 255)
Note over PreCommit,LintStaged: Stage 1: Code Quality
PreCommit->>LintStaged: Run on staged files
LintStaged->>LintStaged: eslint --fix
LintStaged->>LintStaged: prettier --write
LintStaged-->>PreCommit: Files fixed & re-staged
end
PreCommit-->>Git: Pre-commit passed
Git->>CommitMsg: Trigger commit-msg
rect rgb(255, 245, 230)
Note over CommitMsg,Commitlint: Stage 2: Message Validation
CommitMsg->>Commitlint: Validate message
Commitlint->>Commitlint: Check conventional format
Commitlint-->>CommitMsg: Valid format
end
CommitMsg-->>Git: Commit-msg passed
Git-->>Dev: Commit successful
Hook Manager Selection
flowchart TD
Start([Detect Project Type]) --> Check{package.json?}
Check -->|Yes| NodeJS[Node.js Project]
Check -->|No| CheckPython{pyproject.toml?}
CheckPython -->|Yes| Python[Python Project]
CheckPython -->|No| Mixed[Mixed/Other]
NodeJS --> Husky[Install Husky]
Python --> PreCommit[Install pre-commit]
Mixed --> Both[Install Both]
subgraph Husky[Husky Stack]
H1[npm install husky]
H2[npx husky init]
H3[lint-staged config]
H4[commitlint config]
end
subgraph PreCommit[pre-commit Stack]
P1[pip install pre-commit]
P2[pre-commit install]
P3[.pre-commit-config.yaml]
P4[ruff hooks]
end
Husky --> Done([Hooks Configured])
PreCommit --> Done
Both --> Done
classDef nodejs fill:#68A063,color:white
classDef python fill:#3776AB,color:white
class NodeJS,H1,H2,H3,H4 nodejs
class Python,P1,P2,P3,P4 python
Commit Message Validation
flowchart LR
Input([Commit Message]) --> Parse{Parse Header}
Parse --> Type[type]
Parse --> Scope[scope - optional]
Parse --> Subject[subject]
Type --> ValidType{Valid type?}
ValidType -->|Yes| CheckCase{Lowercase?}
ValidType -->|No| Reject([REJECT])
CheckCase -->|Yes| CheckLength{Length ≤ 100?}
CheckCase -->|No| Reject
CheckLength -->|Yes| Accept([ACCEPT])
CheckLength -->|No| Reject
subgraph Types[Allowed Types]
feat[feat]
fix[fix]
docs[docs]
style[style]
refactor[refactor]
test[test]
chore[chore]
ci[ci]
end
ValidType -.-> Types
classDef pass fill:#90EE90
classDef fail fill:#FFB6C1
class Accept pass
class Reject fail
Emergency Bypass
flowchart TD
Commit([git commit]) --> Hooks{Hooks Run?}
Hooks -->|Normal| RunHooks[Execute Hooks]
RunHooks -->|Pass| Success([Commit Created])
RunHooks -->|Fail| Fix[Fix Issues]
Fix --> Commit
Hooks -->|--no-verify| Bypass[Skip ALL Hooks]
Bypass --> Warning([Commit Created
⚠️ No validation])
Hooks -->|HUSKY=0| Partial[Skip Husky Only]
Partial --> GitHooks[Git hooks still run]
GitHooks --> Success
classDef warning fill:#FFD700
class Warning,Bypass warning