find-complexity

bởi openshift

Tìm các hàm và phương thức có độ phức tạp cyclomatic cao, độ dài quá mức hoặc quá nhiều tham số. Sử dụng khi người dùng yêu cầu tìm mã phức tạp, độ phức tạp…

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

Find Complexity Hotspots

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

Rules

  • Report findings, do not refactor. Refactoring is a separate task.
  • Focus on production code (ols/). 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 ols/ directory.

For branch mode:

git diff --name-only origin/main -- 'ols/' | grep '\.py$'

Step 2: Cyclomatic Complexity

uvx radon cc <target> -s -n C -a

This shows functions with complexity grade C or worse (threshold: 11+).

Grades: A (1-5), B (6-10), C (11-15), D (16-20), E (21-25), F (26+).

Step 3: Maintainability Index

uvx radon mi <target> -s -n B

This shows files with maintainability grade B or worse.

Grades: A (20+, good), B (10-19, medium), C (0-9, poor).

Step 4: Cognitive Complexity

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

uvx --with flake8-cognitive-complexity flake8 --select=CCR001 --max-cognitive-complexity=10 <target>

Step 5: Function Length

Find long functions (30+ lines of logic, excluding docstrings and blank lines):

uvx radon raw <target> -s

Also use pylint for method length:

uv run pylint --disable=all --enable=too-many-statements,too-many-branches,too-many-return-statements,too-many-arguments,too-many-locals <target>

Step 6: File Size

Find large files (500+ lines):

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

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

Step 7: Classify Findings

For each function found, classify:

CategoryCriteriaAction
SplitHigh complexity + long bodyBreak into smaller functions
SimplifyHigh complexity + short bodyReduce branching (early returns, lookup tables)
ParameterizeToo many arguments (6+)Group into config/dataclass
MonitorGrade C, not growingNote it, revisit if it gets worse
Split fileFile over 500 linesBreak into focused modules

Step 8: Report

For each finding:

  1. File, function name, line number
  2. Complexity grade and score
  3. Number of statements / arguments
  4. Classification (split / simplify / parameterize / monitor)
  5. Brief suggestion

Summary: total hotspots by grade, top 5 worst offenders.

Thêm skills từ openshift

openshift-expert
openshift
Chuyên gia nền tảng OpenShift và Kubernetes với kiến thức sâu về kiến trúc cluster, operators, mạng, lưu trữ, xử lý sự cố và pipeline CI/CD. Sử dụng…
official
find-token
openshift
Tìm mã xác thực ẩn. Chạy tập lệnh find-token để lấy mã duy nhất.
official
code-review
openshift
Xem xét một pull request về chất lượng mã, tính đúng đắn và các quy ước của dự án. Sử dụng khi người dùng yêu cầu xem xét một PR, đánh giá mã, hoặc kiểm tra các thay đổi trên một…
official
css-review
openshift
Xem xét CSS về phong cách mã hóa, cách sử dụng token PatternFly và các phương pháp tốt nhất. Sử dụng khi người dùng yêu cầu xem xét CSS, kiểm tra kiểu dáng hoặc kiểm tra các tệp CSS.
official
review-readmes
openshift
Xem xét tất cả các tệp README.md trong kho lưu trữ để tìm lỗi chính tả, lỗi sai và thông tin lỗi thời. Sử dụng khi người dùng yêu cầu xem xét README, kiểm tra độ chính xác của tài liệu, hoặc…
official
review-skills
openshift
Xem xét các kỹ năng AI của dự án để phát hiện trùng lặp, tham chiếu lỗi thời, sai sót và vấn đề cấu trúc. Sử dụng khi người dùng yêu cầu xem xét kỹ năng, kiểm tra kỹ năng, kiểm tra…
official
test
openshift
Chạy kiểm thử đầu cuối được lọc theo thẻ. Sử dụng khi người dùng yêu cầu chạy kiểm thử, chạy Playwright, hoặc kiểm thử một tính năng cụ thể có thẻ như @core hoặc @attach.
official
unused-exports
openshift
Tìm các ký hiệu được xuất khẩu nhưng không bao giờ được nhập vào tệp khác. Sử dụng khi người dùng nói "kiểm tra xuất khẩu", "xuất khẩu không dùng" hoặc yêu cầu dọn dẹp xuất khẩu.
official