🔎 ln-341-code-quality-checker Workflow

Linear Workflow - Worker v1.0.0

Overview

Purpose: Analyze code quality of Done implementation tasks for DRY/KISS/YAGNI/Architecture violations and guide compliance.

Type: Linear Workflow (5 sequential phases)

Single Responsibility: ONLY analyzes code quality and reports issues - does NOT create tasks or change statuses.

Fail Fast: Phase 4 Step 1 in ln-330-story-executor - checks quality BEFORE testing to catch refactoring needs early.

graph TD Start([START]) --> Phase1[Phase 1: Discovery
Load Story
Discover guides
Extract guide links] Phase1 --> Phase2[Phase 2: Load Done Tasks
Query implementation tasks
Filter out test tasks
Identify affected files] Phase2 --> Phase3[Phase 3: Analyze Changes
Extract git diffs
Read file contents
Parse AST] Phase3 --> Phase4[Phase 4: Check Violations
Check 1: DRY duplicates
Check 2: KISS complexity
Check 3: YAGNI unused
Check 4: Architecture layers
Check 5: Guide compliance] Phase4 --> Phase5[Phase 5: Report Results
Categorize by severity
Linear comment
Return JSON verdict] Phase5 --> End([END:
JSON verdict + issues]) classDef phase fill:#E3F2FD,stroke:#1976D2,stroke-width:2px classDef endpoint fill:#C8E6C9,stroke:#388E3C,stroke-width:2px class Phase1,Phase2,Phase3,Phase4,Phase5 phase class Start,End endpoint

Phase Descriptions

Phase 1: Discovery
Phase 2: Load Done Implementation Tasks
Phase 3: Analyze Code Changes
Phase 4: Check Violations (5 checks)
Phase 5: Report Results

Violation Types

1. DRY (Don't Repeat Yourself)

Detects: Duplicate functions, code blocks, validation logic, error handling patterns

Example: Same validation function in 3 different files

Fix: Extract to shared utility module

Severity: HIGH if >2 duplicates, MEDIUM if 2 duplicates

2. KISS (Keep It Simple)

Detects: High cyclomatic complexity (>10), deep nesting (>4 levels), long functions (>50 lines)

Example: Function with 5 nested if statements

Fix: Simplify with early returns, extract helper functions

Severity: HIGH if complexity >15, MEDIUM if >10

3. YAGNI (You Aren't Gonna Need It)

Detects: Unused functions, premature abstraction, over-engineering

Example: Interface with only one implementation

Fix: Remove unused code, simplify abstraction

Severity: MEDIUM (doesn't break functionality, adds maintenance burden)

4. Architecture Violations

Detects: Layer violations (controller → repository, skipping service), circular dependencies

Example: Controller imports Repository directly instead of Service

Fix: Follow layer hierarchy: Controller → Service → Repository

Severity: HIGH (breaks architecture, creates coupling)

5. Guide Compliance Violations

Detects: Code doesn't follow recommended patterns from project guides

Example: Custom JWT implementation instead of authlib (Guide 01 recommendation)

Fix: Use recommended library/pattern from guide

Severity: HIGH if security/critical, MEDIUM otherwise

Output Format

{
  "verdict": "PASS" | "ISSUES_FOUND",
  "story_id": "US001",
  "tasks_analyzed": 3,
  "issues": [
    {
      "type": "DRY",
      "severity": "HIGH",
      "file": "src/auth/service.py",
      "line": 42,
      "description": "Duplicate validation logic in 3 places",
      "suggestion": "Extract to shared validator function"
    }
  ],
  "summary": {
    "dry_violations": 2,
    "kiss_violations": 1,
    "yagni_violations": 0,
    "architecture_violations": 1,
    "guide_violations": 1,
    "total_issues": 5,
    "high_severity": 3,
    "medium_severity": 2,
    "low_severity": 0
  },
  "linear_comment_id": "abc123"
}
    

Key Characteristics

Complexity Metrics

Cyclomatic Complexity Thresholds: