返回技能列表

clean-codebase

pjt222
更新于 2 days ago
7 次查看
17
2
17
在 GitHub 上查看
文档api

关于

This skill automatically cleans up code hygiene issues like dead code, unused imports, and lint warnings while normalizing formatting across the codebase. It's ideal for addressing accumulated technical debt after rapid development without altering core business logic. Developers should use it when static analysis tools report fixable issues or when inconsistent formatting and unused code clutter the project.

快速安装

Claude Code

推荐
主要方式
npx skills add pjt222/agent-almanac -a claude-code
插件命令备选方式
/plugin add https://github.com/pjt222/agent-almanac
Git 克隆备选方式
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/clean-codebase

在 Claude Code 中复制并粘贴此命令以安装该技能

技能文档

clean-codebase

Cuándo Usar

Use this skill when a codebase has accumulated hygiene debt:

  • Lint warnings have piled up during rapid development
  • Unused imports and variables clutter files
  • Dead code paths exist but were never removed
  • Formatting is inconsistent across files
  • Static analysis tools report fixable issues

Do NOT use for architectural refactoring, bug fixes, or business logic changes. This skill focuses purely on hygiene and automated cleanup.

Entradas

ParameterTypeRequiredDescription
codebase_pathstringYesAbsolute path to codebase root
languagestringYesPrimary language (js, python, r, rust, etc.)
cleanup_modeenumNosafe (default) or aggressive
run_testsbooleanNoRun test suite after cleanup (default: true)
backupbooleanNoCreate backup before deletion (default: true)

Procedimiento

Paso 1: Pre-Cleanup Assessment

Measure the current state to quantify improvements later.

# Count lint warnings by severity
lint_tool --format json > lint_before.json

# Count lines of code
cloc . --json > cloc_before.json

# List unused symbols (language-dependent)
# JavaScript/TypeScript: ts-prune or depcheck
# Python: vulture
# R: lintr unused function checks

Esperado: Baseline metrics saved to lint_before.json and cloc_before.json

En caso de fallo: If lint tool not found, skip automated fixes and focus on manual review

Paso 2: Fix Automated Lint Warnings

Apply safe automated fixes (spacing, quotes, semicolons, trailing whitespace).

JavaScript/TypeScript:

eslint --fix .
prettier --write .

Python:

black .
isort .
ruff check --fix .

R:

Rscript -e "styler::style_dir('.')"

Rust:

cargo fmt
cargo clippy --fix --allow-dirty

Esperado: All safe lint warnings resolved; files formatted consistently

En caso de fallo: If automated fixes introduce test failures, revert changes and escalate

Paso 3: Identify Dead Code Paths

Use static analysis to find unreferenced functions, unused variables, and orphaned files.

JavaScript/TypeScript:

ts-prune | tee dead_code.txt
depcheck | tee unused_deps.txt

Python:

vulture . | tee dead_code.txt

R:

Rscript -e "lintr::lint_dir('.', linters = lintr::unused_function_linter())"

General approach:

  1. Grep for function definitions
  2. Grep for function calls
  3. Report functions defined but never called

Esperado: dead_code.txt lists unused functions, variables, and files

En caso de fallo: If static analysis tool unavailable, manually review recent commit history for orphaned code

Paso 4: Remove Unused Imports

Clean up import blocks by removing references to packages never used.

JavaScript:

eslint --fix --rule 'no-unused-vars: error'

Python:

autoflake --remove-all-unused-imports --in-place --recursive .

R:

# Manual review: grep for library() calls, check if package used
grep -r "library(" . | cut -d: -f2 | sort | uniq

Esperado: All unused import statements removed

En caso de fallo: If removing imports breaks build, they were used indirectly — restore and document

Paso 5: Remove Dead Code (Mode-Dependent)

Safe Mode (default):

  • Only remove code explicitly marked as deprecated
  • Remove commented-out code blocks (if >10 lines and >6 months old)
  • Remove TODO comments referencing completed issues

Aggressive Mode (opt-in):

  • Remove all functions identified as unused in Step 3
  • Remove private methods with zero references
  • Remove feature flags for deprecated features

For each candidate deletion:

  1. Verify zero references in codebase
  2. Check git history for recent activity (skip if modified in last 30 days)
  3. Remove code and add entry to CLEANUP_LOG.md

Esperado: Dead code removed; CLEANUP_LOG.md documents all deletions

En caso de fallo: If uncertain whether code is truly dead, move to archive/ directory instead

Paso 6: Normalize Formatting

Ensure consistent formatting across all files (even if not caught by linters).

  1. Normalize line endings (LF vs CRLF)
  2. Ensure single newline at end of file
  3. Remove trailing whitespace
  4. Normalize indentation (spaces vs tabs, indent width)
