find-complexity

द्वारा openshift

उच्च चक्रीय जटिलता, अत्यधिक लंबाई या बहुत अधिक पैरामीटर वाले फ़ंक्शन खोजें। उपयोग तब करें जब उपयोगकर्ता जटिल कोड, जटिलता हॉटस्पॉट खोजने के लिए कहे,…

npx skills add https://github.com/openshift/lightspeed-operator --skill find-complexity

Find Complexity Hotspots

Identify Go functions that are hard to review, test, and maintain.

Rules

  • Report findings, do not refactor. Refactoring is a separate task.
  • Focus on production code (internal/, api/, cmd/). Skip tests unless explicitly asked.
  • Rank by severity: highest complexity first.

Step 1: Determine Scope

Ask the user:

  • Branch mode: only files changed in the current branch vs main.
  • Full mode: scan the entire codebase.

For branch mode:

git diff --name-only upstream/main -- 'internal/' 'api/' 'cmd/' | grep '\.go$' | grep -v '_test\.go$'

Step 2: Install Prerequisites

Install gocyclo and gocognit if not available:

go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
go install github.com/uudashr/gocognit/cmd/gocognit@latest

Step 3: Cyclomatic Complexity

gocyclo -over 10 <target>

This shows functions with cyclomatic complexity over 10.

Thresholds: 1-10 (simple), 11-20 (moderate), 21-50 (complex), 51+ (untestable).

Step 4: Cognitive Complexity

Cognitive complexity weights nesting depth — a 5-deep if scores much higher than 5 sequential ifs.

gocognit -over 15 <target>

This shows functions with cognitive complexity over 15.

Step 5: Function Length

Find long functions (50+ lines of code, excluding comments and blank lines):

for file in $(find <target> -name '*.go' -not -name '*_test.go'); do
    awk '/^func / {start=NR; func=$0} 
         /^}/ && start {
           len=NR-start; 
           if(len>50) print FILENAME":"start": "func" ("len" lines)"
         }' "$file"
done

Step 6: Parameter Count

Find functions with too many parameters (6+):

rg "^func.*\([^)]{60,}\)" <target> -A 0

Functions with 6+ parameters are candidates for parameter objects or config structs.

Step 7: File Size

Find large files (500+ lines):

wc -l $(find <target> -name '*.go' -not -name '*_test.go') | sort -rn | head -20

Files over 500 lines are candidates for splitting into focused packages.

Step 8: Classify Findings

For each function found, classify:

CategoryCriteriaAction
SplitHigh complexity + long bodyBreak into smaller functions
SimplifyHigh complexity + short bodyReduce branching (early returns, switch statements)
ParameterizeToo many arguments (6+)Group into config struct
MonitorComplexity 11-15, not growingNote it, revisit if it gets worse
Split fileFile over 500 linesBreak into focused packages

Step 9: Report

For each finding:

  1. File, function name, line number
  2. Cyclomatic/cognitive complexity score
  3. Lines of code / parameter count
  4. Classification (split / simplify / parameterize / monitor)
  5. Brief suggestion

Summary: total hotspots, top 5 worst offenders, estimated refactoring effort.

openshift की और Skills

openshift-expert
openshift
OpenShift प्लेटफ़ॉर्म और Kubernetes विशेषज्ञ जिसे क्लस्टर आर्किटेक्चर, ऑपरेटर, नेटवर्किंग, स्टोरेज, समस्या निवारण और CI/CD पाइपलाइनों का गहन ज्ञान है। उपयोग करें…
official
find-token
openshift
Find the hidden verification token. Run the find-token script to retrieve a unique token.
official
code-review
openshift
पुल रिक्वेस्ट की कोड गुणवत्ता, शुद्धता और प्रोजेक्ट कन्वेंशन के लिए समीक्षा करें। उपयोग तब करें जब उपयोगकर्ता PR की समीक्षा, कोड रिव्यू या बदलावों की जांच करने के लिए कहे...
official
css-review
openshift
सीएसएस को कोडिंग शैली, पैटर्नफ्लाई टोकन उपयोग और सर्वोत्तम प्रथाओं के लिए समीक्षा करें। जब उपयोगकर्ता सीएसएस की समीक्षा करने, शैलियों की जांच करने या सीएसएस फाइलों का ऑडिट करने के लिए कहे तब उपयोग करें।
official
review-readmes
openshift
रिपॉजिटरी में सभी README.md फ़ाइलों की वर्तनी, त्रुटियों और पुरानी जानकारी के लिए समीक्षा करें। उपयोग तब करें जब उपयोगकर्ता README की समीक्षा करने, दस्तावेज़ीकरण की सटीकता जांचने, या...
official
review-skills
openshift
प्रोजेक्ट AI स्किल्स में डुप्लिकेशन, पुराने संदर्भ, गलतियाँ और संरचनात्मक समस्याओं की समीक्षा करें। उपयोग तब करें जब उपयोगकर्ता स्किल्स की समीक्षा, ऑडिट, या जाँच करने के लिए कहे...
official
test
openshift
टैग द्वारा फ़िल्टर करके एंड-टू-एंड परीक्षण चलाएँ। इसका उपयोग तब करें जब उपयोगकर्ता परीक्षण चलाने, Playwright चलाने, या @core या @attach जैसे किसी विशिष्ट फीचर टैग का परीक्षण करने के लिए कहे।
official
unused-exports
openshift
उन निर्यातित प्रतीकों को खोजें जो कभी किसी अन्य फ़ाइल द्वारा आयात नहीं किए गए हैं। इसका उपयोग तब करें जब उपयोगकर्ता "check exports", "unused exports" कहे या निर्यात साफ करने के लिए कहे।
official