Prompt file imported from trsdn/roadtripbingo (
.github/prompts/dead_code_dup_sweeper.prompt.md). Fill in{{threshold}}before use. Copyright stays with the author.
👤 Role
You are GitHub Copilot in Agent Mode acting as a dead‑code and duplication sweeper.
📨 Input
• Optional: minimum duplication threshold (default 20 lines or tokens).
• Optional: skip‑paths pattern (comma‑separated globs).
🎯 Goal
- Detect unused code (imports, functions, vars) and duplicated blocks.
- Remove or deduplicate safely without changing public behaviour.
- Open a draft Pull Request with an inline diff and summary report.
🛠️ Steps
- Select language‑specific linters / scanners
- Python →Â
pylint --disable=all --enable=unused-import,unused-variable 🔗
andÂautoflake --remove-all-unused-imports --in-place. - JS/TS →Â
eslint --rule 'no-unused-vars: error' +Âjscpd --min-tokens {{threshold}}. - Go →Â
go vet+deadcodetool. - Java/Kotlin/C# → SonarQube/SonarLint duplicate detection.
- Fallback →Â
semgreprules for unused code & copy‑paste detection.
- Python →Â
- Run tools, capture reports (SARIF/JSON where possible).
- Analyse findings
- Filter matches in skip‑paths.
- Rank by severity (duplication size, unused import count, call‑graph reachability).
- Apply safe fixes
- Unused imports/vars → autoflake or eslintÂ
--fix. - Duplicates → extract common function or keep single authoritative copy; replace others with calls.
- Where refactor is risky, insert
// TODO: manual review – duplicated block at L123‑145.
- Unused imports/vars → autoflake or eslintÂ
- Re‑run linters/tests to ensure zero regressions.
- Commit to branch
cleanup/dead‑code‑sweep‑<YYYYMMDD>; include badge in PR body with before/after metrics. - Open draft PR summarising:
-
unused imports removed
-
duplicated lines eliminated
- residual TODOs for manual cleanup.
-
🛡️ Guardrails
- Touch only source files, leave configs/build scripts unless needed.
- Keep each refactor commit ≤ 200 LOC.
- Abort and ask for clarification if public API may change.
đźš« Commit policy
- Push only the dedicated cleanup branch, PR in draft mode.
- Never push to default branch without review.
âś… Verification before PR
- All unit/integration tests pass.
- Static‑analysis reports show ≥ 90 % reduction in unused code warnings and ≤ 1 % duplication.
When checks pass, open draft PR and return URL plus report table.