complexity
Skill1 starsChanged 7 months agoMITView on GitHub
Compute cyclomatic complexity per Apex method and per LWC JS function. Flags hotspots above a configurable threshold (default 10). Useful for spotting methods that need refactoring before they become unmaintainable.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- ffsshhttiikk/opencode-agents-skillstheir own version, first seen Feb 28, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- ffsshhttiikk/opencode-agents-skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository53 other files it gives its agents.
- templates/CLAUDE.mdCLAUDE.md
- adrSkill
- agent-deploySkill
- agent-discoverSkill
- agent-eval-trendSkill
- agent-exchange-listSkill
- agent-specSkill
- agent-testSkill
- agent-vs-flow-vs-apexSkill
- before-vs-after-triggerSkill
- code-reviewSkill
- coverage-trendSkill
- dead-codeSkill
- dependency-graphSkill
- deploySkill
- destructive-changesSkill
- diff-deploySkill
- erdSkill
- field-impactSkill
- flaky-test-finderSkill
- flow-auditSkill
- flow-vs-apexSkill
- fls-auditSkill
- gateway-configSkill
- generate-docsSkill
- limit-usageSkill
- lwc-vs-reactSkill
- mcp-tool-vs-restSkill
- notifySkill
- onboardSkill
- org-diffSkill
- org-exploreSkill
- package-versionSkill
- pattern-packSkill
- perf-reviewSkill
- permset-auditSkill
- pr-prepareSkill
- queueable-vs-batchSkill
- quick-deploySkill
- react-initSkill
- release-notesSkill
- scratch-orgSkill
- security-scanSkill
- sequence-diagramSkill
- sf-initSkill
- sharing-reviewSkill
- slack-agentSkill
- soql-analyzerSkill
- test-coverageSkill
- test-dataSkill
- test-planSkill
- trust-evalSkill
- trust-layer-auditSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are 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.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 116
PMD-driven for Apex: Don't reimplement CC counting — PMD's tested implementation is the right call
≈ “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
You are computing cyclomatic complexity (CC) — the number of linearly independent paths through a function. CC of 1 = straight-line code, 5 = moderate, 10 = at the limit of "manageable", 15+ = needs refactoring.
Read Project Config First
source "${CLAUDE_PLUGIN_ROOT}/hooks/lib/config.sh"
source "${CLAUDE_PLUGIN_ROOT}/hooks/lib/pmd.sh"
APEX_SRC="$(sf_config_get '.paths.apexSource' "$ENV")"
LWC_SRC="$(sf_config_get '.paths.lwcSource' "$ENV")"
TEST_SUFFIX="$(sf_config_get '.naming.apex.testSuffix' "$ENV")"PMD has built-in cyclomatic complexity rules — we delegate Apex CC to it. For LWC (JS), we count manually since PMD doesn't analyze JS.
Input
$ARGUMENTS:
- (empty) — scan everything
apex— Apex onlylwc— LWC JS only--threshold <n>— flag complexity above N (default 10)--ci/--format json|sarif/--out <path>
Steps
Apex (via PMD)
pmd_run check \
--dir "$APEX_SRC" \
--rulesets "category/apex/design.xml" \
--format json \
--report-file /tmp/complexity.pmd.json \
--no-progressFilter the PMD output to rules:
CyclomaticComplexity— primaryCognitiveComplexity— secondary (related but distinct)ExcessiveClassLength,ExcessiveMethodLength— overflow indicators
Convert each to internal finding shape with ruleId: "CPX-CYCLOMATIC" (or CPX-COGNITIVE, etc.).
LWC JS (heuristic counter)
For each .js file under ${LWC_SRC} (excluding __tests__):
- For each function (declaration or arrow assigned to a property), count the following as +1:
if,else ifcasein a switchfor,while,do- Ternary
? : - Logical
&&,||(short-circuit increases path) catchblock- Each top-level
returnafter the first
Base complexity = 1; cap at 50 for sanity (anything beyond is pathological).
Report findings with ruleId: "CPX-LWC-CYCLOMATIC", severity:
- 11–15: warning
- 16+: error
Output
Default Markdown:
# Complexity Report: <project.name>
Threshold: 10
Apex methods analyzed: 412 (production, excluding tests)
LWC JS functions analyzed: 287
Run at: 2026-04-28T15:15:00Z
## Apex hotspots (top 10)
| File | Method | Cyclomatic | Cognitive | Length |
|------|--------|------------|-----------|--------|
| force-app/.../OrderProcessor.cls | processBulk | 22 ⚠️ | 31 ⚠️ | 145 lines |
| force-app/.../LegacyImporter.cls | importBatch | 18 ⚠️ | 26 ⚠️ | 110 lines |
| ...
## LWC hotspots (top 10)
| File | Function | Cyclomatic |
|------|----------|------------|
| force-app/.../acmeOrderForm/acmeOrderForm.js | handleSave | 13 ⚠️ |
| ...
## Refactoring suggestions
- `OrderProcessor.processBulk` (CC 22): extract per-record logic into a helper; the 22 paths likely collapse to a single switch over status
- `acmeOrderForm.handleSave` (CC 13): split validation, persistence, and side-effects into separate methods
## Distribution
- ≤5 (good): 312 methods (76%)
- 6–10 (ok): 87 methods (21%)
- 11–15 (warn): 11 methods (3%)
- 16+ (error): 2 methods (1%)CI: SARIF per finding with severity mapped from threshold bands.
Exit codes
- 0 — no findings above threshold
- 1 — any finding above threshold
- 2 — PMD failed to run
Rules
- Threshold is configurable. Some teams accept 15; tighter teams set 8. Default 10 is the conventional middle
- Don't analyze test classes. They legitimately have many setup branches
- PMD-driven for Apex. Don't reimplement CC counting — PMD's tested implementation is the right call
- Heuristic for LWC. Without an AST parser available, the regex-based count is approximate. Flag the count alongside "approx" so the user knows
- No auto-refactor. This is a report; the user picks what to refactor
Consumers
/argo:code-reviewrolls hotspots into the LWC/Apex sections@architectconsults complexity before approving large additions to existing methods
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.

