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의 다른 스킬

openshift-expert
openshift
OpenShift 플랫폼 및 Kubernetes 전문가로, 클러스터 아키텍처, 오퍼레이터, 네트워킹, 스토리지, 문제 해결 및 CI/CD 파이프라인에 대한 깊은 지식을 보유하고 있습니다. 사용…
official
find-token
openshift
숨겨진 인증 토큰을 찾습니다. find-token 스크립트를 실행하여 고유 토큰을 검색하세요.
official
code-review
openshift
풀 리퀘스트의 코드 품질, 정확성, 프로젝트 규칙을 검토합니다. 사용자가 PR 검토, 코드 리뷰, 또는 변경 사항 확인을 요청할 때 사용하세요.
official
css-review
openshift
CSS 코딩 스타일, PatternFly 토큰 사용, 모범 사례를 검토합니다. 사용자가 CSS 검토, 스타일 확인, 또는 CSS 파일 감사를 요청할 때 사용하세요.
official
review-readmes
openshift
리포지토리의 모든 README.md 파일을 검토하여 오타, 오류, 오래된 정보를 찾습니다. 사용자가 README 검토, 문서 정확성 확인 등을 요청할 때 사용합니다.
official
review-skills
openshift
프로젝트 AI 스킬의 중복, 오래된 참조, 오류 및 구조적 문제를 검토합니다. 사용자가 스킬 검토, 스킬 감사, 확인 등을 요청할 때 사용하세요.
official
test
openshift
태그로 필터링된 종단 간 테스트를 실행합니다. 사용자가 테스트 실행, Playwright 실행, 또는 @core나 @attach 같은 특정 기능 태그를 테스트하도록 요청할 때 사용하세요.
official
unused-exports
openshift
다른 파일에서 가져오지 않은 내보낸 심볼을 찾습니다. 사용자가 "내보내기 확인", "사용되지 않는 내보내기"라고 말하거나 내보내기를 정리하도록 요청할 때 사용하세요.
official