# Example: Fix line endings and trailing whitespace
find . -type f -name "*.js" -exec sed -i 's/\r$//' {} +
find . -type f -name "*.js" -exec sed -i 's/[[:space:]]*$//' {} +

Esperado: All files follow consistent formatting conventions

En caso de fallo: If sed breaks binary files, skip and document

Paso 7: Run Tests

Validate that cleanup didn't break functionality.

# Language-specific test command
npm test              # JavaScript
pytest                # Python
R CMD check           # R
cargo test            # Rust

Esperado: All tests pass (or same failures as before cleanup)

En caso de fallo: Revert changes incrementally to identify breaking change, then escalate

Paso 8: Generate Cleanup Report

Document all changes for review.

# Codebase Cleanup Report

**Date**: YYYY-MM-DD
**Mode**: safe | aggressive
**Language**: <language>

## Metrics

| Metric | Before | After | Change |
|--------|--------|-------|--------|
| Lint warnings | X | Y | -Z |
| Lines of code | A | B | -C |
| Unused imports | D | 0 | -D |
| Dead functions | E | F | -G |

## Changes Applied

1. Fixed X lint warnings (automated)
2. Removed Y unused imports
3. Deleted Z lines of dead code (see CLEANUP_LOG.md)
4. Normalized formatting across W files

## Escalations

- [Issue description requiring human review]
- [Uncertain deletion moved to archive/]

## Validación

- [x] All tests pass
- [x] Backup created: backup_YYYYMMDD/
- [x] CLEANUP_LOG.md updated

Esperado: Report saved to CLEANUP_REPORT.md in project root

En caso de fallo: (N/A — generate report regardless of outcome)

Validación

After cleanup:

  • All tests pass (or same failures as before)
  • No new lint warnings introduced
  • Backup created before any deletions
  • CLEANUP_LOG.md documents all removed code
  • Cleanup report generated with metrics
  • Git diff reviewed for unexpected changes
  • CI pipeline passes

Errores Comunes

  1. Removing Code Still Used via Reflection: Static analysis misses dynamic calls (e.g., eval(), metaprogramming). Always check git history.

  2. Breaking Implicit Dependencies: Removing imports that were used by dependencies. Run tests after every import removal.

  3. Deleting Feature Flags for Active Features: Even if unused in current branch, feature flags may be active in other environments. Check deployment configs.

  4. Over-Aggressive Formatting: Tools like black or prettier may reformat code in ways that trigger unnecessary diffs. Configure tools to match project style.

  5. Ignoring Test Coverage: Cannot safely clean codebases without tests. If coverage is low, escalate for test additions first.

  6. Not Backing Up: Always create backup_YYYYMMDD/ directory before deleting anything, even if using git.

  7. Wrong R binary on hybrid systems: On WSL or Docker, Rscript may resolve to a cross-platform wrapper instead of native R. Check with which Rscript && Rscript --version. Prefer the native R binary (e.g., /usr/local/bin/Rscript on Linux/WSL) for reliability. See Setting Up Your Environment for R path configuration.

Habilidades Relacionadas

GitHub 仓库

pjt222/agent-almanac
路径: i18n/es/skills/clean-codebase
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

相关推荐技能

railway-docs

文档

Railway Docs Skill可实时获取最新的Railway官方文档,确保回答的准确性。当开发者询问Railway功能特性、工作原理或分享docs.railway.com链接时,应优先使用此技能。它通过专门的LLM优化文档源提供最新信息,避免依赖过时记忆来回答技术问题。

查看技能

n8n-code-python

文档

该Skill为在n8n平台的Python代码节点中编写代码提供专家指导,特别适用于需要使用_input/_json/_node语法、Python标准库或了解n8n中Python限制的场景。它强调JavaScript应作为首选方案,仅当需要特定Python功能或对Python语法更熟悉时才使用Python。Skill提供了快速入门模板和关键注意事项,帮助开发者在n8n中高效编写Python代码。

查看技能

archon

文档

Archon Skill为开发者提供了基于RAG的语义搜索和项目任务管理功能,可通过REST API访问知识库。它支持文档搜索、网站爬取、文件上传和版本控制,适用于技术文档查询和项目管理场景。首次使用时需要配置Archon主机地址,建议在处理外部文档时优先使用该Skill。

查看技能

n8n-code-javascript

文档

这个Skill为n8n工作流中的JavaScript代码节点提供专业指导,涵盖数据处理、HTTP请求和日期操作等核心场景。它详细解释了如何正确使用n8n特有的`$input`/`$json`语法、`$helpers`工具以及DateTime对象,并包含关键的错误排查和模式选择建议。开发者通过该Skill能快速掌握Code节点的正确返回格式、数据访问方法和常见陷阱解决方案。

查看技能