find-duplication

作成者: openshift

コードベース内のコード重複を検出します。現在のブランチの変更にスコープを限定するモードと、コードベース全体をスキャンするモードの2つをサポートしています。ユーザーが検出を依頼した場合に使用します…

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.

openshiftのその他のスキル

openshift-docs
openshift
OpenShift Container Platformのドキュメントをマークダウン形式で検索および閲覧します。ユーザーがOpenShiftの機能、設定、インストールなどについて質問する場合に使用します。
triage-leaked-infra
openshift
AWS VPCまたはHyperShift CIからのインフラセットが削除しても安全かどうかを評価します。ユーザーがcleanleakedの出力を貼り付け、「これは削除できますか?」「これは…」と尋ねたときに使用します。
openshift-expert
openshift
OpenShiftプラットフォームとKubernetesのエキスパートであり、クラスターアーキテクチャ、オペレーター、ネットワーキング、ストレージ、トラブルシューティング、CI/CDパイプラインに関する深い知識を持つ。使用…
Konflux Archived PipelineRuns
openshift
アーカイブされたKonflux PipelineRun、TaskRun、およびポッドログにKubeArchive経由でアクセスします。Konflux PipelineRunの結果を確認する際や調査時に自動適用されます。
backport
openshift
メインからリリースブランチへのコミットやPRをバックポートします。ユーザーがバックポート、チェリーピック、ブランチ間の変更の移植を依頼した場合、または解決中に使用します。
rebase
openshift
現在のブランチをベースブランチにリベースし、すべてのコンフリクトを解決して、lint、i18n、ビルドが通ることを確認します。ユーザーがリベース、更新、同期を依頼した場合に使用します…
Build CPO Image
openshift
コントロールプレーンオペレーターのコンテナイメージをビルドしてプッシュします。CPOの変更をライブクラスターにデプロイしてテストする際に自動適用されます。
find-complexity
openshift
サイクロマティック複雑度が高い、長すぎる、またはパラメータが多すぎる関数やメソッドを見つけます。ユーザーが複雑なコードや複雑性を探すよう依頼した場合に使用します。