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.

Skills เพิ่มเติมจาก openshift

openshift-expert
openshift
ผู้เชี่ยวชาญด้านแพลตฟอร์ม OpenShift และ Kubernetes ที่มีความรู้เชิงลึกเกี่ยวกับสถาปัตยกรรมคลัสเตอร์ โอเปอเรเตอร์ เครือข่าย พื้นที่จัดเก็บข้อมูล การแก้ไขปัญหา และไปป์ไลน์ CI/CD ใช้…
official
find-token
openshift
ค้นหาโทเค็นการยืนยันที่ซ่อนอยู่ รันสคริปต์ find-token เพื่อดึงโทเค็นที่ไม่ซ้ำกัน
official
code-review
openshift
ตรวจสอบ pull request เพื่อดูคุณภาพโค้ด ความถูกต้อง และความสอดคล้องกับข้อกำหนดของโปรเจกต์ ใช้เมื่อผู้ใช้ขอให้ตรวจสอบ PR, ตรวจสอบโค้ด หรือตรวจสอบการเปลี่ยนแปลงใน...
official
css-review
openshift
ตรวจสอบ CSS สำหรับรูปแบบการเขียนโค้ด การใช้โทเค็น PatternFly และแนวปฏิบัติที่ดีที่สุด ใช้เมื่อผู้ใช้ขอให้ตรวจสอบ CSS ตรวจสอบสไตล์ หรือตรวจสอบไฟล์ CSS
official
review-readmes
openshift
ตรวจสอบไฟล์ README.md ทั้งหมดใน repo เพื่อหาคำผิด ข้อผิดพลาด และข้อมูลที่ล้าสมัย ใช้เมื่อผู้ใช้ขอให้ตรวจสอบ README ตรวจสอบความถูกต้องของเอกสาร หรือ…
official
review-skills
openshift
ตรวจสอบทักษะ AI ของโครงการเพื่อหาความซ้ำซ้อน การอ้างอิงที่ล้าสมัย ข้อผิดพลาด และปัญหาเชิงโครงสร้าง ใช้เมื่อผู้ใช้ขอให้ตรวจสอบทักษะ ตรวจสอบทักษะ ตรวจสอบหา…
official
test
openshift
รันการทดสอบแบบ end-to-end ที่กรองตามแท็ก ใช้เมื่อผู้ใช้ขอให้รันการทดสอบ รัน Playwright หรือทดสอบฟีเจอร์เฉพาะแท็ก เช่น @core หรือ @attach
official
unused-exports
openshift
ค้นหาสัญลักษณ์ที่ถูกส่งออกแต่ไม่เคยถูกนำเข้าโดยไฟล์อื่น ใช้เมื่อผู้ใช้พูดว่า "ตรวจสอบการส่งออก" "ส่งออกที่ไม่ได้ใช้" หรือขอให้ทำความสะอาดการส่งออก
official