find-dead-code

bởi openshift

Tìm các hàm, lớp, import không được sử dụng và các đường dẫn mã không thể truy cập. Sử dụng khi người dùng yêu cầu tìm mã chết, mã không dùng, các ứng viên cần dọn dẹp, hoặc muốn…

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

Find Dead Code

Detect unused code that can be safely removed.

Rules

  • Report findings, do not delete. Removal is a separate task.
  • Focus on production code (ols/). Skip tests unless explicitly asked.
  • Vulture has false positives — classify each finding before recommending removal.
  • Code used only via dynamic dispatch (e.g. Pydantic validators, FastAPI dependencies) is not dead.

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: Run Vulture

uvx vulture <target> --min-confidence 80

--min-confidence 80 reduces noise. Lower confidence findings are more likely false positives.

Step 3: Run Pylint Unused Checks

uv run pylint --disable=all --enable=unused-import,unused-variable,unused-argument,unreachable <target>

Cross-reference with vulture findings to increase confidence.

Step 4: Filter False Positives

Common false positives in this codebase:

PatternWhy it's not dead
Pydantic model_validator, field_validatorCalled by Pydantic, not directly
FastAPI dependency functionsInjected via Depends()
__eq__, __hash__, __str__Called implicitly by Python
Constants used in config YAMLReferenced by config loader
Abstract method implementationsCalled via base class interface
Imports re-exported from __init__.pyUsed by external consumers

Step 5: Classify Findings

For each finding, classify:

CategoryCriteriaAction
RemoveClearly unused, no dynamic referencesSafe to delete
VerifyPossibly used dynamically or externallySearch for string references before removing
False positivePydantic/FastAPI/magic methodSkip

For "Verify" findings, search for string-based references:

rg "<function_or_class_name>" ols/ tests/

Step 6: Report

For each finding:

  1. File and line number
  2. What is unused (function, class, import, variable)
  3. Confidence level (vulture %)
  4. Classification (remove / verify / false positive)

Summary: total findings, how many safe to remove, 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…