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-docs
openshift
Tìm kiếm và đọc tài liệu OpenShift Container Platform ở định dạng markdown. Sử dụng khi người dùng hỏi về các tính năng, cấu hình, cài đặt của OpenShift,…
triage-leaked-infra
openshift
Đánh giá xem VPC AWS hoặc bộ hạ tầng từ HyperShift CI có an toàn để xóa hay không. Sử dụng khi người dùng dán đầu ra cleanleaked và hỏi 'tôi có thể xóa cái này không?', 'có…
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…
Konflux Archived PipelineRuns
openshift
Truy cập các PipelineRuns, TaskRuns và nhật ký pod Konflux đã lưu trữ thông qua KubeArchive. Tự động áp dụng khi kiểm tra kết quả PipelineRun Konflux, điều tra…
backport
openshift
Backport các commit hoặc PR từ nhánh main sang nhánh release. Sử dụng khi người dùng yêu cầu backport, cherry-pick, hoặc chuyển các thay đổi giữa các nhánh, hoặc khi đang xử lý…
rebase
openshift
Rebase nhánh hiện tại lên nhánh cơ sở của nó, giải quyết tất cả xung đột, và xác minh lint, i18n, và build đều thành công. Sử dụng khi người dùng yêu cầu rebase, cập nhật, hoặc đồng bộ…
Build CPO Image
openshift
Xây dựng và đẩy hình ảnh container control-plane-operator. Tự động áp dụng khi kiểm tra các thay đổi CPO yêu cầu triển khai lên cụm trực tiếp.
find-complexity
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…