Lower Code Complexity
Reduces the cognitive complexity threshold by 2 and fixes all violations.
Step 1: Gather Requirements
- •Read current threshold from eslint config (cognitive-complexity rule)
- •Calculate new threshold: current - 2 (e.g., 15 -> 13)
- •Run lint with the new threshold to find violations:
bash
bun run lint 2>&1 | grep "cognitive-complexity"
- •Note for each violation:
- •File path and line number
- •Function name
- •Current complexity score
If no violations at new threshold, report success and exit.
Step 2: Create Plan
In plan mode, create a plan that includes the following details:
markdown
Reduce cognitive complexity threshold from [current] to [new]. ## Functions Exceeding Threshold (ordered by complexity) 1. src/services/user.ts:processUser (complexity: 18, target: [new]) - Line 45, function spans lines 45-120 2. src/utils/helpers.ts:validateInput (complexity: 15, target: [new]) - Line 23, function spans lines 23-67 ... ## Configuration Change - File: [eslint config path] - Change: cognitive-complexity threshold from [current] to [new] ## Refactoring Strategies - **Extract functions**: Break complex logic into smaller, named functions - **Early returns**: Reduce nesting with guard clauses - **Extract conditions**: Move complex boolean logic into named variables - **Use lookup tables**: Replace complex switch/if-else chains with object maps ## Acceptance Criteria - All functions at or below complexity [new] - `bun run lint` passes with no cognitive-complexity violations ## Verification Command: `bun run lint 2>&1 | grep "cognitive-complexity" | wc -l` Expected: 0