find-duplication

bởi openshift

Tìm mã trùng lặp trong codebase. Hỗ trợ hai chế độ - giới hạn trong các thay đổi của nhánh hiện tại hoặc quét toàn bộ codebase. Sử dụng khi người dùng yêu cầu tìm…

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

Find Code Duplication

Detect duplicated or near-duplicate code and suggest consolidation candidates.

Rules

  • Report findings, do not refactor. Refactoring is a separate task.
  • Focus on production code (ols/). Skip test duplication unless explicitly asked.
  • Group findings by severity: exact duplicates first, then near-duplicates.
  • For each finding, state whether extraction is worth it or acceptable duplication.

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$'

For full mode, the target is ols/.

Step 2: Run Pylint Duplicate Detection

uv run pylint --disable=all --enable=duplicate-code --min-similarity-lines=6 <target files or directory>

Review output. Filter out false positives:

  • Import blocks (common imports are not duplication)
  • Pydantic model boilerplate (Field declarations)
  • Single-line patterns (logging, raises)

Step 3: Semantic Duplication Search

Pylint only catches textual similarity. Also look for:

  1. Similar function signatures — functions with near-identical parameter lists doing similar work.
  2. Repeated error handling — same try/except/log/return pattern across multiple files.
  3. Copy-pasted blocks — search for distinctive string literals or variable names that appear in multiple files.
rg "<distinctive pattern>" ols/ --type py -l

Step 4: Classify Findings

For each duplicate found, classify:

CategoryAction
Extract — identical logic in 3+ placesRecommend a shared helper
Parameterize — same structure, different valuesRecommend a common function with parameters
Acceptable — similar but serving different domainsNote it, no action needed
Test-only — repeated test setup/fixturesRecommend shared fixture (only if user asked)

Step 5: Report

For each finding:

  1. Files and line ranges involved
  2. What is duplicated (brief description)
  3. Classification (extract / parameterize / acceptable)
  4. Suggested location for shared code (if applicable)

Summary: total findings, how many actionable, estimated lines saved.

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