cognitive-complexity-refactoring
Skill8 starsChanged 6 months agoMITView on GitHub
Use when Biome reports noExcessiveCognitiveComplexity, when functions have deeply nested conditionals (3+ levels), or when refactoring large functions.
In this repository129 other files it gives its agents.
- AGENTS.mdAGENTS.md
- guidance/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- guidance/CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- blast-radius-checkSkill
- brainstormingSkill
- branch-flow-gateSkill
- branch-sync-gateSkill
- codebase-reconSkill
- codeowners-drift-auditSkill
- code-review-batterySkill
- debateSkill
- debug-conductorSkill
- dispatching-parallel-agentsSkill
- domain-buildSkill
- evidence-adjudicatorSkill
- executing-plansSkill
- external-cli-auditSkill
- feature-developmentSkill
- field-rename-verificationSkill
- finishing-a-development-branchSkill
- git-branch-conventionsSkill
- gitlab-cliSkill
- hotfix-charterSkill
- implementation-trackerSkill
- incident-revert-reviewSkill
- infra-config-investigatorSkill
- investigation-stateSkill
- kernel-splitSkill
- llm-behavior-investigatorSkill
- llm-skill-reviewSkill
- merge-authorization-gateSkill
- micro-harsh-reviewSkill
- output-verificationSkill
- pre-commit-gateSkill
- progressive-code-review-gateSkill
- progressive-harsh-reviewSkill
- providing-code-reviewSkill
- pr-triage-gateSkill
- push-authorization-gateSkill
- receiving-code-reviewSkill
- reproduction-experiment-investigatorSkill
- requesting-code-reviewSkill
- requirements-validation-pmSkill
- requirements-validationSkill
- scope-tripwireSkill
- session-handoffSkill
- skills-hierarchy-tuningSkill
- sp-bughuntSkill
- state-consistency-investigatorSkill
- subagent-driven-developmentSkill
- systematic-debuggingSkill
- test-driven-developmentSkill
- timeline-trace-investigatorSkill
- token-estimationSkill
- unified-commit-gateSkill
- using-git-worktreesSkill
- using-superpowersSkill
- verification-before-completionSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 41
When Biome reports an error:
- Distinctive: line 157
If file >300 lines: Refactor into smaller focused files.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
cognitive-complexity-refactoring
When to Use
Invoke this skill when:
- Biome reports:
noExcessiveCognitiveComplexity - Function has 3+ levels of nesting
- You're reviewing a function >30 lines
- Code has multiple nested if/else chains
- You need to simplify complex logic
CRITICAL RULE: NO biome-ignore
biome-ignore comments are BANNED in new code.
When Biome reports an error:
- REQUIRED: Refactor the code to fix the actual issue
- REQUIRED: Extract functions, simplify logic, reduce nesting
- BANNED: Adding
// biome-ignoreto suppress the warning
// ❌ NEVER DO THIS
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: complex
function handleMessage(data: Buffer): void {
// 25 lines of nested if/else statements
}
// ✅ ALWAYS DO THIS - Extract to smaller functions
function handleMessage(data: Buffer): void {
const message = parseMessage(data)
if (message.type === 'partial') {
handlePartialResult(message)
} else if (message.type === 'final') {
handleFinalResult(message)
}
}
function handlePartialResult(message: Message): void {
if (!message.text) return
const event = createResultEvent(message, false)
emitResult(event)
}What is Cognitive Complexity?
Measures how hard a function is to understand.
Calculates based on:
- Nesting depth (each level adds complexity)
- Control flow structures (if, for, while, switch)
- Logical operators (&&, ||)
- Recursion
Threshold: Maximum 15 (configured in biome.json)
Refactoring Patterns
Pattern 1: Extract Nested Logic
// ✅ Complexity reduced by extraction
function processCoordinates() {
for (let x = 0; x < 10; x++) {
for (let y = 0; y < 10; y++) {
processPoint(x, y)
}
}
}
function processPoint(x: number, y: number) {
if (x % 2 !== 0) return
if (y % 2 !== 0) return
const max = x > y ? x : y
console.log(max)
}Pattern 2: Early Returns
// ✅ Complexity: 3
function validate(data: Data | null): boolean {
if (!data) return false
if (!data.isValid) return false
if (!data.hasRequiredFields()) return false
return true
}
// vs ❌ Complexity: 6
function validate(data: Data | null): boolean {
if (data) {
if (data.isValid) {
if (data.hasRequiredFields()) {
return true
}
}
}
return false
}Pattern 3: Extract Conditions
// ✅ Reduce nesting
const canProcess = isActive && hasPermission && !isBlocked
if (!canProcess) return
processItem()
// vs ❌ Nested ifs
if (isActive) {
if (hasPermission) {
if (!isBlocked) {
processItem()
}
}
}File Size Limits
Standard: <300 lines per file Exception: Cohesive state machines (~350 lines acceptable)
If file >300 lines: Refactor into smaller focused files.
Verification
pnpm lint # No Biome complexity warningsA task is NOT complete until this passes.
Failure Modes
| Mode | Symptom | Recovery |
| Over-refactor | New bugs introduced | Run tests after each extraction |
| Wrong extraction boundary | Makes code harder to follow | Keep related logic together |
| Extracting too aggressively | Many tiny functions obscure flow | Balance complexity score with readability |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

