agentleFS
Vimalk0703Vimalk0703/shipworthy/skills/quality/code-complexity/SKILL.md

code-complexity

Skill6 starsChanged 8 months agoMITView on GitHub

Enforce cyclomatic complexity limits, function/file length limits, nesting depth, parameter counts, and duplication detection. Keeps code readable and maintainable.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If you need a comment like // Step 3: ..., that step is its own function.

    line 26
  2. Distinctive:

    If you copy-paste 3+ lines, extract a function.

    line 80

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code Complexity

Limits at a Glance

MetricLimitAction When Exceeded
Cyclomatic complexity< 15 per functionExtract helper functions
Function length~50 lines maxSplit into focused functions
File length~300 lines maxExtract modules/classes
Nesting depthMax 4 levelsEarly returns, extract functions
Parameter countMax 4-5 paramsUse an options/config object
Duplicate blocks> 3 lines repeated 2+ timesExtract shared function

Cyclomatic Complexity (< 15 per function)

Each if, else, case, &&, ||, catch, and ternary adds 1. When a function exceeds 15, extract validation, branching logic, or case handling into separate functions.

Function Length (~50 Lines Max)

If you need a comment like // Step 3: ..., that step is its own function.

// BAD -- 120-line function with section comments
function handleRequest(req: Request) { /* validate, fetch, transform, respond */ }

// GOOD -- each concern is a named function
function handleRequest(req: Request) {
  const input = validateInput(req);
  const data = fetchDependencies(input);
  return saveAndRespond(transformData(data));
}

Deep Nesting (Max 4 Levels)

// BAD -- 5 levels deep
function process(items) {
  if (items) {
    for (const item of items) {
      if (item.active) {
        if (item.type === 'premium') {
          if (item.balance > 0) { /* buried logic */ }
        }
      }
    }
  }
}

// GOOD -- flat with early returns and filtering
function process(items) {
  if (!items) return;
  const eligible = items.filter(i => i.active && i.type === 'premium' && i.balance > 0);
  for (const item of eligible) { /* top-level logic */ }
}

Parameter Count (Max 4-5)

// BAD -- 7 positional params
function createUser(name, email, role, team, avatar, locale, timezone) { ... }

// GOOD -- options object
interface CreateUserOptions {
  name: string; email: string; role: Role;
  team?: string; avatar?: string; locale?: string; timezone?: string;
}
function createUser(options: CreateUserOptions) { ... }

Duplication Detection

If you copy-paste 3+ lines, extract a function. Duplicated code means duplicated bugs. Two functions that are 80% identical should share a parameterized helper.

Enforcing with Tooling

{
  "rules": {
    "complexity": ["error", 15],
    "max-lines-per-function": ["warn", { "max": 50, "skipBlankLines": true }],
    "max-depth": ["error", 4],
    "max-params": ["warn", 5],
    "max-lines": ["warn", { "max": 300 }]
  }
}

Review Checklist

  • No function exceeds cyclomatic complexity of 15
  • Functions are under ~50 lines
  • Files are under ~300 lines
  • No nesting deeper than 4 levels
  • Functions with 5+ parameters use an options object
  • No copy-pasted blocks longer than 3 lines

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.