Code Simplifier

作者 pproencacf93c57cac89無授權條款215 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫7 週前更新

Code simplification skill for improving clarity, consistency, and maintainability while preserving exact behavior. Use when simplifying code, reducing complexity, cleaning up recent changes, applying refactoring patterns, or improving readability. Triggers on tasks involving code cleanup, simplification, refactoring, or readability improvements.

AI 產生的概覽

一套包含 47 條規則的參考指南,用於在完全保留行為的前提下簡化程式碼。

功能
此技能提供依 8 個類別組織的 47 條程式碼簡化規則,涵蓋情境探索、行為保留、命名、重複消除、死碼清理與語言慣用法。每條規則都有獨立的參考檔案,內含說明以及錯誤與正確寫法的對照範例。它也定義了工作流程:先了解專案情境,將範圍限制在近期修改的程式碼,依優先順序套用改寫,驗證行為未變,並保持差異最小。
適用情境
適用於清理或簡化近期修改的程式碼、減少巢狀結構與複雜度或重複、改善命名與可讀性,以及套用特定語言的慣用寫法。也用於審查程式碼的可維護性問題。
執行需求
僅包含指令與參考文件,未附帶指令碼。需要代理能夠讀取專案檔案,例如 CLAUDE.md 以及 lint 或格式化設定。

Community Code Simplification Best Practices

Comprehensive code simplification guide for AI agents and LLMs. Contains 47 rules across 8 categories, prioritized by impact from critical (context discovery, behavior preservation) to incremental (language idioms). Each rule includes detailed explanations, real-world examples comparing incorrect vs. correct implementations, and specific impact metrics.

Core Principles

  1. Context First: Understand project conventions before making any changes
  2. Behavior Preservation: Change how code is written, never what it does
  3. Scope Discipline: Focus on recently modified code, keep diffs small
  4. Clarity Over Brevity: Explicit, readable code beats clever one-liners

When to Apply

Reference these guidelines when:

  • Simplifying or cleaning up recently modified code
  • Reducing nesting, complexity, or duplication
  • Improving naming and readability
  • Applying language-specific idiomatic patterns
  • Reviewing code for maintainability issues

Rule Categories by Priority

PriorityCategoryImpactPrefixRules
1Context DiscoveryCRITICALctx-4
2Behavior PreservationCRITICALbehave-6
3Scope ManagementHIGHscope-5
4Control Flow SimplificationHIGHflow-9
5Naming and ClarityMEDIUM-HIGHname-6
6Duplication ReductionMEDIUMdup-5
7Dead Code EliminationMEDIUMdead-5
8Language IdiomsLOW-MEDIUMidiom-7

Quick Reference

1. Context Discovery (CRITICAL)

  • ctx-read-claude-md [blocked] - Always read CLAUDE.md before simplifying
  • ctx-detect-lint-config [blocked] - Check for linting and formatting configs
  • ctx-follow-existing-patterns [blocked] - Match existing code style in file and project
  • ctx-project-over-generic [blocked] - Project conventions override generic best practices

2. Behavior Preservation (CRITICAL)

  • behave-preserve-outputs [blocked] - Preserve all return values and outputs
  • behave-preserve-errors [blocked] - Preserve error messages, types, and handling
  • behave-preserve-api [blocked] - Preserve public function signatures and types
  • behave-preserve-side-effects [blocked] - Preserve side effects (logging, I/O, state changes)
  • behave-no-semantics-change [blocked] - Forbid subtle semantic changes
  • behave-verify-before-commit [blocked] - Verify behavior preservation before finalizing

3. Scope Management (HIGH)

  • scope-recent-code-only [blocked] - Focus on recently modified code only
  • scope-minimal-diff [blocked] - Keep changes small and reviewable
  • scope-no-unrelated-refactors [blocked] - No unrelated refactors
  • scope-no-global-rewrites [blocked] - Avoid global rewrites and architectural changes
  • scope-respect-boundaries [blocked] - Respect module and component boundaries

4. Control Flow Simplification (HIGH)

  • flow-early-return [blocked] - Use early returns to reduce nesting
  • flow-guard-clauses [blocked] - Use guard clauses for preconditions
  • flow-no-nested-ternaries [blocked] - Never use nested ternary operators
  • flow-explicit-over-dense [blocked] - Prefer explicit control flow over dense expressions
  • flow-flatten-nesting [blocked] - Flatten deep nesting to maximum 2-3 levels
  • flow-single-responsibility [blocked] - Each code block should do one thing
  • flow-positive-conditions [blocked] - Prefer positive conditions over double negatives
  • flow-optional-chaining [blocked] - Use optional chaining and nullish coalescing
  • flow-boolean-simplification [blocked] - Simplify boolean expressions

5. Naming and Clarity (MEDIUM-HIGH)

  • name-intention-revealing [blocked] - Use intention-revealing names
  • name-nouns-for-data [blocked] - Use nouns for data, verbs for actions
  • name-avoid-abbreviations [blocked] - Avoid cryptic abbreviations
  • name-consistent-vocabulary [blocked] - Use consistent vocabulary throughout
  • name-avoid-generic [blocked] - Avoid generic names
  • name-string-interpolation [blocked] - Prefer string interpolation over concatenation

6. Duplication Reduction (MEDIUM)

  • dup-rule-of-three [blocked] - Apply the rule of three
  • dup-no-single-use-helpers [blocked] - Avoid single-use helper functions
  • dup-extract-for-clarity [blocked] - Extract only when it improves clarity
  • dup-avoid-over-abstraction [blocked] - Prefer duplication over premature abstraction
  • dup-data-driven [blocked] - Use data-driven patterns over repetitive conditionals

7. Dead Code Elimination (MEDIUM)

  • dead-remove-unused [blocked] - Delete unused code artifacts
  • dead-delete-not-comment [blocked] - Delete code, never comment it out
  • dead-remove-obvious-comments [blocked] - Remove comments that state the obvious
  • dead-keep-why-comments [blocked] - Keep comments that explain why, not what
  • dead-remove-todo-fixme [blocked] - Remove stale TODO/FIXME comments

8. Language Idioms (LOW-MEDIUM)

  • idiom-ts-strict-types [blocked] - Use strict types over any (TypeScript)
  • idiom-ts-const-assertions [blocked] - Use const assertions and readonly (TypeScript)
  • idiom-rust-question-mark [blocked] - Use ? for error propagation (Rust)
  • idiom-rust-iterator-chains [blocked] - Use iterator chains when clearer (Rust)
  • idiom-python-comprehensions [blocked] - Use comprehensions for simple transforms (Python)
  • idiom-go-error-handling [blocked] - Handle errors immediately (Go)
  • idiom-prefer-language-builtins [blocked] - Prefer language and stdlib builtins

Workflow

  1. Discover context: Read CLAUDE.md, lint configs, examine existing patterns
  2. Identify scope: Focus on recently modified code unless asked to expand
  3. Apply transformations: Use rules in priority order (CRITICAL first)
  4. Verify behavior: Ensure outputs, errors, and side effects remain identical
  5. Keep diffs minimal: Small, focused changes that are easy to review

How to Use

Read individual reference files for detailed explanations and code examples:

  • Section definitions [blocked] - Category structure and impact levels
  • Rule template [blocked] - Template for adding new rules

Reference Files

FileDescription
references/_sections.md [blocked]Category definitions and ordering
assets/templates/_template.md [blocked]Template for new rules
metadata.json [blocked]Version and reference information

來源與署名

來源:pproenca/dot-skills位於skills/.curated/code-simplifier提交cf93c57

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架