find-dead-code

tarafından openshift

Find unused functions, types, constants, imports, and unreachable code paths. Use when the user asks to find dead code, unused code, cleanup candidates, or…

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

Find Dead Code

Detect unused Go code that can be safely removed.

Rules

  • Report findings, do not delete. Removal is a separate task.
  • Focus on production code (internal/, api/, cmd/). Skip tests unless explicitly asked.
  • Tools have false positives — classify each finding before recommending removal.
  • Code used via reflection or dynamic dispatch (e.g. Kubernetes controller-runtime, interface implementations) 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 codebase.

For branch mode:

git diff --name-only upstream/main -- 'internal/' 'api/' 'cmd/' | grep '\.go$' | grep -v '_test\.go$'

Step 2: Run Go Standard Tooling

Check for unused code with the compiler:

go build ./... 2>&1 | grep "declared and not used"
go vet ./... 2>&1 | grep -E "(not used|never used)"

Step 3: Run staticcheck

staticcheck detects unused code, including unexported functions, constants, and variables:

staticcheck -checks=U1000 ./...

U1000 reports unused code that is not exported and not referenced.

Step 4: Run deadcode (Go 1.23+)

If Go 1.23+ is available:

go run golang.org/x/tools/cmd/deadcode@latest -filter <package-pattern>

This finds functions, types, and variables that are never called or referenced.

Step 5: Check Unused Imports

goimports -l <target>

Any file listed has unused imports. Review with:

goimports -d <file>

Step 6: Filter False Positives

Common false positives in this codebase:

PatternWhy it's not dead
Reconcile(ctx, req) implementationsCalled by controller-runtime via interface
SetupWithManager() functionsCalled by manager setup code
init() functionsCalled automatically by Go runtime
Interface method implementationsCalled through interface, not directly
kubebuilder: marker functionsUsed by code generation
Constants/vars in constants.goMay be used in tests or future code
Error constants matching Err* patternMay be used in error wrapping

Step 7: Classify Findings

For each finding, classify:

CategoryCriteriaAction
RemoveClearly unused, no interface/reflection useSafe to delete
VerifyPossibly used dynamically or via interfaceSearch for references before removing
False positiveInterface impl, reflection, kubebuilder markerSkip

For "Verify" findings, search for references:

rg "<function_or_type_name>" internal/ api/ cmd/ test/

Step 8: Report

For each finding:

  1. File and line number
  2. What is unused (function, type, constant, variable, import)
  3. Tool that detected it (staticcheck, deadcode, goimports)
  4. Classification (remove / verify / false positive)
  5. Estimated lines saved

Summary: total findings, how many safe to remove, estimated cleanup size.

openshift tarafından daha fazla skill

openshift-expert
openshift
OpenShift platform ve Kubernetes uzmanı olup, küme mimarisi, operatörler, ağ oluşturma, depolama, sorun giderme ve CI/CD boru hatları konularında derin bilgiye sahiptir. Kullan…
official
find-token
openshift
Gizli doğrulama token'ını bulun. Benzersiz bir token almak için find-token betiğini çalıştırın.
official
code-review
openshift
Bir çekme isteğini kod kalitesi, doğruluk ve proje kuralları açısından inceleyin. Kullanıcı bir PR'ı incelemeyi, kod incelemesi yapmayı veya bir... üzerindeki değişiklikleri incelemeyi istediğinde kullanın.
official
css-review
openshift
CSS kod stilini, PatternFly token kullanımını ve en iyi uygulamaları gözden geçir. Kullanıcı CSS incelemesi, stil kontrolü veya CSS dosyalarını denetleme talebinde bulunduğunda kullan.
official
review-readmes
openshift
Depodaki tüm README.md dosyalarını yazım hataları, hatalar ve güncel olmayan bilgiler açısından gözden geçir. Kullanıcı README'leri gözden geçirmeyi, dokümantasyon doğruluğunu kontrol etmeyi istediğinde veya…
official
review-skills
openshift
Proje yapay zeka becerilerini tekrarlar, güncelliğini yitirmiş referanslar, hatalar ve yapısal sorunlar açısından gözden geçir. Kullanıcı becerileri gözden geçirmek, denetlemek, kontrol etmek istediğinde kullan…
official
test
openshift
Etiketle filtrelenmiş uçtan uca testleri çalıştırın. Kullanıcı test çalıştırmak, Playwright çalıştırmak veya @core ya da @attach gibi belirli bir özellik etiketini test etmek istediğinde kullanın.
official
unused-exports
openshift
Başka bir dosya tarafından hiç içe aktarılmayan dışa aktarılmış sembolleri bulur. Kullanıcı "dışa aktarımları kontrol et", "kullanılmayan dışa aktarımlar" dediğinde veya dışa aktarımları temizlemeyi istediğinde kullanın.
official