Type-challenges’ build and automation layer is under structural stress. Three functions in the scripts/ directory—generatePlayground, an anonymous handler in issue-pr.ts, and an anonymous handler in labeling.ts—all carry critical activity risk (10.66–11.57) and exhibit god-function patterns with fan-out of 10–25 distinct function calls each. Across 140 total functions, 3 are critical and 4 more are high-band, with stale_complex being the dominant antipattern (4 occurrences), suggesting these functions have been repeatedly modified despite their structural complexity.
The table below ranks functions by activity-weighted risk — a score that multiplies structural complexity by recent commit frequency. A function that is both hard to understand (high cyclomatic complexity) and actively changing is a higher priority than one that is complex but untouched. CC = cyclomatic complexity (independent execution paths); ND = max nesting depth; FO = fan-out (distinct callees).
Top 5 Hotspots
| Function | File | Risk | CC | ND | FO |
|---|---|---|---|---|---|
generatePlayground | scripts/generate-play.ts | 11.6 | 18 | 3 | 25 |
<anonymous> | scripts/actions/issue-pr.ts | 11.4 | 27 | 3 | 24 |
<anonymous> | scripts/actions/labeling.ts | 10.7 | 16 | 3 | 10 |
<anonymous> | scripts/actions/toggle-pr-with-issue.ts | 8.3 | 11 | 1 | 7 |
updateIndexREADME | scripts/readme.ts | 8.3 | 9 | 3 | 15 |
Hotspot Analysis
generatePlayground — scripts/generate-play.ts
This function orchestrates playground generation with cyclomatic complexity of 18 and fan-out of 25, meaning it calls 25 distinct downstream functions. Activity risk of 11.57 indicates frequent recent commits. The combination of 18 independent execution paths (each a potential bug surface requiring test coverage) with broad coupling makes changes here a high blast-radius event—a small logic change can ripple across 25 callees and their tests.
Recommendation: Characterize the current behavior of generatePlayground with integration tests before any refactoring. Then systematically extract cohesive sub-functions (e.g., separate file discovery, template rendering, and validation concerns) to reduce CC and fan-out. Use the test suite as a regression safety net during decomposition.
<anonymous> — scripts/actions/issue-pr.ts
An unnamed handler function exhibits the highest cyclomatic complexity in the hotspot set at 27, with activity risk 11.39 and fan-out 24. This is a true god function: 27 independent paths through the control flow, touching 24 other functions, and flagged as both long_function and god_function. The high CC means test case debt—each branch is a potential failure mode.
Recommendation: Map the function’s logical responsibilities (GitHub API calls, PR state transitions, validation rules) and extract each into a dedicated handler. Start with a test-per-branch coverage scan to identify untested paths, then refactor incrementally behind that test wall. Consider extracting validation logic and state machine transitions into separate, testable modules.
<anonymous> — scripts/actions/labeling.ts
This anonymous handler ranks third at activity risk 10.66 with cyclomatic complexity 16 and fan-out 10. The stale_complex pattern indicates this function has been modified repeatedly despite its structural complexity, increasing the regression risk per commit. Nesting depth of 3 is moderate, but the 16 branches combined with active churn make it a prime candidate for defect introduction.
Recommendation: Add characterization tests covering the 16 code paths before making further changes. Identify which branches handle labeling rules vs. state checks vs. API interaction, and extract each into a named, single-responsibility function. This reduces the blast radius and makes future labeling logic changes safer.
Patterns Found
Antipatterns detected across the top functions in this snapshot:
| Pattern | Occurrences |
|---|---|
stale_complex | 4 |
god_function | 3 |
long_function | 2 |
These labels belong to two tiers — Tier 1 (structural): complex_branching, deeply_nested, exit_heavy, long_function, god_function. Tier 2 (relational/temporal): hub_function, cyclic_hub, middle_man, neighbor_risk, stale_complex, churn_magnet, shotgun_target, volatile_god.
Key Takeaways
- All three critical functions (generatePlayground, issue-pr handler, labeling handler) are in scripts/, not core library code—refactoring the build automation will have zero impact on published type-challenges behavior, making this low-risk, high-value work.
stale_complexdominates the antipattern set (4 occurrences), signaling that the team has iterated on already-complex code multiple times; add test coverage before the next commit to lock in behavior and make refactoring safe.- Fan-out values (10–25) are the silent risk multiplier: a logic error in generatePlayground (fan-out 25) can fail across 25 callers. Extract sub-functions and use integration tests to verify the public API contract, not just the implementation details.
Reproduce This Analysis
git clone https://github.com/type-challenges/type-challenges
cd type-challenges
git checkout 0b0b0b18bcb7ac42dc22ce26ffb438231d4754b1
hotspots analyze . --mode snapshot
Hotspots highlights structural and activity risk — not “bad code.” Findings are a prioritization aid, not a bug predictor. Editorial policy →